From 06cdc7731b0223ab98642137b468d37d18771f6c Mon Sep 17 00:00:00 2001 From: finswimmer Date: Wed, 11 Dec 2019 18:49:57 +0100 Subject: [PATCH] fix (#1654): exporting to requirements.txt always prepends -e to dependencies (#1656) * fix (locker): add `develop = false` in `poetry.lock` if set in `pyproject.toml` fix (locker): read `develop` value from `poetry.lock` so it is respect when exporting to `requirements.txt` * fix (test_installer): adopt expected result * change (test_installer): move develop key from source to package in lock file * fix (test_installer): make black happy --- poetry/packages/locker.py | 5 +++++ poetry/puzzle/provider.py | 1 + ...irectory-dependency-poetry-transitive.test | 2 ++ .../with-directory-dependency-poetry.test | 1 + .../with-directory-dependency-setuptools.test | 1 + .../with-file-dependency-transitive.test | 1 + tests/installation/test_installer.py | 21 ++++++++++--------- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/poetry/packages/locker.py b/poetry/packages/locker.py index d59a757d5e6..f2eca202e81 100644 --- a/poetry/packages/locker.py +++ b/poetry/packages/locker.py @@ -138,6 +138,9 @@ def locked_repository( package.add_dependency(dep_name, constraint) + if "develop" in info: + package.develop = info["develop"] + if "source" in info: package.source_type = info["source"].get("type", "") package.source_url = info["source"]["url"] @@ -301,5 +304,7 @@ def _dump_package(self, package): # type: (poetry.packages.Package) -> dict } if package.source_type: data["source"]["type"] = package.source_type + if package.source_type == "directory": + data["develop"] = package.develop return data diff --git a/poetry/puzzle/provider.py b/poetry/puzzle/provider.py index 29390e70321..40b54cda971 100644 --- a/poetry/puzzle/provider.py +++ b/poetry/puzzle/provider.py @@ -275,6 +275,7 @@ def search_for_directory( ) package.source_url = dependency.path.as_posix() + package.develop = dependency.develop if dependency.base is not None: package.root_dir = dependency.base.as_posix() diff --git a/tests/installation/fixtures/with-directory-dependency-poetry-transitive.test b/tests/installation/fixtures/with-directory-dependency-poetry-transitive.test index cb1d1c65b86..06f262f74e6 100644 --- a/tests/installation/fixtures/with-directory-dependency-poetry-transitive.test +++ b/tests/installation/fixtures/with-directory-dependency-poetry-transitive.test @@ -1,6 +1,7 @@ [[package]] category = "main" description = "" +develop = true name = "project-with-extras" optional = false python-versions = "*" @@ -18,6 +19,7 @@ url = "tests/fixtures/directory/project_with_transitive_directory_dependencies/. [[package]] category = "main" description = "" +develop = true name = "project-with-transitive-directory-dependencies" optional = false python-versions = "*" diff --git a/tests/installation/fixtures/with-directory-dependency-poetry.test b/tests/installation/fixtures/with-directory-dependency-poetry.test index d90d69ab089..df8b282d684 100644 --- a/tests/installation/fixtures/with-directory-dependency-poetry.test +++ b/tests/installation/fixtures/with-directory-dependency-poetry.test @@ -9,6 +9,7 @@ version = "1.4.4" [[package]] category = "main" description = "" +develop = true name = "project-with-extras" optional = false python-versions = "*" diff --git a/tests/installation/fixtures/with-directory-dependency-setuptools.test b/tests/installation/fixtures/with-directory-dependency-setuptools.test index a187c2b1dec..b9a97381503 100644 --- a/tests/installation/fixtures/with-directory-dependency-setuptools.test +++ b/tests/installation/fixtures/with-directory-dependency-setuptools.test @@ -9,6 +9,7 @@ python-versions = "*" [[package]] name = "my-package" version = "0.1.2" +develop = true description = "Demo project." category = "main" optional = false diff --git a/tests/installation/fixtures/with-file-dependency-transitive.test b/tests/installation/fixtures/with-file-dependency-transitive.test index 13757e48fb3..db3b632694a 100644 --- a/tests/installation/fixtures/with-file-dependency-transitive.test +++ b/tests/installation/fixtures/with-file-dependency-transitive.test @@ -29,6 +29,7 @@ version = "1.4.4" [[package]] category = "main" description = "" +develop = true name = "project-with-transitive-file-dependencies" optional = false python-versions = "*" diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index a02b779cb22..1db1a2500ff 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -25,6 +25,9 @@ from tests.repositories.test_pypi_repository import MockRepository +fixtures_dir = Path("tests/fixtures") + + class Installer(BaseInstaller): def _get_installer(self): return NoopInstaller() @@ -662,7 +665,7 @@ def test_installer_with_pypi_repository(package, locker, installed): def test_run_installs_with_local_file(installer, locker, repo, package): - file_path = Path("tests/fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl") + file_path = fixtures_dir / "distributions/demo-0.1.0-py2.py3-none-any.whl" package.add_dependency("demo", {"file": str(file_path)}) repo.add_package(get_package("pendulum", "1.4.4")) @@ -677,8 +680,8 @@ def test_run_installs_with_local_file(installer, locker, repo, package): def test_run_installs_wheel_with_no_requires_dist(installer, locker, repo, package): - file_path = Path( - "tests/fixtures/wheel_with_no_requires_dist/demo-0.1.0-py2.py3-none-any.whl" + file_path = ( + fixtures_dir / "wheel_with_no_requires_dist/demo-0.1.0-py2.py3-none-any.whl" ) package.add_dependency("demo", {"file": str(file_path)}) @@ -694,7 +697,7 @@ def test_run_installs_wheel_with_no_requires_dist(installer, locker, repo, packa def test_run_installs_with_local_poetry_directory_and_extras( installer, locker, repo, package, tmpdir ): - file_path = Path("tests/fixtures/project_with_extras") + file_path = fixtures_dir / "project_with_extras" package.add_dependency( "project-with-extras", {"path": str(file_path), "extras": ["extras_a"]} ) @@ -713,8 +716,8 @@ def test_run_installs_with_local_poetry_directory_and_extras( def test_run_installs_with_local_poetry_directory_transitive( installer, locker, repo, package, tmpdir ): - file_path = Path( - "tests/fixtures/directory/project_with_transitive_directory_dependencies/" + file_path = ( + fixtures_dir / "directory/project_with_transitive_directory_dependencies/" ) package.add_dependency( "project-with-transitive-directory-dependencies", {"path": str(file_path)} @@ -735,9 +738,7 @@ def test_run_installs_with_local_poetry_directory_transitive( def test_run_installs_with_local_poetry_file_transitive( installer, locker, repo, package, tmpdir ): - file_path = Path( - "tests/fixtures/directory/project_with_transitive_file_dependencies/" - ) + file_path = fixtures_dir / "directory/project_with_transitive_file_dependencies/" package.add_dependency( "project-with-transitive-file-dependencies", {"path": str(file_path)} ) @@ -757,7 +758,7 @@ def test_run_installs_with_local_poetry_file_transitive( def test_run_installs_with_local_setuptools_directory( installer, locker, repo, package, tmpdir ): - file_path = Path("tests/fixtures/project_with_setup/") + file_path = fixtures_dir / "project_with_setup/" package.add_dependency("my-package", {"path": str(file_path)}) repo.add_package(get_package("pendulum", "1.4.4"))