From afdfb7b21023dbd1641b253714e6d7a96949106d Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sun, 21 Oct 2018 23:26:58 -0700 Subject: [PATCH] Include package name in a freeze warning if package is not installed. --- ...D1F422-0CB9-450F-B4DD-9486524712E5.feature | 1 + src/pip/_internal/operations/freeze.py | 6 +-- tests/functional/test_freeze.py | 40 ++++++++++++++----- 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 news/13D1F422-0CB9-450F-B4DD-9486524712E5.feature diff --git a/news/13D1F422-0CB9-450F-B4DD-9486524712E5.feature b/news/13D1F422-0CB9-450F-B4DD-9486524712E5.feature new file mode 100644 index 00000000000..dbe3638c6e4 --- /dev/null +++ b/news/13D1F422-0CB9-450F-B4DD-9486524712E5.feature @@ -0,0 +1 @@ +Include the package name in a freeze warning if the package is not installed. \ No newline at end of file diff --git a/src/pip/_internal/operations/freeze.py b/src/pip/_internal/operations/freeze.py index d3cdefbfcdc..db3bcd4f815 100644 --- a/src/pip/_internal/operations/freeze.py +++ b/src/pip/_internal/operations/freeze.py @@ -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) diff --git a/tests/functional/test_freeze.py b/tests/functional/test_freeze.py index bf6f058b82e..53f49858154 100644 --- a/tests/functional/test_freeze.py +++ b/tests/functional/test_freeze.py @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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