From ca287f630dc19d22f4b370b2b8867f18818f8f59 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 15 Dec 2021 13:51:33 -0800 Subject: [PATCH 1/4] Fix requirement produced for git URL in extra --- importlib_metadata/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index a7379810..fdf9ce49 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -702,7 +702,7 @@ def parse_condition(section): if extra and markers: markers = f'({markers})' conditions = list(filter(None, [markers, make_condition(extra)])) - return '; ' + ' and '.join(conditions) if conditions else '' + return ' ; ' + ' and '.join(conditions) if conditions else '' for section in sections: yield section.value + parse_condition(section.name) From 3b46c6649349b2039443c95b5346e9b0a834e1f9 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 15 Dec 2021 13:57:14 -0800 Subject: [PATCH 2/4] And test it --- tests/test_api.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 75d4184d..ed9aed0b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -245,18 +245,20 @@ def test_more_complex_deps_requires_text(self): [extra1] dep4 + dep5@ git+https://example.com/python/dep.git@v1.0.0 [extra2:python_version < "3"] - dep5 + dep6 """ ) deps = sorted(Distribution._deps_from_requires_text(requires)) expected = [ 'dep1', 'dep2', - 'dep3; python_version < "3"', - 'dep4; extra == "extra1"', - 'dep5; (python_version < "3") and extra == "extra2"', + 'dep3 ; python_version < "3"', + 'dep4 ; extra == "extra1"', + 'dep5@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1"', + 'dep6 ; (python_version < "3") and extra == "extra2"', ] # It's important that the environment marker expression be # wrapped in parentheses to avoid the following 'and' binding more From d8aaa72f66fc10731c387b6a3c702fdc804203a9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 16 Dec 2021 09:19:02 -0500 Subject: [PATCH 3/4] Only implement the extra space where it's required, fitting the spec more minimally. --- importlib_metadata/__init__.py | 15 ++++++++++++--- tests/test_api.py | 12 ++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index fdf9ce49..d08e9c14 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -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 '' + 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): diff --git a/tests/test_api.py b/tests/test_api.py index ed9aed0b..7e340142 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -245,20 +245,20 @@ def test_more_complex_deps_requires_text(self): [extra1] dep4 - dep5@ git+https://example.com/python/dep.git@v1.0.0 + dep6@ git+https://example.com/python/dep.git@v1.0.0 [extra2:python_version < "3"] - dep6 + dep5 """ ) deps = sorted(Distribution._deps_from_requires_text(requires)) expected = [ 'dep1', 'dep2', - 'dep3 ; python_version < "3"', - 'dep4 ; extra == "extra1"', - 'dep5@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1"', - 'dep6 ; (python_version < "3") and extra == "extra2"', + '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 From d89006754b6136637b576830ba7937d2a6d2d521 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 16 Dec 2021 09:22:31 -0500 Subject: [PATCH 4/4] Update changelog. --- CHANGES.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index b169def6..0d319d58 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v4.8.3 +====== + +* #357: Fixed requirement generation from egg-info when a + URL requirement is given. + v4.8.2 ======