Skip to content

Commit 716ee92

Browse files
authored
Merge pull request #4331 from python-poetry/1.1-fix-relative-paths-dependencies-locking
[1.1] fix: create path dependencies relative to package rather than lockfile
2 parents cdb58c6 + b48e4e7 commit 716ee92

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

poetry/packages/locker.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,22 @@ def locked_repository(
174174
package.marker = parse_marker(split_dep[1].strip())
175175

176176
for dep_name, constraint in info.get("dependencies", {}).items():
177+
178+
root_dir = self._lock.path.parent
179+
if package.source_type == "directory":
180+
# root dir should be the source of the package relative to the lock path
181+
root_dir = Path(package.source_url)
182+
177183
if isinstance(constraint, list):
178184
for c in constraint:
179185
package.add_dependency(
180-
Factory.create_dependency(
181-
dep_name, c, root_dir=self._lock.path.parent
182-
)
186+
Factory.create_dependency(dep_name, c, root_dir=root_dir)
183187
)
184188

185189
continue
186190

187191
package.add_dependency(
188-
Factory.create_dependency(
189-
dep_name, constraint, root_dir=self._lock.path.parent
190-
)
192+
Factory.create_dependency(dep_name, constraint, root_dir=root_dir)
191193
)
192194

193195
if "develop" in info:

tests/packages/test_locker.py

+44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import sys
23
import tempfile
34

45
import pytest
@@ -595,3 +596,46 @@ def test_locker_dumps_dependency_information_correctly(locker, root):
595596
"""
596597

597598
assert expected == content
599+
600+
601+
@pytest.mark.skipif(sys.version_info[:2] == (3, 5), reason="Skip for Python 3.5")
602+
def test_locked_repository_uses_root_dir_of_package(locker, mocker):
603+
content = """\
604+
[[package]]
605+
name = "lib-a"
606+
version = "0.1.0"
607+
description = ""
608+
category = "main"
609+
optional = false
610+
python-versions = "^2.7.9"
611+
develop = true
612+
613+
[package.dependencies]
614+
lib-b = {path = "../libB", develop = true}
615+
616+
[package.source]
617+
type = "directory"
618+
url = "lib/libA"
619+
620+
[metadata]
621+
lock-version = "1.1"
622+
python-versions = "*"
623+
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
624+
625+
[metadata.files]
626+
lib-a = []
627+
lib-b = []
628+
"""
629+
630+
locker.lock.write(tomlkit.parse(content))
631+
create_dependency_patch = mocker.patch("poetry.factory.Factory.create_dependency")
632+
locker.locked_repository()
633+
634+
create_dependency_patch.assert_called_once_with(
635+
"lib-b", {"develop": True, "path": "../libB"}, root_dir=mocker.ANY
636+
)
637+
call_kwargs = create_dependency_patch.call_args[1]
638+
root_dir = call_kwargs["root_dir"]
639+
assert root_dir.match("*/lib/libA")
640+
# relative_to raises an exception if not relative - is_relative_to comes in py3.9
641+
assert root_dir.relative_to(locker.lock.path.parent.resolve()) is not None

0 commit comments

Comments
 (0)