Skip to content

Commit

Permalink
Extract exception trapping functionality and only invoke it when pdb …
Browse files Browse the repository at this point in the history
…is not detected to be present. Fixes pypa#9349.
  • Loading branch information
jaraco committed Dec 24, 2020
1 parent f30a02c commit 3560f77
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _main(self, args):
# Set verbosity so that it can be used elsewhere.
self.verbosity = options.verbose - options.quiet

level_number = setup_logging(
self.level_number = setup_logging(
verbosity=self.verbosity,
no_color=options.no_color,
user_log_file=options.log,
Expand Down Expand Up @@ -186,6 +186,12 @@ def _main(self, args):
"This will become an error in pip 21.0."
)

runner = self.run if 'pdb' in sys.modules else self._trap_run
status = runner(options, args)
self.handle_pip_version_check(options)
return status

def _trap_run(self, options, args):
try:
status = self.run(options, args)
assert isinstance(status, int)
Expand All @@ -210,7 +216,7 @@ def _main(self, args):
# Bypass our logger and write any remaining messages to stderr
# because stdout no longer works.
print('ERROR: Pipe to stdout was broken', file=sys.stderr)
if level_number <= logging.DEBUG:
if self.level_number <= logging.DEBUG:
traceback.print_exc(file=sys.stderr)

return ERROR
Expand All @@ -223,5 +229,3 @@ def _main(self, args):
logger.critical('Exception:', exc_info=True)

return UNKNOWN_ERROR
finally:
self.handle_pip_version_check(options)

0 comments on commit 3560f77

Please sign in to comment.