I've successfully used the markers feature for selectively and declaratively requiring a dependency. See backports.unittest_mock for an example. Through the 'extras', mock will be required, but only on Python 2. When I can rely on Setuptools 17.1, I can change that dependency to python_version < "3.3".
setuptools
使用environment markers对此有支持。在official documentation中详细介绍了它的用法。基于change log是在v20.5中添加的,但是在v20.8.1之前实现是不稳定的(只有15天的间隔)。
原始答案(仍然有效,但将来可能会被弃用):
setuptools
支持在extras_require
参数中使用。格式如下:
它将支持其他比较运算符。
遗憾的是,在documentation中没有提到。在寻找答案时,我发现PEP-426在谈论“环境标记”。有了这个短语,我就可以找到一个setuptools ticket带有以下注释:
这已经讨论过了here,似乎推荐的方法是使用
sys.version_info
测试setup.py
中的Python版本相关问题 更多 >
编程相关推荐