From 8fa1be1a9b679d21f7651d20812bf5c9eb7fad6e Mon Sep 17 00:00:00 2001 From: Brian Tracy Date: Wed, 28 Apr 2021 23:53:32 -0700 Subject: [PATCH] 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'],