From a01fabdf346dd0e07344d55fd0a177b22684b51b Mon Sep 17 00:00:00 2001 From: Nathan Houghton Date: Sat, 9 Oct 2021 18:08:55 -0700 Subject: [PATCH] Don't erroneously emit warning about running pip as root Check the uid using getuid() on platforms other than Linux and Mac OS before warning about running pip as root. Before this change, pip was emitting this warning even when it was run as a non-root user. --- news/10565.bugfix.rst | 1 + src/pip/_internal/cli/req_command.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 news/10565.bugfix.rst diff --git a/news/10565.bugfix.rst b/news/10565.bugfix.rst new file mode 100644 index 00000000000..52b70987fbf --- /dev/null +++ b/news/10565.bugfix.rst @@ -0,0 +1 @@ +Only warn about running pip as root if it is actually being run as root diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index c224bd276e2..dbd15cbce63 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -173,9 +173,10 @@ def warn_if_run_as_root() -> None: # checks: https://mypy.readthedocs.io/en/stable/common_issues.html if sys.platform == "win32" or sys.platform == "cygwin": return - if sys.platform == "darwin" or sys.platform == "linux": - if os.getuid() != 0: - return + + if os.getuid() != 0: + return + logger.warning( "Running pip as the 'root' user can result in broken permissions and " "conflicting behaviour with the system package manager. "