Skip to content

Commit

Permalink
respect develop when installing from git
Browse files Browse the repository at this point in the history
* fixes python-poetry#1080, again
  • Loading branch information
fantix committed Feb 6, 2020
1 parent ed44342 commit 4398a35
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 10 deletions.
4 changes: 4 additions & 0 deletions poetry/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@
"items": {
"type": "string"
}
},
"develop": {
"type": "boolean",
"description": "Whether to install the dependency in development mode."
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions poetry/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
6 changes: 6 additions & 0 deletions poetry/packages/vcs_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(
rev=None,
category="main",
optional=False,
develop=True,
):
self._vcs = vcs
self._source = source
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion poetry/utils/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
37 changes: 37 additions & 0 deletions tests/installation/fixtures/with-vcs-dependency-poetry.test
Original file line number Diff line number Diff line change
@@ -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 = []

17 changes: 17 additions & 0 deletions tests/installation/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
8 changes: 6 additions & 2 deletions tests/puzzle/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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):
Expand Down
26 changes: 22 additions & 4 deletions tests/utils/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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": [
Expand All @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 4398a35

Please sign in to comment.