主页

索引

模块索引

搜索页面

文件setup.py

主要内容包括:

1. 项目元数据
    项目的基本信息,如名称、版本、作者、作者邮箱、描述、URL 等
2. 项目依赖关系
    该项目运行所需的第三方库列表,通常以 install_requires 列出
3. 项目打包
    配置如何将项目打包为可分发的形式,包括指定包所在的目录、数据文件、脚本等
4. 项目入口点
    定义执行入口,指示安装后如何启动或使用该项目
5. 额外依赖
    用于指定额外的依赖,例如开发依赖、测试依赖等

示例:

from setuptools import setup, find_packages

# 指定变量
requirements = (here / "requirements.txt").read_text(encoding="utf-8").splitlines()
extras_require = {
    "selenium": ["selenium>4", "webdriver_manager", "beautifulsoup4"],
    "search-google": ["google-api-python-client==2.94.0"],
}
extras_require["test"] = [
    *set(i for j in extras_require.values() for i in j),
    "pytest",
]

setup(
    # 1. 项目元数据
    name="my_project",
    version="0.1.0",
    author="Your Name",
    author_email="your.email@example.com",
    description="A short description of your project",
    long_description=open("README.md").read(),
    long_description_content_type="text/markdown",
    url="https://github.com/yourusername/my_project",

    # 2. 项目依赖关系
    install_requires=[
        "requests>=2.20.0",
        "numpy>=1.18.0",
    ],
    # install_requires=requirements,


    # 3. 项目打包
    packages=find_packages(),
    # packages=find_packages(exclude=["contrib", "docs", "examples", "tests*"]),
    # packages=find_packages(include=['sample', 'sample.*']),

    # package_data: 用于指定与代码相关联的额外文件,例如配置文件、模板、静态资源等
    # 这些文件在打包时会被包括在内。它的格式是一个字典,键是包的名称,值是要包含的文件列表
    package_data={
        "my_project": ["data/*.csv"],  # 包含数据文件,例如 CSV 文件
    },
    # 如果设为 True,则在打包时会包括源代码控制系统中被标记的所有文件
    include_package_data=True,
    # 尽管配置 package_data 足以满足大多数需求,但在某些情况下,您可能需要将数据文件放在包之外。
    data_files=[('my_data', ['data/data_file'])],


    # 4. 项目入口点
    entry_points={
        "console_scripts": [
            "my_command=my_project.module:function",  # 定义命令行入口
        ],
    },
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.6',  # 指定 Python 版本要求

    # 5. 额外依赖
    extras_require=extras_require,
)

4.项目入口点-entry_points

  • entry_points 是一个字典,键表示入口点的类别,值是一个列表,每个列表项定义一个入口点

  • entry_points 的格式如下:

    entry_points = {
        "<category_name>": [
            "<entry_point_1>",
            "<entry_point_2>",
            ...
        ],
        ...
    }
    

category_name是入口点的类别,主要包括:

1. console_scripts:
    用于定义命令行脚本,允许你在安装后创建可在命令行中执行的脚本
2. gui_scripts:
    与 "console_scripts" 类似,但用于图形用户界面 (GUI) 应用程序
    这个入口点会在系统中创建可执行的 GUI 程序,通常在 GUI 环境中运行
3. pytest11:
    用于 pytest 插件
    定义了 pytest 的扩展点,使你可以创建自定义的 pytest 插件

entry_point_X是具体的入口点定义,格式一般为:

<script_name>=<module_name>:<object_name>
说明:
    <script_name> 是入口点的名称
    <module_name>  Python 模块的名称
    <object_name> 是模块中的对象或函数

console_scripts

  • 用于命令行脚本

  • 格式:

    entry_points = {
        "console_scripts": [
            "<script_name>=<module_name>:<object_name>",
        ],
    }
    

说明:

"console_scripts" 指定了命令行脚本类别
"<script_name>" 是命令行中的命令名称
"<module_name>:<object_name>"
    表示在命令行中执行模块和对应的函数或对象

gui_scripts

  • 用于 GUI 脚本

  • 格式:

    entry_points = {
        "gui_scripts": [
            "my_gui_command=my_gui_module:main",
        ],
    }
    

说明:

"gui_scripts" 用于定义 GUI 应用程序入口点。
"my_gui_command" 是命令行中用于启动 GUI 应用程序的命令。
"my_gui_module:main" 指定 GUI 程序的入口函数。

实例

"""Setup script for MetaGPT."""
import subprocess
from pathlib import Path

from setuptools import Command, find_packages, setup


class InstallMermaidCLI(Command):
    """A custom command to run `npm install -g @mermaid-js/mermaid-cli` via a subprocess."""

    description = "install mermaid-cli"
    user_options = []

    def run(self):
        try:
            subprocess.check_call(["npm", "install", "-g", "@mermaid-js/mermaid-cli"])
        except subprocess.CalledProcessError as e:
            print(f"Error occurred: {e.output}")


here = Path(__file__).resolve().parent
long_description = (here / "README.md").read_text(encoding="utf-8")
requirements = (here / "requirements.txt").read_text(encoding="utf-8").splitlines()


extras_require = {
    "selenium": ["selenium>4", "webdriver_manager", "beautifulsoup4"],
    "search-google": ["google-api-python-client==2.94.0"],
    "search-ddg": ["duckduckgo-search~=4.1.1"],
    "ocr": ["paddlepaddle==2.4.2", "paddleocr~=2.7.3", "tabulate==0.9.0"],
    "rag": [
        "llama-index-core==0.10.15",
        "llama-index-embeddings-azure-openai==0.1.6",
        "llama-index-embeddings-openai==0.1.5",
        "llama-index-embeddings-gemini==0.1.6",
        "llama-index-embeddings-ollama==0.1.2",
        "llama-index-llms-azure-openai==0.1.4",
        "llama-index-readers-file==0.1.4",
        "llama-index-retrievers-bm25==0.1.3",
        "llama-index-vector-stores-faiss==0.1.1",
        "llama-index-vector-stores-elasticsearch==0.1.6",
        "llama-index-vector-stores-chroma==0.1.6",
        "llama-index-postprocessor-cohere-rerank==0.1.4",
        "llama-index-postprocessor-colbert-rerank==0.1.1",
        "llama-index-postprocessor-flag-embedding-reranker==0.1.2",
        "docx2txt==0.8",
    ],
    "android_assistant": ["pyshine==0.0.9", "opencv-python==4.6.0.66"],
}

extras_require["test"] = [
    *set(i for j in extras_require.values() for i in j),
    "pytest",
    "pytest-asyncio",
    "pytest-cov",
    "pytest-mock",
    "pytest-html",
    "pytest-xdist",
    "pytest-timeout",
    "connexion[uvicorn]~=3.0.5",
    "azure-cognitiveservices-speech~=1.31.0",
    "aioboto3~=11.3.0",
    "gradio==3.0.0",
    "grpcio-status==1.48.2",
    "pylint==3.0.3",
    "pybrowsers",
]

extras_require["pyppeteer"] = [
    "pyppeteer>=1.0.2"
]  # pyppeteer is unmaintained and there are conflicts with dependencies
extras_require["dev"] = (["pylint~=3.0.3", "black~=23.3.0", "isort~=5.12.0", "pre-commit~=3.6.0"],)


setup(
    name="metagpt",
    version="0.8.1",
    description="The Multi-Agent Framework",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/geekan/MetaGPT",
    author="Alexander Wu",
    author_email="alexanderwu@deepwisdom.ai",
    license="MIT",
    keywords="metagpt multi-agent multi-role programming gpt llm metaprogramming",
    packages=find_packages(exclude=["contrib", "docs", "examples", "tests*"]),
    python_requires=">=3.9",
    install_requires=requirements,
    extras_require=extras_require,
    cmdclass={
        "install_mermaid": InstallMermaidCLI,
    },
    entry_points={
        "console_scripts": [
            "metagpt=metagpt.software_company:app",
        ],
    },
    include_package_data=True,
)

主页

索引

模块索引

搜索页面