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