在 setup.cfg 中正确使用 PEP 508 环境标记 [英] Correct use of PEP 508 environment markers in setup.cfg
问题描述
我正在尝试使用 PEP 496 -- 环境标记和 PEP 508 -- Python 软件包的依赖规范在特定操作系统上有意义.
I am trying to make use of PEP 496 -- Environment Markers and PEP 508 -- Dependency specification for Python Software Packages by specifying dependencies that only make sense on specific OS.
我的 setup.py
看起来像这样:
My setup.py
looks like this:
import setuptools
assert setuptools.__version__ >= '36.0'
setuptools.setup()
我的最小 setup.cfg
看起来像这样:
My minimal setup.cfg
looks like this:
[metadata]
name = foobar
version = 1.6.5+0.1.0
[options]
packages = find:
install_requires =
ham >= 0.1.0
eggs >= 8.1.2
spam >= 1.2.3; platform_system=="Darwin"
i-love-spam >= 1.2.0; platform_system="Darwin"
然而,当尝试使用 pip install -e foobar/
安装这样的包时,它失败了:
However, when trying to install such a package with pip install -e foobar/
, it fails with:
pip._vendor.pkg_resources.RequirementParseError: Invalid requirement, parse error at "'; platfo'"
我猜它不希望有分号.但是我应该如何使用环境标记呢?
I guess it does not expect semicolon there. But how am I supposed to use environment markers then?
推荐答案
一个字符.这就是你所缺少的.您使用的是 platform_system="Darwin"
而不是 platform_system=="Darwin"
(install_requires
的最后一行).这样就可以正常工作:
One character. That's all you were missing. You had platform_system="Darwin"
instead of platform_system=="Darwin"
(the very last line of your install_requires
). It works fine this way:
[metadata]
name = foobar
version = 1.6.5+0.1.0
[options]
packages = find:
install_requires =
ham >= 0.1.0
eggs >= 8.1.2
spam >= 1.2.3; platform_system=="Darwin"
i-love-spam >= 1.2.0; platform_system=="Darwin"
这不是必需的,但您的 setup.py
也可以简化.
It's not necessary but your setup.py
could be simplified too.
import setuptools
setup(setup_requires=['setuptools>=36.0'])
与之前的评论不同,我喜欢使用 setup.cfg
.它干净而简单.如果你想在运行时使用 setup.cfg
中的信息,很容易解析:
Unlike those commenting before, I like using setup.cfg
. It's clean and easy. If you want to use the information from setup.cfg
at runtime, it's easy to parse:
from setuptools.config import read_configuration
conf_dict = read_configuration('/home/user/dev/package/setup.cfg')
这篇关于在 setup.cfg 中正确使用 PEP 508 环境标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!