如何在不安装 "extras_require" 依赖项的情况下 运行 "python setup.py test"?

How to run "python setup.py test" without installing "extras_require" dependencies?

我在 setup.cfg 中有 extras_require 个依赖项,列为:

[extras_require]
tensorflow = tensorflow
tensorflow_gpu = tensorflow-gpu

那样的话,如果我的包是用 pip install pkg[tensorflow_gpu] 安装的,它会安装一个版本的包,而 pip install pkg[tensorflow] 会安装另一个版本。

这类似于 Edward Package packages (following this git issue).

但是,当我 运行 python setup.py test 时,它会在执行我的单元测试之前安装 tensorflowtensorflow-gpu 包.一旦我在任何单元测试中 import tensorflow 并且依赖于硬件,这可能会有问题。

有没有办法在运行宁python setup.py test时选择性地安装某个extras_require包?

或者有没有办法安装 no extras_require 软件包?因为这样我就可以在 运行 执行测试命令之前安装 tensorflow

(注意:我知道我可以 运行 pip 和 pytest 独立,但我正在寻找使用 setuptools 的解决方案)

看来这不是 setuptools 问题,而是我使用的名为 pyscaffold 的工具的潜在问题。我在他们的 github.

上开了一个 question issue

当我 运行 python setup.py test 使用以下 setup.cfg 时,它工作正常,因为它不会引入 tensorflow。

[metadata]
name = simple

[options]
package_dir = 
    =src
setup_requires = pytest-runner
install_requires = 
tests_require = pytest

[options.extras_require]
tf = tensorflow

[aliases]
test = pytest

[tool:pytest]
addopts = --verbose
testpaths = tests