[Python-modules-team] Bug#830892: A better patch

anatoly techtonik techtonik at gmail.com
Tue Nov 22 14:16:06 UTC 2016


Attached patch sets  --user option only if no --system, --prefix or
--target are defined, which are mutually exclusive to this option.
-------------- next part --------------
diff --git a/pip/commands/install.py b/pip/commands/install.py
index 13b328f..dcc4cd4 100644
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -55,12 +55,6 @@ 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())
@@ -110,7 +104,6 @@ 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())
@@ -122,7 +115,6 @@ 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 "
@@ -132,10 +124,10 @@ class InstallCommand(RequirementCommand):
 
         cmd_opts.add_option(
             '--system',
-            dest='use_user_site',
-            action='store_false',
-            help="Install using the system scheme (overrides --user on "
-                 "Debian systems)")
+            dest='use_system_location',
+            action='store_true',
+            help="Install into operating system location (Debian changes "
+                 "defaults to install to user dir)")
 
         cmd_opts.add_option(
             '--egg',
@@ -233,6 +225,15 @@ class InstallCommand(RequirementCommand):
         if options.build_dir:
             options.build_dir = os.path.abspath(options.build_dir)
 
+
+        # computing 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
+                options.ignore_installed = True
+
+
         options.src_dir = os.path.abspath(options.src_dir)
         install_options = options.install_options or []
         if options.use_user_site:
@@ -241,6 +242,11 @@ class InstallCommand(RequirementCommand):
                     "Can not combine '--user' and '--prefix' as they imply "
                     "different installation locations"
                 )
+            if options.use_system_location:
+                raise CommandError(
+                    "Can not combine '--user' and '--system' as they imply "
+                    "different installation locations"
+                )
             if virtualenv_no_global():
                 raise InstallationError(
                     "Can not perform a '--user' install. User site-packages "


More information about the Python-modules-team mailing list