Blame SOURCES/emit-a-warning-when-running-with-root-privileges.patch

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