Correct use of PEP 508 environment markers in setup.cfg file

I'm trying to use PEP 496 - Environment Markers and PEP 508 - Dependency Specification for Python Software Packages , defining dependencies that only make sense for a specific OS.

Mine setup.py

looks like this:

import setuptools
assert setuptools.__version__ >= '36.0'

setuptools.setup()

      

My minimum 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 a package like this, pip install -e foobar/

it fails:

pip._vendor.pkg_resources.RequirementParseError: Invalid requirement, parse error at "'; platfo'"

      

I guess it doesn't expect a semicolon. But how am I supposed to use environment markers?

+3


source to share


1 answer


One character. That's all you were missing. You had (the very last line of yours ) platform_system="Darwin"

instead . It works great:platform_system=="Darwin"

install_requires

[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"

      

This is optional, but yours setup.py

can be simplified as well.

import setuptools

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

      



Unlike the comments earlier, I like to use setup.cfg

. It's clean and easy. If you want to use information from setup.cfg

at runtime, it is easy to parse:

from setuptools.config import read_configuration

conf_dict = read_configuration('/home/user/dev/package/setup.cfg')

      

Additional information setup.cfg

+2


source







All Articles