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

Fix pip-compile package ordering #1419

Merged
merged 4 commits into from Jun 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion piptools/writer.py
Expand Up @@ -89,7 +89,7 @@ def __init__(
self.emit_find_links = emit_find_links

def _sort_key(self, ireq: InstallRequirement) -> Tuple[bool, str]:
return (not ireq.editable, str(ireq.req).lower())
return (not ireq.editable, key_from_ireq(ireq))

def write_header(self) -> Iterator[str]:
if self.emit_header:
Expand Down
18 changes: 9 additions & 9 deletions tests/test_cli_compile.py
Expand Up @@ -827,10 +827,10 @@ def test_generate_hashes_with_annotations(runner):
@pytest.mark.network
def test_generate_hashes_with_long_annotations(runner):
with open("requirements.in", "w") as fp:
fp.write("Django==1.11.29\n")
fp.write("django-debug-toolbar==1.11\n")
fp.write("django-storages==1.9.1\n")
fp.write("django-taggit==0.24.0\n")
fp.write("Django==1.11.29\n")
fp.write("pytz==2020.4\n")
fp.write("sqlparse==0.3.1\n")

Expand All @@ -844,6 +844,14 @@ def test_generate_hashes_with_long_annotations(runner):
#
# pip-compile --generate-hashes
#
django==1.11.29 \\
--hash=sha256:014e3392058d94f40569206a24523ce254d55ad2f9f46c6550b0fe2e4f94cf3f \\
--hash=sha256:4200aefb6678019a0acf0005cd14cfce3a5e6b9b90d06145fcdd2e474ad4329c
# via
# -r requirements.in
# django-debug-toolbar
# django-storages
# django-taggit
django-debug-toolbar==1.11 \\
--hash=sha256:89d75b60c65db363fb24688d977e5fbf0e73386c67acf562d278402a10fc3736 \\
--hash=sha256:c2b0134119a624f4ac9398b44f8e28a01c7686ac350a12a74793f3dd57a9eea0
Expand All @@ -856,14 +864,6 @@ def test_generate_hashes_with_long_annotations(runner):
--hash=sha256:710b4d15ec1996550cc68a0abbc41903ca7d832540e52b1336e6858737e410d8 \\
--hash=sha256:bb8f27684814cd1414b2af75b857b5e26a40912631904038a7ecacd2bfafc3ac
# via -r requirements.in
django==1.11.29 \\
--hash=sha256:014e3392058d94f40569206a24523ce254d55ad2f9f46c6550b0fe2e4f94cf3f \\
--hash=sha256:4200aefb6678019a0acf0005cd14cfce3a5e6b9b90d06145fcdd2e474ad4329c
# via
# -r requirements.in
# django-debug-toolbar
# django-storages
# django-taggit
pytz==2020.4 \\
--hash=sha256:3e6b7dd2d1e0a59084bcee14a17af60c5c562cdc16d828e8eba2e683d3a7e268 \\
--hash=sha256:5c55e189b682d420be27c6995ba6edce0c0a77dd67bfbe2ae6607134d5851ffd
Expand Down
21 changes: 21 additions & 0 deletions tests/test_writer.py
Expand Up @@ -344,3 +344,24 @@ def test_write_find_links(writer, find_links, expected_lines):
"""
writer.find_links = find_links
assert list(writer.write_find_links()) == expected_lines


def test_write_order(writer, from_line):
"""
Order of packages should match that of `pip freeze`.
"""
writer.emit_header = False

packages = [
from_line("package_a==0.1"),
from_line("Package-b==2.3.4"),
from_line("Package==5.6"),
from_line("package2==7.8.9"),
]
expected_lines = [
"package==5.6",
"package_a==0.1",
"package-b==2.3.4",
"package2==7.8.9",
]
assert list(writer._iter_lines(packages)) == expected_lines