Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create path dependencies relative to package rather than lockfile (#4245) #4246

Merged
merged 3 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,26 @@ 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":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to handle file source types too

# root dir should be the source of the package relative to the lock path
root_dir = Path(
os.path.relpath(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of points;

  1. Move to using pathlib if possible.
  2. We cannot always be sure a "directory" package is relative as it could also be an absolute path.

Path(package.source_url), self._lock.path.parent
)
).resolve()

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:
Expand Down
44 changes: 43 additions & 1 deletion tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_lock_file_should_not_have_mixed_types(locker, root):


def test_reading_lock_file_should_raise_an_error_on_invalid_data(locker):
content = u"""[[package]]
content = """[[package]]
name = "A"
version = "1.0.0"
description = ""
Expand Down Expand Up @@ -598,3 +598,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", autospec=True
)
locker.locked_repository()

create_dependency_patch.assert_called_once_with(
"lib-b", {"develop": True, "path": "../libB"}, root_dir=mocker.ANY
)
root_dir = create_dependency_patch.call_args.kwargs["root_dir"]
assert root_dir.match("*/lib/libA")
assert root_dir.is_relative_to(locker.lock.path.parent.resolve())