Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct use of PEP 508 environment markers in setup.cfg

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?

like image 996
toriningen Avatar asked Jul 03 '17 05:07

toriningen


1 Answers

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.setupcfg import read_configuration

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

More setup.cfg info

like image 186
DarkerIvy Avatar answered Sep 23 '22 06:09

DarkerIvy