Skip to content

Commit

Permalink
Use warnings module for running as root message
Browse files Browse the repository at this point in the history
This allows use of warnings module for runtime warning
as this allows fine tuning using PYTHONWARNINGS
variable, providing a workaround for #10556
  • Loading branch information
ssbarnea committed Jan 13, 2022
1 parent 7f8a684 commit 3db1b7f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/10792.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use warnings module for producing warning when run as root and outside a
virtual environment.
3 changes: 2 additions & 1 deletion src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import sys
import warnings
from functools import partial
from optparse import Values
from typing import Any, List, Optional, Tuple
Expand Down Expand Up @@ -177,7 +178,7 @@ def warn_if_run_as_root() -> None:
if os.getuid() != 0:
return

logger.warning(
warnings.warn(
"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: "
Expand Down

0 comments on commit 3db1b7f

Please sign in to comment.