Skip to content

Commit

Permalink
Don't erroneously emit warning about running pip as root
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
n1000 committed Oct 11, 2021
1 parent 9f18a40 commit e9fed34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/10565.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only warn about running pip as root if it is actually being run as root
17 changes: 8 additions & 9 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ 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
logger.warning(
"Running pip as the 'root' user can result in broken permissions and "
"conflicting behaviour with the system package manager. "
"It is recommended to use a virtual environment instead: "
"https://pip.pypa.io/warnings/venv"
)

if os.getuid() == 0:
logger.warning(
"Running pip as the 'root' user can result in broken permissions and "
"conflicting behaviour with the system package manager. "
"It is recommended to use a virtual environment instead: "
"https://pip.pypa.io/warnings/venv"
)


def with_cleanup(func: Any) -> Any:
Expand Down

0 comments on commit e9fed34

Please sign in to comment.