Revert "Remove show_stdout from run_command args"

This reverts commit 94882fd1ed.
This commit is contained in:
Stéphane Bidoul 2020-12-21 12:44:23 +01:00
parent 6480bed441
commit 6693a71e0a
No known key found for this signature in database
GPG Key ID: BCAB2555446B5B92
5 changed files with 62 additions and 39 deletions

View File

@ -55,7 +55,8 @@ class Bazaar(VersionControl):
url, rev_options = self.get_url_rev_options(url)
self.run_command(
make_command('export', location, url, rev_options.to_args())
make_command('export', location, url, rev_options.to_args()),
show_stdout=False,
)
def fetch_new(self, dest, url, rev_options):
@ -92,7 +93,7 @@ class Bazaar(VersionControl):
@classmethod
def get_remote_url(cls, location):
urls = cls.run_command(['info'], cwd=location)
urls = cls.run_command(['info'], show_stdout=False, cwd=location)
for line in urls.splitlines():
line = line.strip()
for x in ('checkout of branch: ',
@ -107,7 +108,7 @@ class Bazaar(VersionControl):
@classmethod
def get_revision(cls, location):
revision = cls.run_command(
['revno'], cwd=location,
['revno'], show_stdout=False, cwd=location,
)
return revision.splitlines()[-1]

View File

@ -11,7 +11,7 @@ from pip._vendor.packaging.version import parse as parse_version
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.six.moves.urllib import request as urllib_request
from pip._internal.exceptions import BadCommand, SubProcessError
from pip._internal.exceptions import BadCommand, InstallationError, SubProcessError
from pip._internal.utils.misc import display_path, hide_url
from pip._internal.utils.subprocess import make_command
from pip._internal.utils.temp_dir import TempDirectory
@ -79,7 +79,7 @@ class Git(VersionControl):
def get_git_version(self):
VERSION_PFX = 'git version '
version = self.run_command(['version'])
version = self.run_command(['version'], show_stdout=False)
if version.startswith(VERSION_PFX):
version = version[len(VERSION_PFX):].split()[0]
else:
@ -102,7 +102,7 @@ class Git(VersionControl):
# and to suppress the message to stderr.
args = ['symbolic-ref', '-q', 'HEAD']
output = cls.run_command(
args, extra_ok_returncodes=(1, ), cwd=location,
args, extra_ok_returncodes=(1, ), show_stdout=False, cwd=location,
)
ref = output.strip()
@ -121,7 +121,7 @@ class Git(VersionControl):
self.unpack(temp_dir.path, url=url)
self.run_command(
['checkout-index', '-a', '-f', '--prefix', location],
cwd=temp_dir.path
show_stdout=False, cwd=temp_dir.path
)
@classmethod
@ -136,7 +136,7 @@ class Git(VersionControl):
"""
# Pass rev to pre-filter the list.
output = cls.run_command(['show-ref', rev], cwd=dest,
on_returncode='ignore')
show_stdout=False, on_returncode='ignore')
refs = {}
for line in output.strip().splitlines():
try:
@ -310,7 +310,7 @@ class Git(VersionControl):
# exits with return code 1 if there are no matching lines.
stdout = cls.run_command(
['config', '--get-regexp', r'remote\..*\.url'],
extra_ok_returncodes=(1, ), cwd=location,
extra_ok_returncodes=(1, ), show_stdout=False, cwd=location,
)
remotes = stdout.splitlines()
try:
@ -344,7 +344,7 @@ class Git(VersionControl):
if rev is None:
rev = 'HEAD'
current_rev = cls.run_command(
['rev-parse', rev], cwd=location,
['rev-parse', rev], show_stdout=False, cwd=location,
)
return current_rev.strip()
@ -357,7 +357,7 @@ class Git(VersionControl):
# find the repo root
git_dir = cls.run_command(
['rev-parse', '--git-dir'],
cwd=location).strip()
show_stdout=False, cwd=location).strip()
if not os.path.isabs(git_dir):
git_dir = os.path.join(location, git_dir)
repo_root = os.path.abspath(os.path.join(git_dir, '..'))
@ -415,6 +415,7 @@ class Git(VersionControl):
r = cls.run_command(
['rev-parse', '--show-toplevel'],
cwd=location,
show_stdout=False,
on_returncode='raise',
log_failed_cmd=False,
)
@ -422,7 +423,7 @@ class Git(VersionControl):
logger.debug("could not determine if %s is under git control "
"because git is not available", location)
return None
except SubProcessError:
except InstallationError:
return None
return os.path.normpath(r.rstrip('\r\n'))

View File

@ -8,7 +8,7 @@ import os
from pip._vendor.six.moves import configparser
from pip._internal.exceptions import BadCommand, SubProcessError
from pip._internal.exceptions import BadCommand, InstallationError
from pip._internal.utils.misc import display_path
from pip._internal.utils.subprocess import make_command
from pip._internal.utils.temp_dir import TempDirectory
@ -47,7 +47,7 @@ class Mercurial(VersionControl):
self.unpack(temp_dir.path, url=url)
self.run_command(
['archive', location], cwd=temp_dir.path
['archive', location], show_stdout=False, cwd=temp_dir.path
)
def fetch_new(self, dest, url, rev_options):
@ -92,7 +92,7 @@ class Mercurial(VersionControl):
def get_remote_url(cls, location):
url = cls.run_command(
['showconfig', 'paths.default'],
cwd=location).strip()
show_stdout=False, cwd=location).strip()
if cls._is_local_repository(url):
url = path_to_url(url)
return url.strip()
@ -103,7 +103,8 @@ class Mercurial(VersionControl):
Return the repository-local changeset revision number, as an integer.
"""
current_revision = cls.run_command(
['parents', '--template={rev}'], cwd=location).strip()
['parents', '--template={rev}'],
show_stdout=False, cwd=location).strip()
return current_revision
@classmethod
@ -114,7 +115,7 @@ class Mercurial(VersionControl):
"""
current_rev_hash = cls.run_command(
['parents', '--template={node}'],
cwd=location).strip()
show_stdout=False, cwd=location).strip()
return current_rev_hash
@classmethod
@ -130,7 +131,7 @@ class Mercurial(VersionControl):
"""
# find the repo root
repo_root = cls.run_command(
['root'], cwd=location).strip()
['root'], show_stdout=False, cwd=location).strip()
if not os.path.isabs(repo_root):
repo_root = os.path.abspath(os.path.join(location, repo_root))
return find_path_to_setup_from_repo_root(location, repo_root)
@ -144,6 +145,7 @@ class Mercurial(VersionControl):
r = cls.run_command(
['root'],
cwd=location,
show_stdout=False,
on_returncode='raise',
log_failed_cmd=False,
)
@ -151,7 +153,7 @@ class Mercurial(VersionControl):
logger.debug("could not determine if %s is under hg control "
"because hg is not available", location)
return None
except SubProcessError:
except InstallationError:
return None
return os.path.normpath(r.rstrip('\r\n'))

View File

@ -133,7 +133,7 @@ class Subversion(VersionControl):
@classmethod
def _get_svn_url_rev(cls, location):
from pip._internal.exceptions import SubProcessError
from pip._internal.exceptions import InstallationError
entries_path = os.path.join(location, cls.dirname, 'entries')
if os.path.exists(entries_path):
@ -166,12 +166,13 @@ class Subversion(VersionControl):
# are only potentially needed for remote server requests.
xml = cls.run_command(
['info', '--xml', location],
show_stdout=False,
)
url = _svn_info_xml_url_re.search(xml).group(1)
revs = [
int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)
]
except SubProcessError:
except InstallationError:
url, revs = None, []
if revs:
@ -217,7 +218,7 @@ class Subversion(VersionControl):
# svn, version 1.12.0-SlikSvn (SlikSvn/1.12.0)
# compiled May 28 2019, 13:44:56 on x86_64-microsoft-windows6.2
version_prefix = 'svn, version '
version = self.run_command(['--version'])
version = self.run_command(['--version'], show_stdout=True)
if not version.startswith(version_prefix):
return ()
@ -300,7 +301,7 @@ class Subversion(VersionControl):
'export', self.get_remote_call_options(),
rev_options.to_args(), url, location,
)
self.run_command(cmd_args)
self.run_command(cmd_args, show_stdout=False)
def fetch_new(self, dest, url, rev_options):
# type: (str, HiddenText, RevOptions) -> None

View File

@ -34,12 +34,10 @@ from pip._internal.utils.urls import get_url_scheme
if MYPY_CHECK_RUNNING:
from typing import (
Any,
Dict,
Iterable,
Iterator,
List,
Mapping,
Optional,
Text,
Tuple,
@ -89,15 +87,17 @@ def make_vcs_requirement_url(repo_url, rev, project_name, subdir=None):
def call_subprocess(
cmd, # type: Union[List[str], CommandArgs]
show_stdout=False, # type: bool
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]
):
# type: (...) -> Text
"""
Args:
show_stdout: if true, use INFO to log the subprocess's stderr and
stdout streams. Otherwise, use DEBUG. Defaults to False.
extra_ok_returncodes: an iterable of integer return codes that are
acceptable, in addition to 0. Defaults to None, which means [].
log_failed_cmd: if false, failed commands are not logged,
@ -105,16 +105,33 @@ def call_subprocess(
"""
if extra_ok_returncodes is None:
extra_ok_returncodes = []
# log the subprocess output at DEBUG level.
log_subprocess = subprocess_logger.debug
env = os.environ.copy()
if extra_environ:
env.update(extra_environ)
# Most places in pip use show_stdout=False.
# What this means is--
#
# - We log this output of stdout and stderr at DEBUG level
# as it is received.
# - If DEBUG logging isn't enabled (e.g. if --verbose logging wasn't
# requested), then we show a spinner so the user can still see the
# subprocess is in progress.
# - If the subprocess exits with an error, we log the output to stderr
# at ERROR level if it hasn't already been displayed to the console
# (e.g. if --verbose logging wasn't enabled). This way we don't log
# the output to the console twice.
#
# If show_stdout=True, then the above is still done, but with DEBUG
# replaced by INFO.
if show_stdout:
# Then log the subprocess output at INFO level.
log_subprocess = subprocess_logger.info
used_level = logging.INFO
else:
# Then log the subprocess output using DEBUG. This also ensures
# it will be logged to the log file (aka user_log), if enabled.
log_subprocess = subprocess_logger.debug
used_level = logging.DEBUG
# Whether the subprocess will be visible in the console.
showing_subprocess = True
showing_subprocess = subprocess_logger.getEffectiveLevel() <= used_level
command_desc = format_command_args(cmd)
try:
@ -176,8 +193,10 @@ def call_subprocess(
raise SubProcessError(exc_msg)
elif on_returncode == 'warn':
subprocess_logger.warning(
'Command "{}" had error code {} in {}'.format(
command_desc, proc.returncode, cwd)
'Command "%s" had error code %s in %s',
command_desc,
proc.returncode,
cwd,
)
elif on_returncode == 'ignore':
pass
@ -775,9 +794,9 @@ class VersionControl(object):
def run_command(
cls,
cmd, # type: Union[List[str], CommandArgs]
show_stdout=True, # type: bool
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
):
@ -789,9 +808,8 @@ class VersionControl(object):
"""
cmd = make_command(cls.name, *cmd)
try:
return call_subprocess(cmd, cwd,
return call_subprocess(cmd, show_stdout, cwd,
on_returncode=on_returncode,
extra_environ=extra_environ,
extra_ok_returncodes=extra_ok_returncodes,
log_failed_cmd=log_failed_cmd)
except OSError as e: