From 789a00def64b89783634d41df10187b5ae41feb9 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Wed, 5 Feb 2020 19:46:55 -0600 Subject: [PATCH] respect `develop` when installing from git * fixes #1080, again --- poetry/json/schemas/poetry-schema.json | 4 ++ poetry/packages/locker.py | 2 +- poetry/packages/package.py | 1 + poetry/packages/vcs_dependency.py | 6 +++ poetry/puzzle/provider.py | 6 ++- poetry/utils/exporter.py | 4 +- .../fixtures/with-vcs-dependency-poetry.test | 37 +++++++++++++++++++ tests/installation/test_installer.py | 17 +++++++++ tests/puzzle/test_provider.py | 8 +++- tests/utils/test_exporter.py | 26 +++++++++++-- 10 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 tests/installation/fixtures/with-vcs-dependency-poetry.test diff --git a/poetry/json/schemas/poetry-schema.json b/poetry/json/schemas/poetry-schema.json index 10aff39e502..8397ba8aba7 100644 --- a/poetry/json/schemas/poetry-schema.json +++ b/poetry/json/schemas/poetry-schema.json @@ -326,6 +326,10 @@ "items": { "type": "string" } + }, + "develop": { + "type": "boolean", + "description": "Whether to install the dependency in development mode." } } }, diff --git a/poetry/packages/locker.py b/poetry/packages/locker.py index f2eca202e81..400816728d3 100644 --- a/poetry/packages/locker.py +++ b/poetry/packages/locker.py @@ -304,7 +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": + if package.source_type in {"directory", "git"}: data["develop"] = package.develop return data diff --git a/poetry/packages/package.py b/poetry/packages/package.py index 5b7dfea09d1..63720bbe7eb 100644 --- a/poetry/packages/package.py +++ b/poetry/packages/package.py @@ -297,6 +297,7 @@ def add_dependency( branch=constraint.get("branch", None), tag=constraint.get("tag", None), rev=constraint.get("rev", None), + develop=constraint.get("develop", True), category=category, optional=optional, ) diff --git a/poetry/packages/vcs_dependency.py b/poetry/packages/vcs_dependency.py index 7574b8dbac3..fa642acd756 100644 --- a/poetry/packages/vcs_dependency.py +++ b/poetry/packages/vcs_dependency.py @@ -18,6 +18,7 @@ def __init__( rev=None, category="main", optional=False, + develop=True, ): self._vcs = vcs self._source = source @@ -29,6 +30,7 @@ def __init__( self._branch = branch self._tag = tag self._rev = rev + self._develop = develop super(VCSDependency, self).__init__( name, "*", category=category, optional=optional, allows_prereleases=True @@ -58,6 +60,10 @@ def rev(self): def reference(self): # type: () -> str return self._branch or self._tag or self._rev + @property + def develop(self): + return self._develop + @property def pretty_constraint(self): # type: () -> str if self._branch: diff --git a/poetry/puzzle/provider.py b/poetry/puzzle/provider.py index 989a592912b..a806498bed9 100644 --- a/poetry/puzzle/provider.py +++ b/poetry/puzzle/provider.py @@ -169,6 +169,7 @@ def search_for_vcs(self, dependency): # type: (VCSDependency) -> List[Package] dependency.source, dependency.reference, name=dependency.name, + develop=dependency.develop, ) for extra in dependency.extras: @@ -182,8 +183,8 @@ def search_for_vcs(self, dependency): # type: (VCSDependency) -> List[Package] @classmethod def get_package_from_vcs( - cls, vcs, url, reference=None, name=None - ): # type: (str, str, Optional[str], Optional[str]) -> Package + cls, vcs, url, reference=None, name=None, develop=True, + ): # type: (str, str, Optional[str], Optional[str], Optional[bool]) -> Package if vcs != "git": raise ValueError("Unsupported VCS dependency {}".format(vcs)) @@ -206,6 +207,7 @@ def get_package_from_vcs( package.source_type = "git" package.source_url = url package.source_reference = revision + package.develop = develop except Exception: raise finally: diff --git a/poetry/utils/exporter.py b/poetry/utils/exporter.py index 9341962d4fb..c63abcb17bf 100644 --- a/poetry/utils/exporter.py +++ b/poetry/utils/exporter.py @@ -78,9 +78,11 @@ def _export_requirements_txt( package.source_reference, ) dependency.marker = package.marker - line = "-e git+{}@{}#egg={}".format( + line = "git+{}@{}#egg={}".format( package.source_url, package.source_reference, package.name ) + if package.develop: + line = "-e " + line elif package.source_type in ["directory", "file", "url"]: if package.source_type == "file": dependency = FileDependency(package.name, Path(package.source_url)) diff --git a/tests/installation/fixtures/with-vcs-dependency-poetry.test b/tests/installation/fixtures/with-vcs-dependency-poetry.test new file mode 100644 index 00000000000..8a0cac931a8 --- /dev/null +++ b/tests/installation/fixtures/with-vcs-dependency-poetry.test @@ -0,0 +1,37 @@ +[[package]] +category = "main" +description = "Demo project." +develop = false +name = "demo" +optional = false +python-versions = "*" +version = "0.1.2" + +[package.dependencies] +pendulum = ">=1.4.4" + +[package.extras] +bar = ["tomlkit"] +foo = ["cleo"] + +[package.source] +reference = "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24" +type = "git" +url = "https://github.com/demo/demo.git" + +[[package]] +description = "" +category = "main" +name = "pendulum" +optional = false +python-versions = "*" +version = "1.4.4" + +[metadata] +python-versions = "*" +content-hash = "123456789" + +[metadata.files] +demo = [] +pendulum = [] + diff --git a/tests/installation/test_installer.py b/tests/installation/test_installer.py index c236141be44..d9aecaf91cc 100644 --- a/tests/installation/test_installer.py +++ b/tests/installation/test_installer.py @@ -713,6 +713,23 @@ def test_run_installs_with_local_poetry_directory_and_extras( assert len(installer.installer.installs) == 2 +def test_run_installs_with_git_and_develop_false( + installer, locker, repo, package, tmpdir +): + package.add_dependency( + "demo", {"git": "https://github.com/demo/demo.git", "develop": False} + ) + repo.add_package(get_package("pendulum", "1.4.4")) + + installer.run() + + expected = fixture("with-vcs-dependency-poetry") + + assert locker.written_data == expected + + assert len(installer.installer.installs) == 2 + + def test_run_installs_with_local_poetry_directory_transitive( installer, locker, repo, package, tmpdir ): diff --git a/tests/puzzle/test_provider.py b/tests/puzzle/test_provider.py index d3bcba65688..d2b96831d86 100644 --- a/tests/puzzle/test_provider.py +++ b/tests/puzzle/test_provider.py @@ -46,8 +46,11 @@ def provider(root, pool): return Provider(root, pool, NullIO()) -def test_search_for_vcs_setup_egg_info(provider): - dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git") +@pytest.mark.parametrize("develop", [True, False]) +def test_search_for_vcs_setup_egg_info(provider, develop): + dependency = VCSDependency( + "demo", "git", "https://github.com/demo/demo.git", develop=develop + ) package = provider.search_for_vcs(dependency)[0] @@ -58,6 +61,7 @@ def test_search_for_vcs_setup_egg_info(provider): "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], } + assert package.develop == develop def test_search_for_vcs_setup_egg_info_with_extras(provider): diff --git a/tests/utils/test_exporter.py b/tests/utils/test_exporter.py index 0c05c907629..3517bfcccbe 100644 --- a/tests/utils/test_exporter.py +++ b/tests/utils/test_exporter.py @@ -413,7 +413,10 @@ def test_exporter_exports_requirements_txt_with_optional_packages_if_opted_in( assert expected == content -def test_exporter_can_export_requirements_txt_with_git_packages(tmp_dir, poetry): +@pytest.mark.parametrize("develop", [True, False]) +def test_exporter_can_export_requirements_txt_with_git_packages( + tmp_dir, poetry, develop +): poetry.locker.mock_lock_data( { "package": [ @@ -423,6 +426,7 @@ def test_exporter_can_export_requirements_txt_with_git_packages(tmp_dir, poetry) "category": "main", "optional": False, "python-versions": "*", + "develop": develop, "source": { "type": "git", "url": "https://github.com/foo/foo.git", @@ -444,8 +448,13 @@ def test_exporter_can_export_requirements_txt_with_git_packages(tmp_dir, poetry) with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f: content = f.read() - expected = """\ + if develop: + expected = """\ -e git+https://github.com/foo/foo.git@123456#egg=foo +""" + else: + expected = """\ +git+https://github.com/foo/foo.git@123456#egg=foo """ assert expected == content @@ -492,7 +501,10 @@ def test_exporter_can_export_requirements_txt_with_git_packages_and_markers( assert expected == content -def test_exporter_can_export_requirements_txt_with_directory_packages(tmp_dir, poetry): +@pytest.mark.parametrize("develop", [True, False]) +def test_exporter_can_export_requirements_txt_with_directory_packages( + tmp_dir, poetry, develop +): poetry.locker.mock_lock_data( { "package": [ @@ -502,6 +514,7 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(tmp_dir, p "category": "main", "optional": False, "python-versions": "*", + "develop": develop, "source": { "type": "directory", "url": "tests/fixtures/sample_project", @@ -523,8 +536,13 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(tmp_dir, p with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f: content = f.read() - expected = """\ + if develop: + expected = """\ -e tests/fixtures/sample_project +""" + else: + expected = """\ +tests/fixtures/sample_project """ assert expected == content