File: set_user_default.patch

package info (click to toggle)
python-pip 9.0.1-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,900 kB
  • sloc: python: 51,824; makefile: 206; sh: 52
file content (93 lines) | stat: -rw-r--r-- 4,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From f392f69c8f813779b3ad3a384f57dc1f805890ef Mon Sep 17 00:00:00 2001
From: Barry Warsaw <barry@python.org>
Date: Wed, 10 Feb 2016 11:18:37 -0500
Subject: 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@ubuntu.com>,
        Barry Warsaw <barry@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 7d7fb86..83d6a7c 100644
--- a/docs/user_guide.rst
+++ b/docs/user_guide.rst
@@ -513,8 +513,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 227c526..39292b1 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())
@@ -116,6 +123,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.ignore_requires_python())
@@ -128,10 +136,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',