#33 Fix root warning when pip is invoked via python -m pip
Merged a month ago by churchyard. Opened a month ago by churchyard.
rpms/ churchyard/python-pip i6576  into  master

@@ -11,7 +11,7 @@ 

   from optparse import SUPPRESS_HELP

   

   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):

           cmdoptions.check_install_build_global(options)

@@ -23,10 +23,13 @@ 

  +

  +        # Check whether we have root privileges and aren't in venv/virtualenv

  +        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(

- +                "WARNING: Running pip install with root privileges is "

+ +                "Running pip install with root privileges is "

  +                "generally not a good idea. Try `%s install --user` instead."

- +                % path.basename(sys.argv[0])

+ +                % command

  +            )

  +

           upgrade_strategy = "to-satisfy-only"

file modified
+5 -1

@@ -23,7 +23,7 @@ 

  # When updating, update the bundled libraries versions bellow!

  # You can use vendor_meta.sh in the dist git repo

  Version:        19.1.1

- Release:        1%{?dist}

+ Release:        2%{?dist}

  Summary:        A tool for installing and managing Python packages

  

  # We bundle a lot of libraries with pip, which itself is under MIT license.

@@ -493,6 +493,10 @@ 

  %endif

  

  %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

+ - Remove a redundant second WARNING prefix form the abovementioned warning

+ 

  * Wed May 15 2019 Miro Hrončok <mhroncok@redhat.com> - 19.1.1-1

  - Update to 19.1.1 (#1706995)

  

Could you post a link to this upstream discussion as well, above the edited patch?

I don't understand what link.

# pip install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.

# pip2 install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip2 install --user` instead.

# pip3 install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.

# pip3.7 install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3.7 install --user` instead.

# pip2.7 install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip2.7 install --user` instead.

# python3.7 -m pip install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `python3.7 -m pip install --user` instead.

# python3 -m pip install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `python3 -m pip install --user` instead.

# python2 -m pip install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `python2 -m pip install --user` instead.

# python2.7 -m pip install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `python2.7 -m pip install --user` instead.

# ln -s /usr/bin/python3 /usr/bin/python
# python -m pip install six
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try `python -m pip install --user` instead.

I'll see what we can do with the double WARNING.

1 new commit added

  • Remove a redundant second WARNING prefix form the root warning
a month ago

That's part of the commit message.

Running the current build:
<mock-chroot> sh-5.0# python3 -m pip install lektor
WARNING: WARNING: Running pip install with root privileges is generally not a good idea. Try __main__.py install --user instead.

Running the build from the PR:
<mock-chroot> sh-5.0# python3 -m pip install lektor
WARNING: Running pip install with root privileges is generally not a good idea. Try python3 -m pip install --user instead.

Overall looks to me, code wise and through my testing. Merge at will.

Pull-Request has been merged by churchyard

a month ago

I will not backport this now unless there is a demand. I don't want to unnecessarily diverge the branches.