Skip to content

Commit

Permalink
Merge pull request #5943 from cjerdonek/uninstalled-freeze-message
Browse files Browse the repository at this point in the history
Include package name in a freeze warning if package is not installed
  • Loading branch information
cjerdonek committed Oct 27, 2018
2 parents ebfa663 + afdfb7b commit d490f75
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions news/13D1F422-0CB9-450F-B4DD-9486524712E5.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include the package name in a freeze warning if the package is not installed.
6 changes: 3 additions & 3 deletions src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def freeze(
# but has been processed already
if not req_files[line_req.name]:
logger.warning(
"Requirement file [%s] contains %s, but that "
"package is not installed",
"Requirement file [%s] contains %s, but "
"package %r is not installed",
req_file_path,
COMMENT_RE.sub('', line).strip(),
COMMENT_RE.sub('', line).strip(), line_req.name
)
else:
req_files[line_req.name].append(req_file_path)
Expand Down
40 changes: 30 additions & 10 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from tests.lib import (
_create_test_package, _create_test_package_with_srcdir, need_bzr,
need_mercurial,
need_mercurial, path_to_url,
)

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


def test_freeze_with_requirement_option_file_url_egg_not_installed(script):
"""
Test "freeze -r requirements.txt" with a local file URL whose egg name
is not installed.
"""

url = path_to_url('my-package.tar.gz') + '#egg=Does.Not-Exist'
requirements_path = script.scratch_path.join('requirements.txt')
requirements_path.write(url + '\n')

result = script.pip(
'freeze', '--requirement', 'requirements.txt', expect_stderr=True,
)
expected_err = (
'Requirement file [requirements.txt] contains {}, but package '
"'Does.Not-Exist' is not installed\n"
).format(url)
assert result.stderr == expected_err


def test_freeze_with_requirement_option(script):
"""
Test that new requirements are created correctly with --requirement hints
Expand All @@ -444,8 +464,8 @@ def test_freeze_with_requirement_option(script):
expected += "## The following requirements were added by pip freeze:..."
_check_output(result.stdout, expected)
assert (
"Requirement file [hint.txt] contains NoExist==4.2, but that package "
"is not installed"
"Requirement file [hint.txt] contains NoExist==4.2, but package "
"'NoExist' is not installed"
) in result.stderr


Expand Down Expand Up @@ -486,12 +506,12 @@ def test_freeze_with_requirement_option_multiple(script):
""")
_check_output(result.stdout, expected)
assert (
"Requirement file [hint1.txt] contains NoExist==4.2, but that "
"package is not installed"
"Requirement file [hint1.txt] contains NoExist==4.2, but package "
"'NoExist' is not installed"
) in result.stderr
assert (
"Requirement file [hint2.txt] contains NoExist2==2.0, but that "
"package is not installed"
"Requirement file [hint2.txt] contains NoExist2==2.0, but package "
"'NoExist2' is not installed"
) in result.stderr
# any options like '--index-url http://ignore' should only be emitted once
# even if they are listed in multiple requirements files
Expand Down Expand Up @@ -524,7 +544,7 @@ def test_freeze_with_requirement_option_package_repeated_one_file(script):
""")
_check_output(result.stdout, expected_out)
err1 = ("Requirement file [hint1.txt] contains NoExist, "
"but that package is not installed\n")
"but package 'NoExist' is not installed\n")
err2 = "Requirement simple2 included multiple times [hint1.txt]\n"
assert err1 in result.stderr
assert err2 in result.stderr
Expand Down Expand Up @@ -560,8 +580,8 @@ def test_freeze_with_requirement_option_package_repeated_multi_file(script):
""")
_check_output(result.stdout, expected_out)

err1 = ("Requirement file [hint2.txt] contains NoExist, but that "
"package is not installed\n")
err1 = ("Requirement file [hint2.txt] contains NoExist, but package "
"'NoExist' is not installed\n")
err2 = ("Requirement simple included multiple times "
"[hint1.txt, hint2.txt]\n")
assert err1 in result.stderr
Expand Down

0 comments on commit d490f75

Please sign in to comment.