Commit 0e9e9944 by Simone Primarosa Committed by GitHub

pep508: ensure whitespace prefix for quoted marker

Prior to this fix, when formatting PEP 508 dependency specification for
remote url references, the quoted marker was not prefixed with required
whitespace. This change ensures that the format adheres to the 
specified grammar.

Resolves: python-poetry/poetry#2326
parent c945890e
...@@ -33,8 +33,8 @@ def dependency_from_pep_508(name): ...@@ -33,8 +33,8 @@ def dependency_from_pep_508(name):
name = parts[0].strip() name = parts[0].strip()
if len(parts) > 1: if len(parts) > 1:
rest = parts[1] rest = parts[1]
if ";" in rest: if " ;" in rest:
name += ";" + rest.split(";", 1)[1] name += " ;" + rest.split(" ;", 1)[1]
req = Requirement(name) req = Requirement(name)
......
...@@ -83,7 +83,7 @@ def parse_requires(requires): # type: (str) -> List[str] ...@@ -83,7 +83,7 @@ def parse_requires(requires): # type: (str) -> List[str]
continue continue
if current_marker: if current_marker:
line = "{}; {}".format(line, current_marker) line = "{} ; {}".format(line, current_marker)
requires_dist.append(line) requires_dist.append(line)
......
...@@ -183,6 +183,22 @@ def test_dependency_from_pep_508_with_git_url(): ...@@ -183,6 +183,22 @@ def test_dependency_from_pep_508_with_git_url():
assert "1.2" == dep.reference assert "1.2" == dep.reference
def test_dependency_from_pep_508_with_git_url_and_comment_and_extra():
name = (
"poetry @ git+https://github.com/python-poetry/poetry.git@b;ar;#egg=poetry"
' ; extra == "foo;"'
)
dep = dependency_from_pep_508(name)
assert "poetry" == dep.name
assert dep.is_vcs()
assert "git" == dep.vcs
assert "https://github.com/python-poetry/poetry.git" == dep.source
assert "b;ar;" == dep.reference
assert dep.in_extras == ["foo;"]
def test_dependency_from_pep_508_with_url(): def test_dependency_from_pep_508_with_url():
name = "django-utils @ https://example.com/django-utils-1.0.0.tar.gz" name = "django-utils @ https://example.com/django-utils-1.0.0.tar.gz"
......
...@@ -29,6 +29,9 @@ pathlib2>=2.3.0.0,<3.0.0.0 ...@@ -29,6 +29,9 @@ pathlib2>=2.3.0.0,<3.0.0.0
[:python_version >= "3.4.0.0" and python_version < "3.6.0.0"] [:python_version >= "3.4.0.0" and python_version < "3.6.0.0"]
zipfile36>=0.1.0.0,<0.2.0.0 zipfile36>=0.1.0.0,<0.2.0.0
[dev]
isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort
""" """
result = parse_requires(requires) result = parse_requires(requires)
expected = [ expected = [
...@@ -45,10 +48,11 @@ zipfile36>=0.1.0.0,<0.2.0.0 ...@@ -45,10 +48,11 @@ zipfile36>=0.1.0.0,<0.2.0.0
"msgpack-python>=0.5.0.0,<0.6.0.0", "msgpack-python>=0.5.0.0,<0.6.0.0",
"pyparsing>=2.2.0.0,<3.0.0.0", "pyparsing>=2.2.0.0,<3.0.0.0",
"requests-toolbelt>=0.8.0.0,<0.9.0.0", "requests-toolbelt>=0.8.0.0,<0.9.0.0",
'typing>=3.6.0.0,<4.0.0.0; (python_version >= "2.7.0.0" and python_version < "2.8.0.0") or (python_version >= "3.4.0.0" and python_version < "3.5.0.0")', 'typing>=3.6.0.0,<4.0.0.0 ; (python_version >= "2.7.0.0" and python_version < "2.8.0.0") or (python_version >= "3.4.0.0" and python_version < "3.5.0.0")',
'virtualenv>=15.2.0.0,<16.0.0.0; python_version >= "2.7.0.0" and python_version < "2.8.0.0"', 'virtualenv>=15.2.0.0,<16.0.0.0 ; python_version >= "2.7.0.0" and python_version < "2.8.0.0"',
'pathlib2>=2.3.0.0,<3.0.0.0; python_version >= "2.7.0.0" and python_version < "2.8.0.0"', 'pathlib2>=2.3.0.0,<3.0.0.0 ; python_version >= "2.7.0.0" and python_version < "2.8.0.0"',
'zipfile36>=0.1.0.0,<0.2.0.0; python_version >= "3.4.0.0" and python_version < "3.6.0.0"', 'zipfile36>=0.1.0.0,<0.2.0.0 ; python_version >= "3.4.0.0" and python_version < "3.6.0.0"',
'isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort ; extra == "dev"',
] ]
assert result == expected assert result == expected
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment