|
|
1a9f8e |
From aab24967a03bda3b0999d80562a6064c27d1e0e0 Mon Sep 17 00:00:00 2001
|
|
|
1a9f8e |
From: Tomas Orsava <torsava@redhat.com>
|
|
|
1a9f8e |
Date: Tue, 12 Nov 2019 17:15:08 +0100
|
|
|
1a9f8e |
Subject: [PATCH] Downstream only patch
|
|
|
1a9f8e |
|
|
|
1a9f8e |
Emit a warning to the user if pip install is run with root privileges
|
|
|
1a9f8e |
Issue upstream: https://github.com/pypa/pip/issues/4288
|
|
|
1a9f8e |
---
|
|
|
1a9f8e |
src/pip/_internal/commands/install.py | 19 +++++++++++++++++++
|
|
|
1a9f8e |
1 file changed, 19 insertions(+)
|
|
|
1a9f8e |
|
|
|
bcedfd |
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
|
|
|
1a9f8e |
index 5842d18..a6104b4 100644
|
|
|
bcedfd |
--- a/src/pip/_internal/commands/install.py
|
|
|
bcedfd |
+++ b/src/pip/_internal/commands/install.py
|
|
|
1a9f8e |
@@ -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
|
|
|
1a9f8e |
@@ -281,6 +283,23 @@ class InstallCommand(RequirementCommand):
|
|
|
bcedfd |
def run(self, options, args):
|
|
|
1a9f8e |
# 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
|
|
|
1a9f8e |
--
|
|
|
1a9f8e |
2.20.1
|
|
|
1a9f8e |
|