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

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