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

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