1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Make the root warning silence flag multi-state (#11035)

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.
This commit is contained in:
Tzu-ping Chung 2022-04-15 01:10:19 +08:00 committed by GitHub
parent e4376ed128
commit 2e1112a814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View file

@ -853,13 +853,13 @@ disable_pip_version_check: Callable[..., Option] = partial(
"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.",
)

View file

@ -227,7 +227,7 @@ class InstallCommand(RequirementCommand):
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,
@ -464,7 +464,7 @@ class InstallCommand(RequirementCommand):
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

View file

@ -54,7 +54,7 @@ class UninstallCommand(Command, SessionCommandMixin):
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:
@ -101,6 +101,6 @@ class UninstallCommand(Command, SessionCommandMixin):
)
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