Fix root warning when pip is invoked via python -m pip

Fixes https://github.com/pypa/pip/issues/6576
This commit is contained in:
Miro Hrončok 2019-06-10 13:09:38 +02:00
parent fa2f84fe5b
commit de5ce17674
2 changed files with 9 additions and 3 deletions

View File

@ -11,7 +11,7 @@ index 1279d4a..aeb9d26 100644
from optparse import SUPPRESS_HELP from optparse import SUPPRESS_HELP
from pip._vendor import pkg_resources from pip._vendor import pkg_resources
@@ -217,6 +219,20 @@ class InstallCommand(RequirementCommand): @@ -217,6 +219,23 @@ class InstallCommand(RequirementCommand):
def run(self, options, args): def run(self, options, args):
cmdoptions.check_install_build_global(options) cmdoptions.check_install_build_global(options)
@ -23,10 +23,13 @@ index 1279d4a..aeb9d26 100644
+ +
+ # Check whether we have root privileges and aren't in venv/virtualenv + # Check whether we have root privileges and aren't in venv/virtualenv
+ if os.getuid() == 0 and not is_venv(): + if os.getuid() == 0 and not is_venv():
+ command = path.basename(sys.argv[0])
+ if command == "__main__.py":
+ command = path.basename(sys.executable) + " -m pip"
+ logger.warning( + logger.warning(
+ "WARNING: Running pip install with root privileges is " + "WARNING: Running pip install with root privileges is "
+ "generally not a good idea. Try `%s install --user` instead." + "generally not a good idea. Try `%s install --user` instead."
+ % path.basename(sys.argv[0]) + % command
+ ) + )
+ +
upgrade_strategy = "to-satisfy-only" upgrade_strategy = "to-satisfy-only"

View File

@ -23,7 +23,7 @@ Name: python-%{srcname}
# When updating, update the bundled libraries versions bellow! # When updating, update the bundled libraries versions bellow!
# You can use vendor_meta.sh in the dist git repo # You can use vendor_meta.sh in the dist git repo
Version: 19.1.1 Version: 19.1.1
Release: 1%{?dist} Release: 2%{?dist}
Summary: A tool for installing and managing Python packages Summary: A tool for installing and managing Python packages
# We bundle a lot of libraries with pip, which itself is under MIT license. # We bundle a lot of libraries with pip, which itself is under MIT license.
@ -493,6 +493,9 @@ ln -sf %{buildroot}%{_bindir}/pip3 _bin/pip
%endif %endif
%changelog %changelog
* Mon Jun 10 2019 Miro Hrončok <mhroncok@redhat.com> - 19.1.1-2
- Fix root warning when pip is invoked via python -m pip
* Wed May 15 2019 Miro Hrončok <mhroncok@redhat.com> - 19.1.1-1 * Wed May 15 2019 Miro Hrončok <mhroncok@redhat.com> - 19.1.1-1
- Update to 19.1.1 (#1706995) - Update to 19.1.1 (#1706995)