Skip to content

Commit

Permalink
Order root extra dependencies (#7375)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeger00 authored Jan 20, 2023
1 parent 7279a07 commit 2cab074
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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: sorted(dep.pretty_name for dep in deps)
for extra, deps in sorted(root.extras.items())
}

Expand Down
35 changes: 35 additions & 0 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,41 @@ 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],
}
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

0 comments on commit 2cab074

Please sign in to comment.