Skip to content

Commit

Permalink
Merge pull request #134 from sbidoul/sort-output
Browse files Browse the repository at this point in the history
Sort requirements by canonical distribution name
  • Loading branch information
sbidoul committed Jan 10, 2024
2 parents 98371c7 + c3ec362 commit c46ed92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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
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)
if req_name is None:
return req_line
return req_name


def sync(
python: str,
upgrade_all: bool,
Expand Down Expand Up @@ -78,8 +85,9 @@ def sync(
):
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

0 comments on commit c46ed92

Please sign in to comment.