[Python-modules-commits] [python-pip] 05/08: Default to --user in non-virtual environments.

Barry Warsaw barry at moszumanska.debian.org
Thu Feb 25 22:09:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

barry pushed a commit to branch master
in repository python-pip.

commit d72211ae99990ba08eba3a5bf151f48e041679d5
Author: Barry Warsaw <barry at python.org>
Date:   Wed Feb 10 11:18:37 2016 -0500

    Default to --user in non-virtual environments.
    
    When running as a normal user in a non-virtual environment, default to
    --user and --ignore-installed.  When inside virtual environments or when
    running as root, keep the default behavior.
    
    Author: Didier Roche <didrocks at ubuntu.com>,
            Barry Warsaw <barry at debian.org>
    Bug: https://github.com/pypa/pip/issues/1668
    Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=725848
    Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/pip/+bug/1419695
    
    Patch-Name: set_user_default.patch
---
 docs/user_guide.rst     |  6 ++++--
 pip/commands/install.py | 20 +++++++++++++++++++-
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/docs/user_guide.rst b/docs/user_guide.rst
index 90f941c..d3f7945 100644
--- a/docs/user_guide.rst
+++ b/docs/user_guide.rst
@@ -508,8 +508,10 @@ which means that all Python distributions support an alternative install
 location that is specific to a user.  The default location for each OS is
 explained in the python documentation for the `site.USER_BASE
 <http://docs.python.org/library/site.html#site.USER_BASE>`_ variable.  This mode
-of installation can be turned on by specifying the :ref:`--user
-<install_--user>` option to ``pip install``.
+of installation is the default on Debian and derivative systems (--user has no
+effect) when inside non-virtual environments, and when the script is run as
+non-root. --ignore-installed is then used.  This behavior can be turned off by
+specifying the :ref:`--system <install_--system>` option to ``pip install``.
 
 Moreover, the "user scheme" can be customized by setting the
 ``PYTHONUSERBASE`` environment variable, which updates the value of ``site.USER_BASE``.
diff --git a/pip/commands/install.py b/pip/commands/install.py
index 7ddde93..13b328f 100644
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -24,6 +24,7 @@ from pip.utils.deprecation import RemovedInPip10Warning
 from pip.utils.filesystem import check_path_owner
 from pip.wheel import WheelCache, WheelBuilder
 
+from pip.locations import running_under_virtualenv
 
 logger = logging.getLogger(__name__)
 
@@ -54,6 +55,12 @@ class InstallCommand(RequirementCommand):
     def __init__(self, *args, **kw):
         super(InstallCommand, self).__init__(*args, **kw)
 
+        default_user = True
+        if running_under_virtualenv():
+            default_user = False
+        if os.geteuid() == 0:
+            default_user = False
+
         cmd_opts = self.cmd_opts
 
         cmd_opts.add_option(cmdoptions.constraints())
@@ -103,6 +110,7 @@ class InstallCommand(RequirementCommand):
             '-I', '--ignore-installed',
             dest='ignore_installed',
             action='store_true',
+            default=default_user,
             help='Ignore the installed packages (reinstalling instead).')
 
         cmd_opts.add_option(cmdoptions.no_deps())
@@ -114,10 +122,20 @@ class InstallCommand(RequirementCommand):
             '--user',
             dest='use_user_site',
             action='store_true',
+            default=default_user,
             help="Install to the Python user install directory for your "
                  "platform. Typically ~/.local/, or %APPDATA%\Python on "
                  "Windows. (See the Python documentation for site.USER_BASE "
-                 "for full details.)")
+                 "for full details.)  On Debian systems, this is the "
+                 "default when running outside of a virtual environment "
+                 "and not as root.")
+
+        cmd_opts.add_option(
+            '--system',
+            dest='use_user_site',
+            action='store_false',
+            help="Install using the system scheme (overrides --user on "
+                 "Debian systems)")
 
         cmd_opts.add_option(
             '--egg',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-pip.git



More information about the Python-modules-commits mailing list