Skip to content

Commit 680576c

Browse files
committed
Check uid on OpenBSD, NetBSD, FreeBSD before warning about root
1 parent 9f18a40 commit 680576c

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

news/10565.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Only warn about running pip as root on BSD systems if it is actually being run as root

src/pip/_internal/cli/req_command.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,18 @@ def warn_if_run_as_root() -> None:
169169
# On Windows, there are no "system managed" Python packages. Installing as
170170
# Administrator via pip is the correct way of updating system environments.
171171
#
172-
# We choose sys.platform over utils.compat.WINDOWS here to enable Mypy platform
173-
# checks: https://mypy.readthedocs.io/en/stable/common_issues.html
174-
if sys.platform == "win32" or sys.platform == "cygwin":
175-
return
176-
if sys.platform == "darwin" or sys.platform == "linux":
177-
if os.getuid() != 0:
178-
return
179-
logger.warning(
180-
"Running pip as the 'root' user can result in broken permissions and "
181-
"conflicting behaviour with the system package manager. "
182-
"It is recommended to use a virtual environment instead: "
183-
"https://pip.pypa.io/warnings/venv"
184-
)
172+
# Due to this, checking for execution as root is performed only on *nix
173+
# style platforms.
174+
if (sys.platform == "darwin" or sys.platform == "linux" or
175+
sys.platform.startswith("openbsd") or sys.platform.startswith("freebsd") or
176+
sys.platform.startswith("netbsd")):
177+
if os.getuid() == 0:
178+
logger.warning(
179+
"Running pip as the 'root' user can result in broken permissions and "
180+
"conflicting behaviour with the system package manager. "
181+
"It is recommended to use a virtual environment instead: "
182+
"https://pip.pypa.io/warnings/venv"
183+
)
185184

186185

187186
def with_cleanup(func: Any) -> Any:

0 commit comments

Comments
 (0)