python-pip/emit-a-warning-when-running...

41 lines
1.2 KiB
Diff

From e29dfc3855813dbab25513ca82703fc5d7b989cf Mon Sep 17 00:00:00 2001
From: Tomas Orsava <torsava@redhat.com>
Date: Tue, 14 Feb 2017 17:10:09 +0100
Subject: [PATCH] Emit a warning when running with root privileges
---
pip/commands/install.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/commands/install.py b/commands/install.py
index 227c526..88c7c58 100644
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -6,6 +6,8 @@ import os
import tempfile
import shutil
import warnings
+import sys
+from os import path
try:
import wheel
except ImportError:
@@ -193,6 +195,14 @@ class InstallCommand(RequirementCommand):
cmdoptions.resolve_wheel_no_use_binary(options)
cmdoptions.check_install_build_global(options)
+ # Check whether we have root privileges
+ if os.getuid() == 0:
+ logger.warning(
+ "WARNING: Running pip install with root privileges is"
+ "generally not a good idea. Try `%s install --user` instead."
+ % path.basename(sys.argv[0])
+ )
+
if options.as_egg:
warnings.warn(
"--egg has been deprecated and will be removed in the future. "
--
2.11.0