From ffb56014ebcf8886aec8f8f59dfb29b5ca3421c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Thu, 29 Jul 2021 17:28:44 +0200 Subject: [PATCH] Merge pull request #4246 from zumper/m.4245-relative-paths fix: create path dependencies relative to package rather than lockfile (#4245) --- poetry/packages/locker.py | 14 +++++++----- tests/packages/test_locker.py | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/poetry/packages/locker.py b/poetry/packages/locker.py index d3f62c3b941..586eae8da1a 100644 --- a/poetry/packages/locker.py +++ b/poetry/packages/locker.py @@ -174,20 +174,22 @@ def locked_repository( package.marker = parse_marker(split_dep[1].strip()) for dep_name, constraint in info.get("dependencies", {}).items(): + + root_dir = self._lock.path.parent + if package.source_type == "directory": + # root dir should be the source of the package relative to the lock path + root_dir = Path(package.source_url) + if isinstance(constraint, list): for c in constraint: package.add_dependency( - Factory.create_dependency( - dep_name, c, root_dir=self._lock.path.parent - ) + Factory.create_dependency(dep_name, c, root_dir=root_dir) ) continue package.add_dependency( - Factory.create_dependency( - dep_name, constraint, root_dir=self._lock.path.parent - ) + Factory.create_dependency(dep_name, constraint, root_dir=root_dir) ) if "develop" in info: diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index ecb8bcb870b..f7572a10fd5 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -595,3 +595,45 @@ def test_locker_dumps_dependency_information_correctly(locker, root): """ assert expected == content + + +def test_locked_repository_uses_root_dir_of_package(locker, mocker): + content = """\ +[[package]] +name = "lib-a" +version = "0.1.0" +description = "" +category = "main" +optional = false +python-versions = "^2.7.9" +develop = true + +[package.dependencies] +lib-b = {path = "../libB", develop = true} + +[package.source] +type = "directory" +url = "lib/libA" + +[metadata] +lock-version = "1.1" +python-versions = "*" +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" + +[metadata.files] +lib-a = [] +lib-b = [] +""" + + locker.lock.write(tomlkit.parse(content)) + create_dependency_patch = mocker.patch("poetry.factory.Factory.create_dependency") + locker.locked_repository() + + create_dependency_patch.assert_called_once_with( + "lib-b", {"develop": True, "path": "../libB"}, root_dir=mocker.ANY + ) + call_kwargs = create_dependency_patch.call_args[1] + root_dir = call_kwargs["root_dir"] + assert root_dir.match("*/lib/libA") + # relative_to raises an exception if not relative - is_relative_to comes in py3.9 + assert root_dir.relative_to(locker.lock.path.parent.resolve()) is not None