Skip to content

Commit d7472a8

Browse files
committed
Improve log/error messages esp. ones involve ENABLE_USER_SITE
This is to be squashed with the commit above
1 parent 90a1357 commit d7472a8

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/pip/_internal/commands/install.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -688,26 +688,23 @@ def decide_user_install(
688688
# (mismatch between user or group id and effective id)
689689
# or by an administrator.
690690
if use_user_site is not None:
691+
# use_user_site might be passed as an int.
691692
use_user_site = bool(use_user_site)
692693
if use_user_site:
693694
logger.debug("User install by explicit request")
694695
else:
695696
logger.debug("Non-user install by explicit request")
696697
if use_user_site and ENABLE_USER_SITE is None:
697698
raise InstallationError(
698-
"User site-packages are disabled "
699-
"for security reasons or by an administrator."
699+
"User site-packages cannot be used because "
700+
"site.ENABLE_USER_SITE is None, which indicates "
701+
"it was disabled for security reasons or by an administrator."
700702
)
701-
elif ENABLE_USER_SITE is None:
703+
elif not ENABLE_USER_SITE:
702704
logger.debug(
703-
"User site-packages are disabled "
704-
"for security reasons or by an administrator."
705-
)
706-
use_user_site = False
707-
elif ENABLE_USER_SITE is False:
708-
logger.debug(
709-
"User site-packages are disabled by user request "
710-
"(with 'python -s' or PYTHONNOUSERSITE)"
705+
"User site-packages is disabled "
706+
"because site.ENABLE_USER_SITE is %s",
707+
ENABLE_USER_SITE,
711708
)
712709
use_user_site = False
713710
elif root_path is not None:
@@ -728,7 +725,7 @@ def decide_user_install(
728725
if virtualenv_no_global():
729726
raise InstallationError(
730727
"Can not perform a '--user' install. "
731-
"User site-packages are not visible in this virtualenv."
728+
"User site-packages is not visible in this virtualenv."
732729
)
733730
if not site_packages_writable(
734731
user=use_user_site, root=root_path, isolated=isolated_mode,

tests/functional/test_install_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_install_user_venv_nositepkgs_fails(self, virtualenv,
9898
expect_error=True,
9999
)
100100
assert (
101-
"Can not perform a '--user' install. User site-packages are not "
101+
"Can not perform a '--user' install. User site-packages is not "
102102
"visible in this virtualenv." in result.stderr
103103
)
104104

0 commit comments

Comments
 (0)