Correct use of PEP 508 environment markers in setup.cfg

China☆狼群 提交于 2019-12-06 02:28:27

问题


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.

My setup.py looks like this:

import setuptools
assert setuptools.__version__ >= '36.0'

setuptools.setup()

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"

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?


回答1:


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"

It's not necessary but your setup.py could be simplified too.

import setuptools

setup(setup_requires=['setuptools>=36.0'])

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')

More setup.cfg info



来源:https://stackoverflow.com/questions/44878440/correct-use-of-pep-508-environment-markers-in-setup-cfg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!