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

locker: sort by name and version so that multiple versions of the sam… #5446

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -472,7 +472,7 @@ def _get_lock_data(self) -> TOMLDocument:
def _lock_packages(self, packages: list[Package]) -> list:
locked = []

for package in sorted(packages, key=lambda x: x.name):
for package in sorted(packages, key=lambda x: (x.name, x.version)):
spec = self._dump_package(package)

locked.append(spec)
Expand Down
16 changes: 14 additions & 2 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def test_lock_file_data_is_ordered(locker: Locker, root: ProjectPackage):
package_a = get_package("A", "1.0.0")
package_a.add_dependency(Factory.create_dependency("B", "^1.0"))
package_a.files = [{"file": "foo", "hash": "456"}, {"file": "bar", "hash": "123"}]
package_a2 = get_package("A", "2.0.0")
package_a2.files = [{"file": "baz", "hash": "345"}]
package_git = Package(
"git-package",
"1.2.3",
Expand All @@ -50,14 +52,15 @@ def test_lock_file_data_is_ordered(locker: Locker, root: ProjectPackage):
source_reference="develop",
source_resolved_reference="123456",
)
packages = [package_a, get_package("B", "1.2"), package_git]
packages = [package_a2, package_a, get_package("B", "1.2"), package_git]

locker.set_lock_data(root, packages)

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

expected = """[[package]]
expected = """\
[[package]]
name = "A"
version = "1.0.0"
description = ""
Expand All @@ -68,6 +71,14 @@ def test_lock_file_data_is_ordered(locker: Locker, root: ProjectPackage):
[package.dependencies]
B = "^1.0"

[[package]]
name = "A"
version = "2.0.0"
description = ""
category = "main"
optional = false
python-versions = "*"

[[package]]
name = "B"
version = "1.2"
Expand Down Expand Up @@ -100,6 +111,7 @@ def test_lock_file_data_is_ordered(locker: Locker, root: ProjectPackage):
A = [
{file = "bar", hash = "123"},
{file = "foo", hash = "456"},
{file = "baz", hash = "345"},
]
B = []
git-package = []
Expand Down