From 636be1458329042e2e050c9d4693a5f2abbd678e Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Mon, 22 Aug 2022 09:43:45 +0200 Subject: [PATCH 1/3] test(locker): add test to ensure sorted order --- tests/packages/test_locker.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index 38ddcb12eec..ecb24f5fa75 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -598,6 +598,49 @@ def test_locker_dumps_dependency_information_correctly(locker, root): assert expected == content +def test_locker_dumps_dependency_extras_in_correct_order(locker, root): + root_dir = Path(__file__).parent.parent.joinpath("fixtures") + package_a = get_package("A", "1.0.0") + 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) + + package_a.extras = { + "C": [package_third, package_second, package_first], + "B": [package_first, package_second, package_third], + } + + locker.set_lock_data(root, [package_a]) + + with locker.lock.open(encoding="utf-8") as f: + content = f.read() + + expected = """[[package]] +name = "A" +version = "1.0.0" +description = "" +category = "main" +optional = false +python-versions = "*" + +[package.extras] +B = ["first (==1.0.0)", "second (==1.0.0)", "third (==1.0.0)"] +C = ["first (==1.0.0)", "second (==1.0.0)", "third (==1.0.0)"] + +[metadata] +lock-version = "1.1" +python-versions = "*" +content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8" + +[metadata.files] +A = [] +""" + + assert content == expected + + @pytest.mark.skipif(sys.version_info[:2] == (3, 5), reason="Skip for Python 3.5") def test_locked_repository_uses_root_dir_of_package(locker, mocker): content = """\ From 91423d5585e5bdc611a979ed0e15e2870242a8fb Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Mon, 22 Aug 2022 09:48:06 +0200 Subject: [PATCH 2/3] fix(locker): sort dependencies of extras --- poetry/packages/locker.py | 6 +++--- tests/installation/fixtures/with-pypi-repository.test | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/poetry/packages/locker.py b/poetry/packages/locker.py index 68ba611d48a..4829e2345bb 100644 --- a/poetry/packages/locker.py +++ b/poetry/packages/locker.py @@ -570,14 +570,14 @@ def _dump_package(self, package): # type: (Package) -> dict data["dependencies"][k].append(constraint) if package.extras: - extras = {} + extras = OrderedDict() for name, deps in package.extras.items(): # TODO: This should use dep.to_pep_508() once this is fixed # https://github.com/python-poetry/poetry-core/pull/102 - extras[name] = [ + extras[name] = sorted( dep.base_pep_508_name if not dep.constraint.is_any() else dep.name for dep in deps - ] + ) data["extras"] = extras diff --git a/tests/installation/fixtures/with-pypi-repository.test b/tests/installation/fixtures/with-pypi-repository.test index 3f3719452d9..37a5b52868c 100644 --- a/tests/installation/fixtures/with-pypi-repository.test +++ b/tests/installation/fixtures/with-pypi-repository.test @@ -7,7 +7,7 @@ optional = false python-versions = "*" [package.extras] -dev = ["coverage", "hypothesis", "pympler", "pytest", "six", "zope.interface", "sphinx", "zope.interface"] +dev = ["coverage", "hypothesis", "pympler", "pytest", "six", "sphinx", "zope.interface", "zope.interface"] docs = ["sphinx", "zope.interface"] tests = ["coverage", "hypothesis", "pympler", "pytest", "six", "zope.interface"] From b1aff59089964a63e5380eca1b6a3c19b54f6374 Mon Sep 17 00:00:00 2001 From: Mathieu Kniewallner Date: Mon, 22 Aug 2022 09:48:53 +0200 Subject: [PATCH 3/3] fix(locker): sort extras --- poetry/packages/locker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry/packages/locker.py b/poetry/packages/locker.py index 4829e2345bb..4ab23342054 100644 --- a/poetry/packages/locker.py +++ b/poetry/packages/locker.py @@ -571,7 +571,7 @@ def _dump_package(self, package): # type: (Package) -> dict if package.extras: extras = OrderedDict() - for name, deps in package.extras.items(): + for name, deps in sorted(package.extras.items()): # TODO: This should use dep.to_pep_508() once this is fixed # https://github.com/python-poetry/poetry-core/pull/102 extras[name] = sorted(