Skip to content

Commit d490f75

Browse files
authored
Merge pull request #5943 from cjerdonek/uninstalled-freeze-message
Include package name in a freeze warning if package is not installed
2 parents ebfa663 + afdfb7b commit d490f75

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include the package name in a freeze warning if the package is not installed.

src/pip/_internal/operations/freeze.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ def freeze(
114114
# but has been processed already
115115
if not req_files[line_req.name]:
116116
logger.warning(
117-
"Requirement file [%s] contains %s, but that "
118-
"package is not installed",
117+
"Requirement file [%s] contains %s, but "
118+
"package %r is not installed",
119119
req_file_path,
120-
COMMENT_RE.sub('', line).strip(),
120+
COMMENT_RE.sub('', line).strip(), line_req.name
121121
)
122122
else:
123123
req_files[line_req.name].append(req_file_path)

tests/functional/test_freeze.py

+30-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from tests.lib import (
1010
_create_test_package, _create_test_package_with_srcdir, need_bzr,
11-
need_mercurial,
11+
need_mercurial, path_to_url,
1212
)
1313

1414
distribute_re = re.compile('^distribute==[0-9.]+\n', re.MULTILINE)
@@ -419,6 +419,26 @@ def test_freeze_bazaar_clone(script, tmpdir):
419419
""")
420420

421421

422+
def test_freeze_with_requirement_option_file_url_egg_not_installed(script):
423+
"""
424+
Test "freeze -r requirements.txt" with a local file URL whose egg name
425+
is not installed.
426+
"""
427+
428+
url = path_to_url('my-package.tar.gz') + '#egg=Does.Not-Exist'
429+
requirements_path = script.scratch_path.join('requirements.txt')
430+
requirements_path.write(url + '\n')
431+
432+
result = script.pip(
433+
'freeze', '--requirement', 'requirements.txt', expect_stderr=True,
434+
)
435+
expected_err = (
436+
'Requirement file [requirements.txt] contains {}, but package '
437+
"'Does.Not-Exist' is not installed\n"
438+
).format(url)
439+
assert result.stderr == expected_err
440+
441+
422442
def test_freeze_with_requirement_option(script):
423443
"""
424444
Test that new requirements are created correctly with --requirement hints
@@ -444,8 +464,8 @@ def test_freeze_with_requirement_option(script):
444464
expected += "## The following requirements were added by pip freeze:..."
445465
_check_output(result.stdout, expected)
446466
assert (
447-
"Requirement file [hint.txt] contains NoExist==4.2, but that package "
448-
"is not installed"
467+
"Requirement file [hint.txt] contains NoExist==4.2, but package "
468+
"'NoExist' is not installed"
449469
) in result.stderr
450470

451471

@@ -486,12 +506,12 @@ def test_freeze_with_requirement_option_multiple(script):
486506
""")
487507
_check_output(result.stdout, expected)
488508
assert (
489-
"Requirement file [hint1.txt] contains NoExist==4.2, but that "
490-
"package is not installed"
509+
"Requirement file [hint1.txt] contains NoExist==4.2, but package "
510+
"'NoExist' is not installed"
491511
) in result.stderr
492512
assert (
493-
"Requirement file [hint2.txt] contains NoExist2==2.0, but that "
494-
"package is not installed"
513+
"Requirement file [hint2.txt] contains NoExist2==2.0, but package "
514+
"'NoExist2' is not installed"
495515
) in result.stderr
496516
# any options like '--index-url http://ignore' should only be emitted once
497517
# even if they are listed in multiple requirements files
@@ -524,7 +544,7 @@ def test_freeze_with_requirement_option_package_repeated_one_file(script):
524544
""")
525545
_check_output(result.stdout, expected_out)
526546
err1 = ("Requirement file [hint1.txt] contains NoExist, "
527-
"but that package is not installed\n")
547+
"but package 'NoExist' is not installed\n")
528548
err2 = "Requirement simple2 included multiple times [hint1.txt]\n"
529549
assert err1 in result.stderr
530550
assert err2 in result.stderr
@@ -560,8 +580,8 @@ def test_freeze_with_requirement_option_package_repeated_multi_file(script):
560580
""")
561581
_check_output(result.stdout, expected_out)
562582

563-
err1 = ("Requirement file [hint2.txt] contains NoExist, but that "
564-
"package is not installed\n")
583+
err1 = ("Requirement file [hint2.txt] contains NoExist, but package "
584+
"'NoExist' is not installed\n")
565585
err2 = ("Requirement simple included multiple times "
566586
"[hint1.txt, hint2.txt]\n")
567587
assert err1 in result.stderr

0 commit comments

Comments
 (0)