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

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