installation - setup.py/setup.cfg 安装所有附加功能

标签 installation setuptools setup.py

我在 setup.cfg 中寻找“继承”其他附加功能的可能性,如下所示:

[options.extras_require]
all =
    <doc>
    <dev>
    <test>
doc =
    sphinx
dev =
    dvc
    twine  # for publishing
    <test>
test =
    flake8
    pytest
    pytest-cov
    coverage
    pytest-shutil
    pytest-virtualenv
    pytest-fixture-config
    pytest-xdist

我希望通过运行来安装所有附加组件

pip install PACKAGE[all]

最佳答案

我相信 setuptools 使用 configparser's BasicInterpolation在解析 setup.cfg 文件时。因此,您可以利用这一优势来执行以下操作:

[options.extras_require]
all =
    %(doc)s
    %(dev)s
    %(test)s
doc =
    sphinx
dev =
    dvc
    twine  # for publishing
    %(test)s
test =
    flake8
    pytest
    pytest-cov
    coverage
    pytest-shutil
    pytest-virtualenv
    pytest-fixture-config
    pytest-xdist

构建 sdist 然后查看项目的 *.egg-info/requires.txt 文件以获取结果。由于 test 被包含在 all 中两次,一次是直接包含的,一次是通过 dev 间接包含的,所以 all 中会有一些重复>,但很可能这应该不是什么大问题。


另一个理论上应该适用于所有构建后端和前端的解决方案是“自力更生”:

[options.extras_require]
all =
    PROJECT[doc]
    PROJECT[dev]
    PROJECT[test]
doc =
    sphinx
dev =
    dvc
    twine  # for publishing
    PROJECT[test]
test =
    flake8
    pytest
    pytest-cov
    coverage
    pytest-shutil
    pytest-virtualenv
    pytest-fixture-config
    pytest-xdist

引用:

关于installation - setup.py/setup.cfg 安装所有附加功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61609869/

相关文章:

sql-server - Inno Setup - 尝试安装 NetFx3 功能时出现 "An attempt was made to load a program with an incorrect format"

python - 为什么 "python setup.py sdist"会在项目根目录中创建不需要的 "PROJECT-egg.info"?

python - 为什么 setuptools 不复制子文件夹中的模块?

python - 将参数从 Python 传递到 C 时出现问题

python - 如何同时使用 zc.buildout 和 setup.py?

windows - Windows卸载软件时如何找到安装位置

linux - 配置重命名后以 rpm 规范重启服务

installation - 如何安排使用MSI在下次重新启动时进行安装?

python - 分发需要最小 Python 版本的 Python 包的最佳方法是什么

setuptools - 获取setup.cfg包的版本