Skip to content

Commit 8b1b6b6

Browse files
committed
Sort requirements by canonical distribution name
1 parent 6989350 commit 8b1b6b6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/pip_deepfreeze/sync.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .project_name import get_project_name
1414
from .req_file_parser import OptionsLine, parse as parse_req_file
1515
from .req_merge import prepare_frozen_reqs_for_upgrade
16-
from .req_parser import get_req_names
16+
from .req_parser import get_req_name, get_req_names
1717
from .utils import (
1818
HttpFetcher,
1919
get_temp_path_in_dir,
@@ -28,6 +28,13 @@
2828
)
2929

3030

31+
def _req_line_sort_key(req_line: str) -> str:
32+
req_name = get_req_name(req_line)
33+
if req_name is None:
34+
return req_line
35+
return req_name
36+
37+
3138
def sync(
3239
python: str,
3340
upgrade_all: bool,
@@ -78,8 +85,9 @@ def sync(
7885
):
7986
if isinstance(parsed_req_line, OptionsLine):
8087
print(parsed_req_line.raw_line, file=f)
81-
# output frozen dependencies of project
82-
for req_line in frozen_reqs:
88+
# output frozen dependencies of project,
89+
# sorted by canonical requirement name
90+
for req_line in sorted(frozen_reqs, key=_req_line_sort_key):
8391
print(normalize_req_line(req_line), file=f)
8492
# uninstall unneeded dependencies, if asked to do so
8593
unneeded_req_names = sorted(

0 commit comments

Comments
 (0)