1"""Base Command class, and related routines"""
10from optparse
import Values
11from typing
import Any, Callable, List, Optional, Tuple
20 PREVIOUS_BUILD_DIR_ERROR,
29 NetworkConnectionError,
30 PreviousBuildDirError,
47 ignore_require_venv: bool =
False
49 def __init__(self, name: str, summary: str, isolated: bool =
False) ->
None:
56 prog=f
"{get_prog()} {name}",
58 add_help_option=
False,
60 description=self.__doc__,
67 optgroup_name = f
"{self.name.capitalize()} Options"
84 This is a no-op so that commands by default do not do the pip version
89 assert not hasattr(options,
"no_index")
91 def run(self, options: Values, args: List[str]) -> int:
92 raise NotImplementedError
94 def parse_args(self, args: List[str]) -> Tuple[Values, List[str]]:
98 def main(self, args: List[str]) -> int:
101 return self.
_main(args)
105 def _main(self, args: List[str]) -> int:
119 level_number = setup_logging(
128 if always_enabled_features:
130 "The following features are always enabled: %s. ",
131 ", ".join(sorted(always_enabled_features)),
141 "The --python option must be placed before the pip subcommand name"
157 if not running_under_virtualenv():
165 "The directory '%s' or its parent directory is not owned "
166 "or is not writable by the current user. The cache "
167 "has been disabled. Check the permissions and owner of "
168 "that directory. If executing pip with sudo, you should "
169 "use sudo's -H flag.",
175 run_func: Callable[..., int]
176 ) -> Callable[..., int]:
177 @functools.wraps(run_func)
183 except DiagnosticPipError
as exc:
188 except PreviousBuildDirError
as exc:
192 return PREVIOUS_BUILD_DIR_ERROR
197 NetworkConnectionError,
203 except CommandError
as exc:
208 except BrokenStdoutLoggingError:
211 print(
"ERROR: Pipe to stdout was broken", file=
sys.stderr)
216 except KeyboardInterrupt:
221 except BaseException:
226 return exc_logging_wrapper
234 return run(options, args)
int _main(self, List[str] args)
None __init__(self, str name, str summary, bool isolated=False)
Tuple[Values, List[str]] parse_args(self, List[str] args)
None handle_pip_version_check(self, Values options)
int run(self, Values options, List[str] args)
Generator[None, None, None] main_context(self)
_T enter_context(self, ContextManager[_T] context_provider)