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

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