Skip to content

Commit

Permalink
Improve log/error messages esp. ones involve ENABLE_USER_SITE
Browse files Browse the repository at this point in the history
This is to be squashed with the commit above
  • Loading branch information
McSinyx committed Aug 3, 2020
1 parent 90a1357 commit d7472a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions src/pip/_internal/commands/install.py
Expand Up @@ -688,26 +688,23 @@ def decide_user_install(
# (mismatch between user or group id and effective id)
# or by an administrator.
if use_user_site is not None:
# use_user_site might be passed as an int.
use_user_site = bool(use_user_site)
if use_user_site:
logger.debug("User install by explicit request")
else:
logger.debug("Non-user install by explicit request")
if use_user_site and ENABLE_USER_SITE is None:
raise InstallationError(
"User site-packages are disabled "
"for security reasons or by an administrator."
"User site-packages cannot be used because "
"site.ENABLE_USER_SITE is None, which indicates "
"it was disabled for security reasons or by an administrator."
)
elif ENABLE_USER_SITE is None:
elif not ENABLE_USER_SITE:
logger.debug(
"User site-packages are disabled "
"for security reasons or by an administrator."
)
use_user_site = False
elif ENABLE_USER_SITE is False:
logger.debug(
"User site-packages are disabled by user request "
"(with 'python -s' or PYTHONNOUSERSITE)"
"User site-packages is disabled "
"because site.ENABLE_USER_SITE is %s",
ENABLE_USER_SITE,
)
use_user_site = False
elif root_path is not None:
Expand All @@ -728,7 +725,7 @@ def decide_user_install(
if virtualenv_no_global():
raise InstallationError(
"Can not perform a '--user' install. "
"User site-packages are not visible in this virtualenv."
"User site-packages is not visible in this virtualenv."
)
if not site_packages_writable(
user=use_user_site, root=root_path, isolated=isolated_mode,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_user.py
Expand Up @@ -98,7 +98,7 @@ def test_install_user_venv_nositepkgs_fails(self, virtualenv,
expect_error=True,
)
assert (
"Can not perform a '--user' install. User site-packages are not "
"Can not perform a '--user' install. User site-packages is not "
"visible in this virtualenv." in result.stderr
)

Expand Down

0 comments on commit d7472a8

Please sign in to comment.