Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special case warning for requirements.txt install #9915

Merged
merged 4 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/9915.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a special error message when users forget the ``-r`` flag when installing.
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.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 "
"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.stdout


@pytest.mark.parametrize(
"extra_to_install, simple_version", [
['', '3.0'],
Expand Down