Skip to content

Commit

Permalink
Make the root warning silence flag multi-state (#11035)
Browse files Browse the repository at this point in the history
Instead of a flag, make the option take an argument like this:

    --root-user-action=ignore

This allows us to add more alternatives in the future, for example to
emit a hard error when a root user is detected.

Also re-label the news fragment to point to the issue instead of the PR
that introduced the option.
  • Loading branch information
uranusjr committed Apr 14, 2022
1 parent e4376ed commit 2e1112a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
File renamed without changes.
12 changes: 6 additions & 6 deletions src/pip/_internal/cli/cmdoptions.py
Expand Up @@ -853,13 +853,13 @@ def _handle_no_use_pep517(
"of pip is available for download. Implied with --no-index.",
)

warn_about_root_user: Callable[..., Option] = partial(
root_user_action: Callable[..., Option] = partial(
Option,
"--no-warn-when-using-as-a-root-user",
dest="warn_about_root_user",
default=True,
action="store_false",
help="Do not warn when used as a root user",
"--root-user-action",
dest="root_user_action",
default="warn",
choices=["warn", "ignore"],
help="Action if pip is run as a root user. By default, a warning message is shown.",
)


Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/commands/install.py
Expand Up @@ -227,7 +227,7 @@ def add_options(self) -> None:
self.cmd_opts.add_option(cmdoptions.prefer_binary())
self.cmd_opts.add_option(cmdoptions.require_hashes())
self.cmd_opts.add_option(cmdoptions.progress_bar())
self.cmd_opts.add_option(cmdoptions.warn_about_root_user())
self.cmd_opts.add_option(cmdoptions.root_user_action())

index_opts = cmdoptions.make_option_group(
cmdoptions.index_group,
Expand Down Expand Up @@ -464,7 +464,7 @@ def run(self, options: Values, args: List[str]) -> int:
self._handle_target_dir(
options.target_dir, target_temp_dir, options.upgrade
)
if options.warn_about_root_user:
if options.root_user_action == "warn":
warn_if_run_as_root()
return SUCCESS

Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/commands/uninstall.py
Expand Up @@ -54,7 +54,7 @@ def add_options(self) -> None:
action="store_true",
help="Don't ask for confirmation of uninstall deletions.",
)
self.cmd_opts.add_option(cmdoptions.warn_about_root_user())
self.cmd_opts.add_option(cmdoptions.root_user_action())
self.parser.insert_option_group(0, self.cmd_opts)

def run(self, options: Values, args: List[str]) -> int:
Expand Down Expand Up @@ -101,6 +101,6 @@ def run(self, options: Values, args: List[str]) -> int:
)
if uninstall_pathset:
uninstall_pathset.commit()
if options.warn_about_root_user:
if options.root_user_action == "warn":
warn_if_run_as_root()
return SUCCESS

0 comments on commit 2e1112a

Please sign in to comment.