Skip to content

Commit

Permalink
Special case warning for requirements.txt install
Browse files Browse the repository at this point in the history
Added a special warning for users who accidentally do
`pip install requirements.txt` and forget the `-r` flag.
Issue pypa#9908
  • Loading branch information
briantracy committed Apr 29, 2021
1 parent 7a77484 commit 8fa1be1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
6 changes: 6 additions & 0 deletions tests/functional/test_install_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 8fa1be1

Please sign in to comment.