From 8fa1be1a9b679d21f7651d20812bf5c9eb7fad6e Mon Sep 17 00:00:00 2001 From: Brian Tracy Date: Wed, 28 Apr 2021 23:53:32 -0700 Subject: [PATCH 1/4] Special case warning for requirements.txt install Added a special warning for users who accidentally do `pip install requirements.txt` and forget the `-r` flag. Issue #9908 --- src/pip/_internal/resolution/resolvelib/factory.py | 7 +++++++ tests/functional/test_install_extras.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index 6e3f195187b..12d476d4ead 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -540,6 +540,13 @@ def _report_single_requirement_conflict(self, req, parent): req_disp, ", ".join(versions) or "none", ) + if str(req) == "requirements.txt": + logger.critical( + "HINT: You are attempting to install a package literally " + 'named "requirements.txt" (which cannot exist). Consider ' + "using the '-r' flag to install the packages listed in " + "requirements.txt" + ) return DistributionNotFound(f"No matching distribution found for {req}") diff --git a/tests/functional/test_install_extras.py b/tests/functional/test_install_extras.py index de1ee3795ea..3fa32bcc566 100644 --- a/tests/functional/test_install_extras.py +++ b/tests/functional/test_install_extras.py @@ -143,6 +143,12 @@ def test_install_special_extra(script): ) in result.stderr, str(result) +def test_install_requirements_no_r_flag(script): + '''Beginners sometimes forget the -r and this leads to confusion''' + result = script.pip('install', 'requirements.txt', expect_error=True) + assert 'literally named "requirements.txt"' in result.stderr + + @pytest.mark.parametrize( "extra_to_install, simple_version", [ ['', '3.0'], From 04d113f684f0abad606d0c597dfddda87356c511 Mon Sep 17 00:00:00 2001 From: Brian Tracy Date: Thu, 29 Apr 2021 08:38:04 -0700 Subject: [PATCH 2/4] Special case warning for requirements.txt install Added entry to news/ directory documenting change. Issue #9908 --- news/9915.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/9915.feature.rst diff --git a/news/9915.feature.rst b/news/9915.feature.rst new file mode 100644 index 00000000000..f03b03f7311 --- /dev/null +++ b/news/9915.feature.rst @@ -0,0 +1 @@ +Add a special error message when users forget the -r flag when installing. From 03543767cdac7aaa95f2d5f6f6607f2882c7b91b Mon Sep 17 00:00:00 2001 From: briantracy Date: Thu, 29 Apr 2021 20:15:57 -0700 Subject: [PATCH 3/4] Update news/9915.feature.rst Co-authored-by: Tzu-ping Chung --- news/9915.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/9915.feature.rst b/news/9915.feature.rst index f03b03f7311..6d7d2bc057f 100644 --- a/news/9915.feature.rst +++ b/news/9915.feature.rst @@ -1 +1 @@ -Add a special error message when users forget the -r flag when installing. +Add a special error message when users forget the ``-r`` flag when installing. From 39398cb2812cce5ad62a18f195060477b79f6c59 Mon Sep 17 00:00:00 2001 From: Brian Tracy Date: Thu, 29 Apr 2021 20:22:58 -0700 Subject: [PATCH 4/4] Special case warning for requirements.txt install Changed log level of special case warning to info instead of critical. --- src/pip/_internal/resolution/resolvelib/factory.py | 2 +- tests/functional/test_install_extras.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/resolution/resolvelib/factory.py b/src/pip/_internal/resolution/resolvelib/factory.py index 12d476d4ead..87e3af2de4c 100644 --- a/src/pip/_internal/resolution/resolvelib/factory.py +++ b/src/pip/_internal/resolution/resolvelib/factory.py @@ -541,7 +541,7 @@ def _report_single_requirement_conflict(self, req, parent): ", ".join(versions) or "none", ) if str(req) == "requirements.txt": - logger.critical( + logger.info( "HINT: You are attempting to install a package literally " 'named "requirements.txt" (which cannot exist). Consider ' "using the '-r' flag to install the packages listed in " diff --git a/tests/functional/test_install_extras.py b/tests/functional/test_install_extras.py index 3fa32bcc566..83bcc548295 100644 --- a/tests/functional/test_install_extras.py +++ b/tests/functional/test_install_extras.py @@ -146,7 +146,7 @@ def test_install_special_extra(script): def test_install_requirements_no_r_flag(script): '''Beginners sometimes forget the -r and this leads to confusion''' result = script.pip('install', 'requirements.txt', expect_error=True) - assert 'literally named "requirements.txt"' in result.stderr + assert 'literally named "requirements.txt"' in result.stdout @pytest.mark.parametrize(