Skip to content

Commit

Permalink
[1.1] Sort extras and extras dependencies in lock file (#6207)
Browse files Browse the repository at this point in the history
* test(locker): add test to ensure sorted order

* fix(locker): sort dependencies of extras

* fix(locker): sort extras
  • Loading branch information
mkniewallner authored Aug 22, 2022
1 parent 7cd0307 commit 4bd98ac
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
8 changes: 4 additions & 4 deletions poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,14 @@ def _dump_package(self, package): # type: (Package) -> dict
data["dependencies"][k].append(constraint)

if package.extras:
extras = {}
for name, deps in package.extras.items():
extras = OrderedDict()
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] = [
extras[name] = sorted(
dep.base_pep_508_name if not dep.constraint.is_any() else dep.name
for dep in deps
]
)

data["extras"] = extras

Expand Down
2 changes: 1 addition & 1 deletion tests/installation/fixtures/with-pypi-repository.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
43 changes: 43 additions & 0 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand Down

0 comments on commit 4bd98ac

Please # to comment.