|
|
6d97c1 |
From 74bb5d26e232493de43adfa1f4b42b66fd701294 Mon Sep 17 00:00:00 2001
|
|
|
6d97c1 |
From: Tomas Hrnciar <thrnciar@redhat.com>
|
|
|
6d97c1 |
Date: Sun, 26 Apr 2020 13:52:24 +0200
|
|
|
6d97c1 |
Subject: [PATCH] Downstream only patch
|
|
|
6d97c1 |
|
|
|
6d97c1 |
Emit a warning to the user if pip install is run with root privileges
|
|
|
6d97c1 |
Issue upstream: https://github.com/pypa/pip/issues/4288
|
|
|
6d97c1 |
---
|
|
|
6d97c1 |
src/pip/_internal/commands/install.py | 19 +++++++++++++++++++
|
|
|
6d97c1 |
1 file changed, 19 insertions(+)
|
|
|
6d97c1 |
|
|
|
6d97c1 |
diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py
|
|
|
6d97c1 |
index 70bda2e2..1e750ae1 100644
|
|
|
6d97c1 |
--- a/src/pip/_internal/commands/install.py
|
|
|
6d97c1 |
+++ b/src/pip/_internal/commands/install.py
|
|
|
6d97c1 |
@@ -13,6 +13,8 @@ import operator
|
|
|
6d97c1 |
import os
|
|
|
6d97c1 |
import shutil
|
|
|
6d97c1 |
import site
|
|
|
6d97c1 |
+import sys
|
|
|
6d97c1 |
+from os import path
|
|
|
6d97c1 |
from optparse import SUPPRESS_HELP
|
|
|
6d97c1 |
|
|
|
6d97c1 |
from pip._vendor import pkg_resources
|
|
|
6d97c1 |
@@ -241,6 +243,23 @@ class InstallCommand(RequirementCommand):
|
|
|
6d97c1 |
raise CommandError("Can not combine '--user' and '--target'")
|
|
|
6d97c1 |
|
|
|
6d97c1 |
cmdoptions.check_install_build_global(options)
|
|
|
6d97c1 |
+
|
|
|
6d97c1 |
+ def is_venv():
|
|
|
6d97c1 |
+ return (hasattr(sys, 'real_prefix') or
|
|
|
6d97c1 |
+ (hasattr(sys, 'base_prefix') and
|
|
|
6d97c1 |
+ sys.base_prefix != sys.prefix))
|
|
|
6d97c1 |
+
|
|
|
6d97c1 |
+ # Check whether we have root privileges and aren't in venv/virtualenv
|
|
|
6d97c1 |
+ if os.getuid() == 0 and not is_venv() and not options.root_path:
|
|
|
6d97c1 |
+ command = path.basename(sys.argv[0])
|
|
|
6d97c1 |
+ if command == "__main__.py":
|
|
|
6d97c1 |
+ command = path.basename(sys.executable) + " -m pip"
|
|
|
6d97c1 |
+ logger.warning(
|
|
|
6d97c1 |
+ "Running pip install with root privileges is "
|
|
|
6d97c1 |
+ "generally not a good idea. Try `%s install --user` instead."
|
|
|
6d97c1 |
+ % command
|
|
|
6d97c1 |
+ )
|
|
|
6d97c1 |
+
|
|
|
6d97c1 |
upgrade_strategy = "to-satisfy-only"
|
|
|
6d97c1 |
if options.upgrade:
|
|
|
6d97c1 |
upgrade_strategy = options.upgrade_strategy
|
|
|
6d97c1 |
--
|
|
|
6d97c1 |
2.23.0
|
|
|
6d97c1 |
|