From 2cab0744059360c32904ab54a7661ef85c93e92e Mon Sep 17 00:00:00 2001 From: Yeger Date: Fri, 20 Jan 2023 19:04:31 +0200 Subject: [PATCH] Order root extra dependencies (#7375) --- src/poetry/packages/locker.py | 2 +- tests/packages/test_locker.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py index 7fd19669457..7fa0e6ffce9 100644 --- a/src/poetry/packages/locker.py +++ b/src/poetry/packages/locker.py @@ -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()) } diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index 268658a3ff1..23022d41c66 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -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(