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 94 95 96
|
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. When inside virtual environments, when running as root or when
--prefix or --target are specified, keep the default behavior.
Author: Didier Roche <didrocks@ubuntu.com>,
Barry Warsaw <barry@debian.org>,
Anatoly techtonik <techtonik@gmail.com>,
Andrej Shadura <andrewsh@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/html/user_guide.rst | 6 ++++--
pip/commands/install.py | 20 +++++++++++++++++++-
2 files changed, 23 insertions(+), 3 deletions(-)
--- a/docs/html/user_guide.rst
+++ b/docs/html/user_guide.rst
@@ -545,8 +545,10 @@
location that is specific to a user. The default location for each OS is
explained in the python documentation for the `site.USER_BASE
<https://docs.python.org/3/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. 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``.
--- a/src/pip/_internal/commands/install.py
+++ b/src/pip/_internal/commands/install.py
@@ -35,6 +35,7 @@
except ImportError:
wheel = None
+from pip._internal.locations import running_under_virtualenv
logger = logging.getLogger(__name__)
@@ -95,11 +96,14 @@
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(
'--no-user',
- dest='use_user_site',
- action='store_false',
+ dest='use_system_location',
+ action='store_true',
help=SUPPRESS_HELP)
cmd_opts.add_option(
'--root',
@@ -116,6 +120,13 @@
help="Installation prefix where lib, bin and other top-level "
"folders are placed")
+ cmd_opts.add_option(
+ '--system',
+ dest='use_system_location',
+ action='store_true',
+ help="Install using the system scheme (overrides --user on "
+ "Debian systems)")
+
cmd_opts.add_option(cmdoptions.build_dir())
cmd_opts.add_option(cmdoptions.src())
@@ -223,6 +234,15 @@
else:
python_versions = None
+ # compute install location defaults
+ if (not options.use_user_site and not options.prefix_path and not
+ options.target_dir and not options.use_system_location):
+ if not running_under_virtualenv() and os.geteuid() != 0:
+ options.use_user_site = True
+
+ if options.use_system_location:
+ options.use_user_site = False
+
options.src_dir = os.path.abspath(options.src_dir)
install_options = options.install_options or []
if options.use_user_site:
|