Skip to content

Commit

Permalink
Merge pull request #358 from hauntsaninja/fixurl
Browse files Browse the repository at this point in the history
Fix requirement produced for git URL in extra
  • Loading branch information
jaraco committed Dec 16, 2021
2 parents fef1016 + d890067 commit 134ed7f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v4.8.3
======

* #357: Fixed requirement generation from egg-info when a
URL requirement is given.

v4.8.2
======

Expand Down
13 changes: 11 additions & 2 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,16 +696,25 @@ def _convert_egg_info_reqs_to_simple_reqs(sections):
def make_condition(name):
return name and f'extra == "{name}"'

def parse_condition(section):
def quoted_marker(section):
section = section or ''
extra, sep, markers = section.partition(':')
if extra and markers:
markers = f'({markers})'
conditions = list(filter(None, [markers, make_condition(extra)]))
return '; ' + ' and '.join(conditions) if conditions else ''

def url_req_space(req):
"""
PEP 508 requires a space between the url_spec and the quoted_marker.
Ref python/importlib_metadata#357.
"""
# '@' is uniquely indicative of a url_req.
return ' ' * ('@' in req)

for section in sections:
yield section.value + parse_condition(section.name)
space = url_req_space(section.value)
yield section.value + space + quoted_marker(section.name)


class DistributionFinder(MetaPathFinder):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def test_more_complex_deps_requires_text(self):
[extra1]
dep4
dep6@ git+https://example.com/python/dep.git@v1.0.0
[extra2:python_version < "3"]
dep5
Expand All @@ -257,6 +258,7 @@ def test_more_complex_deps_requires_text(self):
'dep3; python_version < "3"',
'dep4; extra == "extra1"',
'dep5; (python_version < "3") and extra == "extra2"',
'dep6@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1"',
]
# It's important that the environment marker expression be
# wrapped in parentheses to avoid the following 'and' binding more
Expand Down

0 comments on commit 134ed7f

Please sign in to comment.