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

setup.py/setup.cfg install all extras

我在 setup.cfg 中寻找 'inherit' 其他附加功能的可能性,如下所示:

[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 在解析 setup.cfg 文件时使用 configparser's BasicInterpolation。所以你可以利用它来做如下的事情:

[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

参考文献: