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

Don't suggest --user in virtual environment #9409

Merged
merged 1 commit into from
Apr 9, 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
2 changes: 2 additions & 0 deletions news/9409.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``--user`` is no longer suggested incorrectly when pip fails with a permission
error in a virtual environment.
7 changes: 5 additions & 2 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
write_output,
)
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.virtualenv import virtualenv_no_global
from pip._internal.utils.virtualenv import (
running_under_virtualenv,
virtualenv_no_global,
)
from pip._internal.wheel_builder import (
BinaryAllowedPredicate,
build,
Expand Down Expand Up @@ -725,7 +728,7 @@ def create_os_error_message(error, show_traceback, using_user_site):
user_option_part = "Consider using the `--user` option"
permissions_part = "Check the permissions"

if not using_user_site:
if not running_under_virtualenv() and not using_user_site:
parts.extend([
user_option_part, " or ",
permissions_part.lower(),
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_command_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from pip._vendor.packaging.requirements import Requirement

from pip._internal.commands import install
from pip._internal.commands.install import (
create_os_error_message,
decide_user_install,
Expand Down Expand Up @@ -109,7 +110,8 @@ def test_rejection_for_location_requirement_options():
' permissions.\n'),
])
def test_create_os_error_message(
error, show_traceback, using_user_site, expected
monkeypatch, error, show_traceback, using_user_site, expected
):
monkeypatch.setattr(install, "running_under_virtualenv", lambda: False)
msg = create_os_error_message(error, show_traceback, using_user_site)
assert msg == expected