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