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

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