Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle "extras" from PEP 508 #5

Open
gordonmessmer opened this issue Jan 21, 2020 · 3 comments
Open

Handle "extras" from PEP 508 #5

gordonmessmer opened this issue Jan 21, 2020 · 3 comments

Comments

@gordonmessmer
Copy link
Owner

https://www.python.org/dev/peps/pep-0508/#extras

@gordonmessmer
Copy link
Owner Author

Given $ pip install 'cairocffi>=0.9[xcb]', pip will install cairocffi and seems to treat "[xcb]" as an extras specification, but pkg_resources doesn't seem to parse that requirement...

>>> from pkg_resources import Requirement
>>> parsed_req = Requirement.parse('cairocffi>=0.9[xcb]')
>>> parsed_req.key
'cairocffi'
>>> parsed_req.specs
[('>=', '0.9[xcb]')]
>>> parsed_req.extras
()

>>> parsed_req = Requirement.parse('cairocffi [xcb] >=0.9')
>>> parsed_req.key
'cairocffi'
>>> parsed_req.specs
[('>=', '0.9')]
>>> parsed_req.extras
('xcb',)

@encukou
Copy link

encukou commented Jan 21, 2020

According to PEP 508, an extra needs to be right after the name, not after the version.

pip is not a reference implementation of the standards. It has lots of legacy behavior that the standards try to clean up.
Same goes for setuptools/pkg_resources (which seems right in this particular case).
It's best to avoid both in favor of packaging:

>>> import packaging.requirements
>>> packaging.requirements.Requirement('cairocffi>=0.9[xcb]').extras
set()
>>> packaging.requirements.Requirement('cairocffi[xcb]>=0.9').extras
{'xcb'}

Instead of adding pip compatibility, let's fix the packages/projects that use nonstandard specifications.

@hroncok
Copy link

hroncok commented Jan 21, 2020

We have came to the same conclusion in https://bugzilla.redhat.com/show_bug.cgi?id=1758141#c12 and below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants