From b8ca53d4624c377104ed4119f3f276f5e927a49d Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 18:24:20 +0100 Subject: [PATCH 1/9] Add failing test for dependency_from_pep_508 See https://github.com/python-poetry/poetry/issues/2326 --- tests/packages/test_main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/packages/test_main.py b/tests/packages/test_main.py index 238f8c497..92731b187 100644 --- a/tests/packages/test_main.py +++ b/tests/packages/test_main.py @@ -183,6 +183,22 @@ def test_dependency_from_pep_508_with_git_url(): 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(): name = "django-utils @ https://example.com/django-utils-1.0.0.tar.gz" From 193c8a973b2b1e1a463e4b7aea36a2df3acc362a Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 18:24:27 +0100 Subject: [PATCH 2/9] Fix dependency_from_pep_508 --- poetry/core/packages/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry/core/packages/__init__.py b/poetry/core/packages/__init__.py index f86a24b96..16854c530 100644 --- a/poetry/core/packages/__init__.py +++ b/poetry/core/packages/__init__.py @@ -63,8 +63,8 @@ def dependency_from_pep_508( name = parts[0].strip() if len(parts) > 1: rest = parts[1] - if ";" in rest: - name += ";" + rest.split(";", 1)[1] + if " ;" in rest: + name += " ;" + rest.split(" ;", 1)[1] req = Requirement(name) From b0c88b8295fdeb11c2c4341b408931f520d6231c Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 18:25:15 +0100 Subject: [PATCH 3/9] Add parse_requires tests Test copied from https://github.com/python-poetry/poetry/blob/299a885e880afce613f76927165dce3b1f55591c/tests/utils/test_helpers.py --- tests/_helpers/__init__.py | 0 tests/{ => _helpers}/utils.py | 0 tests/conftest.py | 2 +- tests/integration/test_pep517.py | 4 +-- tests/utils/__init__.py | 0 tests/utils/test_helpers.py | 49 ++++++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/_helpers/__init__.py rename tests/{ => _helpers}/utils.py (100%) create mode 100644 tests/utils/__init__.py create mode 100644 tests/utils/test_helpers.py diff --git a/tests/_helpers/__init__.py b/tests/_helpers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/utils.py b/tests/_helpers/utils.py similarity index 100% rename from tests/utils.py rename to tests/_helpers/utils.py diff --git a/tests/conftest.py b/tests/conftest.py index 1269d5bab..6f3fb784f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ import pytest from poetry.core.utils._compat import Path -from tests.utils import tempfile +from tests._helpers.utils import tempfile def pytest_addoption(parser): diff --git a/tests/integration/test_pep517.py b/tests/integration/test_pep517.py index 0ef13e21d..04d7b6023 100644 --- a/tests/integration/test_pep517.py +++ b/tests/integration/test_pep517.py @@ -6,8 +6,8 @@ from pep517.check import check from poetry.core.utils._compat import PY35 from poetry.core.utils._compat import Path -from tests.utils import subprocess_run -from tests.utils import temporary_project_directory +from tests._helpers.utils import subprocess_run +from tests._helpers.utils import temporary_project_directory pytestmark = pytest.mark.integration diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py new file mode 100644 index 000000000..9c10fbc89 --- /dev/null +++ b/tests/utils/test_helpers.py @@ -0,0 +1,49 @@ +import pytest + +from poetry.core.utils.helpers import parse_requires + + +def test_parse_requires(): + requires = """\ +jsonschema>=2.6.0.0,<3.0.0.0 +lockfile>=0.12.0.0,<0.13.0.0 +pip-tools>=1.11.0.0,<2.0.0.0 +pkginfo>=1.4.0.0,<2.0.0.0 +pyrsistent>=0.14.2.0,<0.15.0.0 +toml>=0.9.0.0,<0.10.0.0 +cleo>=0.6.0.0,<0.7.0.0 +cachy>=0.1.1.0,<0.2.0.0 +cachecontrol>=0.12.4.0,<0.13.0.0 +requests>=2.18.0.0,<3.0.0.0 +msgpack-python>=0.5.0.0,<0.6.0.0 +pyparsing>=2.2.0.0,<3.0.0.0 +requests-toolbelt>=0.8.0.0,<0.9.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"] +virtualenv>=15.2.0.0,<16.0.0.0 +pathlib2>=2.3.0.0,<3.0.0.0 +[:python_version >= "3.4.0.0" and python_version < "3.6.0.0"] +zipfile36>=0.1.0.0,<0.2.0.0 +""" + result = parse_requires(requires) + expected = [ + "jsonschema>=2.6.0.0,<3.0.0.0", + "lockfile>=0.12.0.0,<0.13.0.0", + "pip-tools>=1.11.0.0,<2.0.0.0", + "pkginfo>=1.4.0.0,<2.0.0.0", + "pyrsistent>=0.14.2.0,<0.15.0.0", + "toml>=0.9.0.0,<0.10.0.0", + "cleo>=0.6.0.0,<0.7.0.0", + "cachy>=0.1.1.0,<0.2.0.0", + "cachecontrol>=0.12.4.0,<0.13.0.0", + "requests>=2.18.0.0,<3.0.0.0", + "msgpack-python>=0.5.0.0,<0.6.0.0", + "pyparsing>=2.2.0.0,<3.0.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")', + '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"', + 'zipfile36>=0.1.0.0,<0.2.0.0; python_version >= "3.4.0.0" and python_version < "3.6.0.0"', + ] + assert result == expected From e09029d53f8ce376b83e60d0c0d7f1cfb7039784 Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 18:34:53 +0100 Subject: [PATCH 4/9] Add failing test for parse_requires --- tests/utils/test_helpers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index 9c10fbc89..c7d3ac2e9 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -25,6 +25,8 @@ def test_parse_requires(): pathlib2>=2.3.0.0,<3.0.0.0 [:python_version >= "3.4.0.0" and python_version < "3.6.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) expected = [ @@ -45,5 +47,6 @@ def test_parse_requires(): '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"', '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 From 69986e3a61a88b7dfebc9d37b77972a55b7ae017 Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 18:38:37 +0100 Subject: [PATCH 5/9] Fix parse_requires --- poetry/core/utils/helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/poetry/core/utils/helpers.py b/poetry/core/utils/helpers.py index c3e13f558..544169502 100644 --- a/poetry/core/utils/helpers.py +++ b/poetry/core/utils/helpers.py @@ -81,6 +81,8 @@ def parse_requires(requires): # type: (str) -> List[str] continue if current_marker: + if "@" in line: + line += " " line = "{}; {}".format(line, current_marker) requires_dist.append(line) From ba98fb82ae14b3155215a9cc9274a31dd2856ee2 Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 18:51:36 +0100 Subject: [PATCH 6/9] Fix lint errors --- tests/utils/test_helpers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index c7d3ac2e9..386833d00 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -1,5 +1,3 @@ -import pytest - from poetry.core.utils.helpers import parse_requires From 6c6942fc117635f8c7a7f63f8e485a864ff73e01 Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 19:07:36 +0100 Subject: [PATCH 7/9] Fix integration errors --- tests/_helpers/__init__.py | 0 tests/conftest.py | 2 +- tests/integration/test_pep517.py | 4 ++-- tests/{_helpers/utils.py => testutils.py} | 0 4 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 tests/_helpers/__init__.py rename tests/{_helpers/utils.py => testutils.py} (100%) diff --git a/tests/_helpers/__init__.py b/tests/_helpers/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/conftest.py b/tests/conftest.py index 6f3fb784f..b70a906b4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,7 @@ import pytest from poetry.core.utils._compat import Path -from tests._helpers.utils import tempfile +from tests.testutils import tempfile def pytest_addoption(parser): diff --git a/tests/integration/test_pep517.py b/tests/integration/test_pep517.py index 04d7b6023..568c1004a 100644 --- a/tests/integration/test_pep517.py +++ b/tests/integration/test_pep517.py @@ -6,8 +6,8 @@ from pep517.check import check from poetry.core.utils._compat import PY35 from poetry.core.utils._compat import Path -from tests._helpers.utils import subprocess_run -from tests._helpers.utils import temporary_project_directory +from tests.testutils import subprocess_run +from tests.testutils import temporary_project_directory pytestmark = pytest.mark.integration diff --git a/tests/_helpers/utils.py b/tests/testutils.py similarity index 100% rename from tests/_helpers/utils.py rename to tests/testutils.py From 1177b408c5e99a995116c71611cb005917ba47d2 Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 19:14:57 +0100 Subject: [PATCH 8/9] Update test_helpers.py --- tests/utils/test_helpers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index 386833d00..e2697421f 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -16,13 +16,17 @@ def test_parse_requires(): msgpack-python>=0.5.0.0,<0.6.0.0 pyparsing>=2.2.0.0,<3.0.0.0 requests-toolbelt>=0.8.0.0,<0.9.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"] virtualenv>=15.2.0.0,<16.0.0.0 pathlib2>=2.3.0.0,<3.0.0.0 + [:python_version >= "3.4.0.0" and python_version < "3.6.0.0"] zipfile36>=0.1.0.0,<0.2.0.0 + [dev] isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort """ From 69053b2280eda254c562c966dc550de81e402a4e Mon Sep 17 00:00:00 2001 From: simonepri Date: Sat, 25 Apr 2020 21:28:27 +0100 Subject: [PATCH 9/9] Update parse_requires fix --- poetry/core/utils/helpers.py | 4 +--- tests/utils/test_helpers.py | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/poetry/core/utils/helpers.py b/poetry/core/utils/helpers.py index 544169502..c4fe56741 100644 --- a/poetry/core/utils/helpers.py +++ b/poetry/core/utils/helpers.py @@ -81,9 +81,7 @@ def parse_requires(requires): # type: (str) -> List[str] continue if current_marker: - if "@" in line: - line += " " - line = "{}; {}".format(line, current_marker) + line = "{} ; {}".format(line, current_marker) requires_dist.append(line) diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index e2697421f..a2e423c1d 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -45,10 +45,10 @@ def test_parse_requires(): "msgpack-python>=0.5.0.0,<0.6.0.0", "pyparsing>=2.2.0.0,<3.0.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")', - '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"', - 'zipfile36>=0.1.0.0,<0.2.0.0; python_version >= "3.4.0.0" and python_version < "3.6.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"', + '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"', 'isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e528357650281a3d3ec22#egg=isort ; extra == "dev"', ] assert result == expected