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

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