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

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