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

Order root extra dependencies #7375

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def set_lock_data(self, root: Package, packages: list[Package]) -> bool:

if root.extras:
lock["extras"] = {
extra: [dep.pretty_name for dep in deps]
extra: [dep.pretty_name for dep in sorted(deps, key=lambda dep: dep.pretty_name)]
radoering marked this conversation as resolved.
Show resolved Hide resolved
for extra, deps in sorted(root.extras.items())
}

Expand Down
37 changes: 37 additions & 0 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,43 @@ def test_locker_should_raise_an_error_if_lock_version_is_newer_and_not_allowed(
_ = locker.lock_data


def test_root_extras_dependencies_are_ordered(locker: Locker, root: ProjectPackage):
root_dir = Path(__file__).parent.parent.joinpath("fixtures")
Factory.create_dependency("B", "1.0.0", root_dir=root_dir)
Factory.create_dependency("C", "1.0.0", root_dir=root_dir)
package_first = Factory.create_dependency("first", "1.0.0", root_dir=root_dir)
package_second = Factory.create_dependency("second", "1.0.0", root_dir=root_dir)
package_third = Factory.create_dependency("third", "1.0.0", root_dir=root_dir)

root.extras = {
"C": [package_third, package_second, package_first],
"B": [package_first, package_second, package_third],
}
# root.requires[-1].activate()

locker.set_lock_data(root, [])

expected = f"""\
# {GENERATED_COMMENT}
package = []

[extras]
B = ["first", "second", "third"]
C = ["first", "second", "third"]

[metadata]
lock-version = "2.0"
python-versions = "*"
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
""" # noqa: E800

with locker.lock.open(encoding="utf-8") as f:
content = f.read()

print(content)
assert content == expected


def test_extras_dependencies_are_ordered(locker: Locker, root: ProjectPackage):
package_a = get_package("A", "1.0.0")
package_a.add_dependency(
Expand Down