Skip to content

Commit

Permalink
Remove on_returncode parameter from call_subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
deveshks committed May 23, 2020
1 parent 94882fd commit ab3ee71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
10 changes: 7 additions & 3 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ def get_revision_sha(cls, dest, rev):
rev: the revision name.
"""
# Pass rev to pre-filter the list.
output = cls.run_command(['show-ref', rev], cwd=dest,
on_returncode='ignore')

output = ''
try:
output = cls.run_command(['show-ref', rev], cwd=dest)
except SubProcessError:
pass

refs = {}
for line in output.strip().splitlines():
try:
Expand Down Expand Up @@ -378,7 +383,6 @@ def get_repository_root(cls, location):
r = cls.run_command(
['rev-parse', '--show-toplevel'],
cwd=location,
on_returncode='raise',
log_failed_cmd=False,
)
except BadCommand:
Expand Down
1 change: 0 additions & 1 deletion src/pip/_internal/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def get_repository_root(cls, location):
r = cls.run_command(
['root'],
cwd=location,
on_returncode='raise',
log_failed_cmd=False,
)
except BadCommand:
Expand Down
42 changes: 14 additions & 28 deletions src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def make_vcs_requirement_url(repo_url, rev, project_name, subdir=None):
def call_subprocess(
cmd, # type: Union[List[str], CommandArgs]
cwd=None, # type: Optional[str]
on_returncode='raise', # type: str
extra_environ=None, # type: Optional[Mapping[str, Any]]
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
log_failed_cmd=True # type: Optional[bool]
Expand Down Expand Up @@ -150,32 +149,21 @@ def call_subprocess(
proc.returncode and proc.returncode not in extra_ok_returncodes
)
if proc_had_error:
if on_returncode == 'raise':
if not showing_subprocess and log_failed_cmd:
# Then the subprocess streams haven't been logged to the
# console yet.
msg = make_subprocess_output_error(
cmd_args=cmd,
cwd=cwd,
lines=all_output,
exit_status=proc.returncode,
)
subprocess_logger.error(msg)
exc_msg = (
'Command errored out with exit status {}: {} '
'Check the logs for full command output.'
).format(proc.returncode, command_desc)
raise SubProcessError(exc_msg)
elif on_returncode == 'warn':
subprocess_logger.warning(
'Command "{}" had error code {} in {}'.format(
command_desc, proc.returncode, cwd)
if not showing_subprocess and log_failed_cmd:
# Then the subprocess streams haven't been logged to the
# console yet.
msg = make_subprocess_output_error(
cmd_args=cmd,
cwd=cwd,
lines=all_output,
exit_status=proc.returncode,
)
elif on_returncode == 'ignore':
pass
else:
raise ValueError('Invalid value: on_returncode={!r}'.format(
on_returncode))
subprocess_logger.error(msg)
exc_msg = (
'Command errored out with exit status {}: {} '
'Check the logs for full command output.'
).format(proc.returncode, command_desc)
raise SubProcessError(exc_msg)
return ''.join(all_output)


Expand Down Expand Up @@ -768,7 +756,6 @@ def run_command(
cls,
cmd, # type: Union[List[str], CommandArgs]
cwd=None, # type: Optional[str]
on_returncode='raise', # type: str
extra_environ=None, # type: Optional[Mapping[str, Any]]
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
log_failed_cmd=True # type: bool
Expand All @@ -782,7 +769,6 @@ def run_command(
cmd = make_command(cls.name, *cmd)
try:
return call_subprocess(cmd, cwd,
on_returncode=on_returncode,
extra_environ=extra_environ,
extra_ok_returncodes=extra_ok_returncodes,
log_failed_cmd=log_failed_cmd)
Expand Down

0 comments on commit ab3ee71

Please sign in to comment.