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

Sort requirements by canonical distribution name #134

Merged
merged 1 commit into from
Jan 10, 2024
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
1 change: 1 addition & 0 deletions news/134.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sort requirement files by canonical requirement name to help ensure stability and comparability.
14 changes: 11 additions & 3 deletions src/pip_deepfreeze/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .project_name import get_project_name
from .req_file_parser import OptionsLine, parse as parse_req_file
from .req_merge import prepare_frozen_reqs_for_upgrade
from .req_parser import get_req_names
from .req_parser import get_req_name, get_req_names

Check warning on line 16 in src/pip_deepfreeze/sync.py

View check run for this annotation

Codecov / codecov/patch

src/pip_deepfreeze/sync.py#L16

Added line #L16 was not covered by tests
from .utils import (
HttpFetcher,
get_temp_path_in_dir,
Expand All @@ -28,6 +28,13 @@
)


def _req_line_sort_key(req_line: str) -> str:
req_name = get_req_name(req_line)

Check warning on line 32 in src/pip_deepfreeze/sync.py

View check run for this annotation

Codecov / codecov/patch

src/pip_deepfreeze/sync.py#L31-L32

Added lines #L31 - L32 were not covered by tests
if req_name is None:
return req_line
return req_name

Check warning on line 35 in src/pip_deepfreeze/sync.py

View check run for this annotation

Codecov / codecov/patch

src/pip_deepfreeze/sync.py#L34-L35

Added lines #L34 - L35 were not covered by tests


def sync(
python: str,
upgrade_all: bool,
Expand Down Expand Up @@ -78,8 +85,9 @@
):
if isinstance(parsed_req_line, OptionsLine):
print(parsed_req_line.raw_line, file=f)
# output frozen dependencies of project
for req_line in frozen_reqs:
# output frozen dependencies of project,
# sorted by canonical requirement name
for req_line in sorted(frozen_reqs, key=_req_line_sort_key):
print(normalize_req_line(req_line), file=f)
# uninstall unneeded dependencies, if asked to do so
unneeded_req_names = sorted(
Expand Down