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

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