|
|
1ee682 |
From aab24967a03bda3b0999d80562a6064c27d1e0e0 Mon Sep 17 00:00:00 2001
|
|
|
1ee682 |
From: Tomas Orsava <torsava@redhat.com>
|
|
|
1ee682 |
Date: Tue, 12 Nov 2019 17:15:08 +0100
|
|
|
1ee682 |
Subject: [PATCH] Downstream only patch
|
|
|
1ee682 |
|
|
|
1ee682 |
Emit a warning to the user if pip install is run with root privileges
|
|
|
1ee682 |
Issue upstream: https://github.com/pypa/pip/issues/4288
|
|
|
1ee682 |
---
|
|
|
1ee682 |
src/pip/_internal/commands/install.py | 19 +++++++++++++++++++
|
|
|
1ee682 |
1 file changed, 19 insertions(+)
|
|
|
1ee682 |
|
|
|
875274 |
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
|
|
|
1ee682 |
index 5842d18..a6104b4 100644
|
|
|
875274 |
--- a/src/pip/_internal/commands/install.py
|
|
|
875274 |
+++ b/src/pip/_internal/commands/install.py
|
|
|
1ee682 |
@@ -12,6 +12,8 @@ import logging
|
|
|
875274 |
import operator
|
|
|
875274 |
import os
|
|
|
875274 |
import shutil
|
|
|
875274 |
+import sys
|
|
|
875274 |
+from os import path
|
|
|
875274 |
from optparse import SUPPRESS_HELP
|
|
|
875274 |
|
|
|
875274 |
from pip._vendor import pkg_resources
|
|
|
1ee682 |
@@ -281,6 +283,23 @@ class InstallCommand(RequirementCommand):
|
|
|
875274 |
def run(self, options, args):
|
|
|
1ee682 |
# type: (Values, List[Any]) -> int
|
|
|
875274 |
cmdoptions.check_install_build_global(options)
|
|
|
875274 |
+
|
|
|
875274 |
+ def is_venv():
|
|
|
875274 |
+ return (hasattr(sys, 'real_prefix') or
|
|
|
875274 |
+ (hasattr(sys, 'base_prefix') and
|
|
|
875274 |
+ sys.base_prefix != sys.prefix))
|
|
|
875274 |
+
|
|
|
875274 |
+ # Check whether we have root privileges and aren't in venv/virtualenv
|
|
|
875274 |
+ if os.getuid() == 0 and not is_venv():
|
|
|
875274 |
+ command = path.basename(sys.argv[0])
|
|
|
875274 |
+ if command == "__main__.py":
|
|
|
875274 |
+ command = path.basename(sys.executable) + " -m pip"
|
|
|
875274 |
+ logger.warning(
|
|
|
875274 |
+ "Running pip install with root privileges is "
|
|
|
875274 |
+ "generally not a good idea. Try `%s install --user` instead."
|
|
|
875274 |
+ % command
|
|
|
875274 |
+ )
|
|
|
875274 |
+
|
|
|
875274 |
upgrade_strategy = "to-satisfy-only"
|
|
|
875274 |
if options.upgrade:
|
|
|
875274 |
upgrade_strategy = options.upgrade_strategy
|
|
|
1ee682 |
--
|
|
|
1ee682 |
2.20.1
|
|
|
1ee682 |
|