Skip to content

Commit 09cf19b

Browse files
committed
Fix locked information for path, url and VCS dependencies
1 parent 67c1b34 commit 09cf19b

File tree

4 files changed

+96
-8
lines changed

4 files changed

+96
-8
lines changed

poetry/packages/locker.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,25 @@ def _dump_package(self, package): # type: (Package) -> dict
504504
dependencies[dependency.pretty_name] = []
505505

506506
constraint = inline_table()
507-
constraint["version"] = str(dependency.pretty_constraint)
507+
508+
if dependency.is_directory() or dependency.is_file():
509+
constraint["path"] = dependency.path.as_posix()
510+
511+
if dependency.is_directory() and dependency.develop:
512+
constraint["develop"] = True
513+
elif dependency.is_url():
514+
constraint["url"] = dependency.url
515+
elif dependency.is_vcs():
516+
constraint[dependency.vcs] = dependency.source
517+
518+
if dependency.branch:
519+
constraint["branch"] = dependency.branch
520+
elif dependency.tag:
521+
constraint["tag"] = dependency.tag
522+
elif dependency.rev:
523+
constraint["rev"] = dependency.rev
524+
else:
525+
constraint["version"] = str(dependency.pretty_constraint)
508526

509527
if dependency.extras:
510528
constraint["extras"] = sorted(dependency.extras)
@@ -520,7 +538,10 @@ def _dump_package(self, package): # type: (Package) -> dict
520538
# All the constraints should have the same type,
521539
# but we want to simplify them if it's possible
522540
for dependency, constraints in tuple(dependencies.items()):
523-
if all(len(constraint) == 1 for constraint in constraints):
541+
if all(
542+
len(constraint) == 1 and "version" in constraint
543+
for constraint in constraints
544+
):
524545
dependencies[dependency] = [
525546
constraint["version"] for constraint in constraints
526547
]

tests/installation/fixtures/with-directory-dependency-poetry-transitive.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ python-versions = "*"
6565
version = "1.2.3"
6666

6767
[package.dependencies]
68-
project-with-extras = "1.2.3"
69-
project-with-transitive-file-dependencies = "1.2.3"
68+
project-with-extras = { "path" = "../../project_with_extras" }
69+
project-with-transitive-file-dependencies = { "path" = "../project_with_transitive_file_dependencies" }
7070

7171
[package.source]
7272
type = "directory"
@@ -82,8 +82,8 @@ python-versions = "*"
8282
version = "1.2.3"
8383

8484
[package.dependencies]
85-
demo = "0.1.0"
86-
inner-directory-project = "1.2.4"
85+
demo = { "path" = "../../distributions/demo-0.1.0-py2.py3-none-any.whl" }
86+
inner-directory-project = { "path" = "inner-directory-project" }
8787

8888
[package.source]
8989
type = "directory"

tests/installation/fixtures/with-file-dependency-transitive.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ python-versions = "*"
4848
version = "1.2.3"
4949

5050
[package.dependencies]
51-
demo = "0.1.0"
52-
inner-directory-project = "1.2.4"
51+
demo = { "path" = "../../distributions/demo-0.1.0-py2.py3-none-any.whl" }
52+
inner-directory-project = { "path" = "inner-directory-project" }
5353

5454
[package.source]
5555
type = "directory"

tests/packages/test_locker.py

+67
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import tempfile
33

4+
from pathlib import Path
5+
46
import pytest
57
import tomlkit
68

@@ -529,3 +531,68 @@ def test_locker_should_neither_emit_warnings_nor_raise_error_for_lower_compatibl
529531
_ = locker.lock_data
530532

531533
assert 0 == len(caplog.records)
534+
535+
536+
def test_locker_dumps_dependency_information_correctly(locker, root):
537+
root_dir = Path(__file__).parent.parent.joinpath("fixtures")
538+
package_a = get_package("A", "1.0.0")
539+
package_a.add_dependency(
540+
Factory.create_dependency(
541+
"B", {"path": "project_with_extras", "develop": True}, root_dir=root_dir
542+
)
543+
)
544+
package_a.add_dependency(
545+
Factory.create_dependency(
546+
"C",
547+
{"path": "directory/project_with_transitive_directory_dependencies"},
548+
root_dir=root_dir,
549+
)
550+
)
551+
package_a.add_dependency(
552+
Factory.create_dependency(
553+
"D", {"path": "distributions/demo-0.1.0.tar.gz"}, root_dir=root_dir
554+
)
555+
)
556+
package_a.add_dependency(
557+
Factory.create_dependency(
558+
"E", {"url": "https://python-poetry.org/poetry-1.2.0.tar.gz"}
559+
)
560+
)
561+
package_a.add_dependency(
562+
Factory.create_dependency(
563+
"F", {"git": "https://github.com/python-poetry/poetry.git", "branch": "foo"}
564+
)
565+
)
566+
567+
packages = [package_a]
568+
569+
locker.set_lock_data(root, packages)
570+
571+
with locker.lock.open(encoding="utf-8") as f:
572+
content = f.read()
573+
574+
expected = """[[package]]
575+
name = "A"
576+
version = "1.0.0"
577+
description = ""
578+
category = "main"
579+
optional = false
580+
python-versions = "*"
581+
582+
[package.dependencies]
583+
B = {path = "project_with_extras", develop = true}
584+
C = {path = "directory/project_with_transitive_directory_dependencies"}
585+
D = {path = "distributions/demo-0.1.0.tar.gz"}
586+
E = {url = "https://python-poetry.org/poetry-1.2.0.tar.gz"}
587+
F = {git = "https://github.com/python-poetry/poetry.git", branch = "foo"}
588+
589+
[metadata]
590+
lock-version = "1.1"
591+
python-versions = "*"
592+
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
593+
594+
[metadata.files]
595+
A = []
596+
"""
597+
598+
assert expected == content

0 commit comments

Comments
 (0)