Skip to content

Commit 2e5e914

Browse files
committed
Remove show_stdout from run_command args
1 parent f52b538 commit 2e5e914

File tree

5 files changed

+36
-59
lines changed

5 files changed

+36
-59
lines changed

src/pip/_internal/vcs/bazaar.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def export(self, location, url):
5454

5555
url, rev_options = self.get_url_rev_options(url)
5656
self.run_command(
57-
make_command('export', location, url, rev_options.to_args()),
58-
show_stdout=False,
57+
make_command('export', location, url, rev_options.to_args())
5958
)
6059

6160
def fetch_new(self, dest, url, rev_options):
@@ -92,7 +91,7 @@ def get_url_rev_and_auth(cls, url):
9291

9392
@classmethod
9493
def get_remote_url(cls, location):
95-
urls = cls.run_command(['info'], show_stdout=False, cwd=location)
94+
urls = cls.run_command(['info'], cwd=location)
9695
for line in urls.splitlines():
9796
line = line.strip()
9897
for x in ('checkout of branch: ',
@@ -107,7 +106,7 @@ def get_remote_url(cls, location):
107106
@classmethod
108107
def get_revision(cls, location):
109108
revision = cls.run_command(
110-
['revno'], show_stdout=False, cwd=location,
109+
['revno'], cwd=location,
111110
)
112111
return revision.splitlines()[-1]
113112

src/pip/_internal/vcs/git.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pip._vendor.six.moves.urllib import parse as urllib_parse
1212
from pip._vendor.six.moves.urllib import request as urllib_request
1313

14-
from pip._internal.exceptions import BadCommand, InstallationError
14+
from pip._internal.exceptions import BadCommand, SubProcessError
1515
from pip._internal.utils.misc import display_path, hide_url
1616
from pip._internal.utils.subprocess import make_command
1717
from pip._internal.utils.temp_dir import TempDirectory
@@ -78,7 +78,7 @@ def is_immutable_rev_checkout(self, url, dest):
7878

7979
def get_git_version(self):
8080
VERSION_PFX = 'git version '
81-
version = self.run_command(['version'], show_stdout=False)
81+
version = self.run_command(['version'])
8282
if version.startswith(VERSION_PFX):
8383
version = version[len(VERSION_PFX):].split()[0]
8484
else:
@@ -101,7 +101,7 @@ def get_current_branch(cls, location):
101101
# and to suppress the message to stderr.
102102
args = ['symbolic-ref', '-q', 'HEAD']
103103
output = cls.run_command(
104-
args, extra_ok_returncodes=(1, ), show_stdout=False, cwd=location,
104+
args, extra_ok_returncodes=(1, ), cwd=location,
105105
)
106106
ref = output.strip()
107107

@@ -120,7 +120,7 @@ def export(self, location, url):
120120
self.unpack(temp_dir.path, url=url)
121121
self.run_command(
122122
['checkout-index', '-a', '-f', '--prefix', location],
123-
show_stdout=False, cwd=temp_dir.path
123+
cwd=temp_dir.path
124124
)
125125

126126
@classmethod
@@ -135,7 +135,7 @@ def get_revision_sha(cls, dest, rev):
135135
"""
136136
# Pass rev to pre-filter the list.
137137
output = cls.run_command(['show-ref', rev], cwd=dest,
138-
show_stdout=False, on_returncode='ignore')
138+
on_returncode='ignore')
139139
refs = {}
140140
for line in output.strip().splitlines():
141141
try:
@@ -286,7 +286,7 @@ def get_remote_url(cls, location):
286286
# exits with return code 1 if there are no matching lines.
287287
stdout = cls.run_command(
288288
['config', '--get-regexp', r'remote\..*\.url'],
289-
extra_ok_returncodes=(1, ), show_stdout=False, cwd=location,
289+
extra_ok_returncodes=(1, ), cwd=location,
290290
)
291291
remotes = stdout.splitlines()
292292
try:
@@ -306,7 +306,7 @@ def get_revision(cls, location, rev=None):
306306
if rev is None:
307307
rev = 'HEAD'
308308
current_rev = cls.run_command(
309-
['rev-parse', rev], show_stdout=False, cwd=location,
309+
['rev-parse', rev], cwd=location,
310310
)
311311
return current_rev.strip()
312312

@@ -319,7 +319,7 @@ def get_subdirectory(cls, location):
319319
# find the repo root
320320
git_dir = cls.run_command(
321321
['rev-parse', '--git-dir'],
322-
show_stdout=False, cwd=location).strip()
322+
cwd=location).strip()
323323
if not os.path.isabs(git_dir):
324324
git_dir = os.path.join(location, git_dir)
325325
repo_root = os.path.abspath(os.path.join(git_dir, '..'))
@@ -378,15 +378,14 @@ def get_repository_root(cls, location):
378378
r = cls.run_command(
379379
['rev-parse', '--show-toplevel'],
380380
cwd=location,
381-
show_stdout=False,
382381
on_returncode='raise',
383382
log_failed_cmd=False,
384383
)
385384
except BadCommand:
386385
logger.debug("could not determine if %s is under git control "
387386
"because git is not available", location)
388387
return None
389-
except InstallationError:
388+
except SubProcessError:
390389
return None
391390
return os.path.normpath(r.rstrip('\r\n'))
392391

src/pip/_internal/vcs/mercurial.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pip._vendor.six.moves import configparser
1010

11-
from pip._internal.exceptions import BadCommand, InstallationError
11+
from pip._internal.exceptions import BadCommand, SubProcessError
1212
from pip._internal.utils.misc import display_path
1313
from pip._internal.utils.subprocess import make_command
1414
from pip._internal.utils.temp_dir import TempDirectory
@@ -47,7 +47,7 @@ def export(self, location, url):
4747
self.unpack(temp_dir.path, url=url)
4848

4949
self.run_command(
50-
['archive', location], show_stdout=False, cwd=temp_dir.path
50+
['archive', location], cwd=temp_dir.path
5151
)
5252

5353
def fetch_new(self, dest, url, rev_options):
@@ -92,7 +92,7 @@ def update(self, dest, url, rev_options):
9292
def get_remote_url(cls, location):
9393
url = cls.run_command(
9494
['showconfig', 'paths.default'],
95-
show_stdout=False, cwd=location).strip()
95+
cwd=location).strip()
9696
if cls._is_local_repository(url):
9797
url = path_to_url(url)
9898
return url.strip()
@@ -103,8 +103,7 @@ def get_revision(cls, location):
103103
Return the repository-local changeset revision number, as an integer.
104104
"""
105105
current_revision = cls.run_command(
106-
['parents', '--template={rev}'],
107-
show_stdout=False, cwd=location).strip()
106+
['parents', '--template={rev}'], cwd=location).strip()
108107
return current_revision
109108

110109
@classmethod
@@ -115,7 +114,7 @@ def get_requirement_revision(cls, location):
115114
"""
116115
current_rev_hash = cls.run_command(
117116
['parents', '--template={node}'],
118-
show_stdout=False, cwd=location).strip()
117+
cwd=location).strip()
119118
return current_rev_hash
120119

121120
@classmethod
@@ -131,7 +130,7 @@ def get_subdirectory(cls, location):
131130
"""
132131
# find the repo root
133132
repo_root = cls.run_command(
134-
['root'], show_stdout=False, cwd=location).strip()
133+
['root'], cwd=location).strip()
135134
if not os.path.isabs(repo_root):
136135
repo_root = os.path.abspath(os.path.join(location, repo_root))
137136
return find_path_to_setup_from_repo_root(location, repo_root)
@@ -145,15 +144,14 @@ def get_repository_root(cls, location):
145144
r = cls.run_command(
146145
['root'],
147146
cwd=location,
148-
show_stdout=False,
149147
on_returncode='raise',
150148
log_failed_cmd=False,
151149
)
152150
except BadCommand:
153151
logger.debug("could not determine if %s is under hg control "
154152
"because hg is not available", location)
155153
return None
156-
except InstallationError:
154+
except SubProcessError:
157155
return None
158156
return os.path.normpath(r.rstrip('\r\n'))
159157

src/pip/_internal/vcs/subversion.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def get_remote_url(cls, location):
132132

133133
@classmethod
134134
def _get_svn_url_rev(cls, location):
135-
from pip._internal.exceptions import InstallationError
135+
from pip._internal.exceptions import SubProcessError
136136

137137
entries_path = os.path.join(location, cls.dirname, 'entries')
138138
if os.path.exists(entries_path):
@@ -165,13 +165,12 @@ def _get_svn_url_rev(cls, location):
165165
# are only potentially needed for remote server requests.
166166
xml = cls.run_command(
167167
['info', '--xml', location],
168-
show_stdout=False,
169168
)
170169
url = _svn_info_xml_url_re.search(xml).group(1)
171170
revs = [
172171
int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)
173172
]
174-
except InstallationError:
173+
except SubProcessError:
175174
url, revs = None, []
176175

177176
if revs:
@@ -215,7 +214,7 @@ def call_vcs_version(self):
215214
# svn, version 1.7.14 (r1542130)
216215
# compiled Mar 28 2018, 08:49:13 on x86_64-pc-linux-gnu
217216
version_prefix = 'svn, version '
218-
version = self.run_command(['--version'], show_stdout=True)
217+
version = self.run_command(['--version'])
219218

220219
if not version.startswith(version_prefix):
221220
return ()
@@ -298,7 +297,7 @@ def export(self, location, url):
298297
'export', self.get_remote_call_options(),
299298
rev_options.to_args(), url, location,
300299
)
301-
self.run_command(cmd_args, show_stdout=False)
300+
self.run_command(cmd_args)
302301

303302
def fetch_new(self, dest, url, rev_options):
304303
# type: (str, HiddenText, RevOptions) -> None

src/pip/_internal/vcs/versioncontrol.py

+13-31
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
if MYPY_CHECK_RUNNING:
4040
from typing import (
4141
Dict, Iterable, Iterator, List, Optional, Text, Tuple,
42-
Type, Union
42+
Type, Union, Mapping, Any
4343
)
4444
from pip._internal.utils.misc import HiddenText
4545
from pip._internal.utils.subprocess import CommandArgs
@@ -83,51 +83,32 @@ def make_vcs_requirement_url(repo_url, rev, project_name, subdir=None):
8383

8484
def call_subprocess(
8585
cmd, # type: Union[List[str], CommandArgs]
86-
show_stdout=False, # type: bool
8786
cwd=None, # type: Optional[str]
8887
on_returncode='raise', # type: str
88+
extra_environ=None, # type: Optional[Mapping[str, Any]]
8989
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
9090
log_failed_cmd=True # type: Optional[bool]
9191
):
9292
# type: (...) -> Text
9393
"""
9494
Args:
95-
show_stdout: if true, use INFO to log the subprocess's stderr and
96-
stdout streams. Otherwise, use DEBUG. Defaults to False.
9795
extra_ok_returncodes: an iterable of integer return codes that are
9896
acceptable, in addition to 0. Defaults to None, which means [].
9997
log_failed_cmd: if false, failed commands are not logged,
10098
only raised.
10199
"""
102100
if extra_ok_returncodes is None:
103101
extra_ok_returncodes = []
104-
# Most places in pip use show_stdout=False.
105-
# What this means is--
106-
#
107-
# - We log this output of stdout and stderr at DEBUG level
108-
# as it is received.
109-
# - If DEBUG logging isn't enabled (e.g. if --verbose logging wasn't
110-
# requested), then we show a spinner so the user can still see the
111-
# subprocess is in progress.
112-
# - If the subprocess exits with an error, we log the output to stderr
113-
# at ERROR level if it hasn't already been displayed to the console
114-
# (e.g. if --verbose logging wasn't enabled). This way we don't log
115-
# the output to the console twice.
116-
#
117-
# If show_stdout=True, then the above is still done, but with DEBUG
118-
# replaced by INFO.
119-
if show_stdout:
120-
# Then log the subprocess output at INFO level.
121-
log_subprocess = subprocess_logger.info
122-
used_level = logging.INFO
123-
else:
124-
# Then log the subprocess output using DEBUG. This also ensures
125-
# it will be logged to the log file (aka user_log), if enabled.
126-
log_subprocess = subprocess_logger.debug
127-
used_level = logging.DEBUG
102+
103+
# log the subprocess output at DEBUG level.
104+
log_subprocess = subprocess_logger.debug
105+
106+
env = os.environ.copy()
107+
if extra_environ:
108+
env.update(extra_environ)
128109

129110
# Whether the subprocess will be visible in the console.
130-
showing_subprocess = subprocess_logger.getEffectiveLevel() <= used_level
111+
showing_subprocess = True
131112

132113
command_desc = format_command_args(cmd)
133114
try:
@@ -786,9 +767,9 @@ def get_revision(cls, location):
786767
def run_command(
787768
cls,
788769
cmd, # type: Union[List[str], CommandArgs]
789-
show_stdout=True, # type: bool
790770
cwd=None, # type: Optional[str]
791771
on_returncode='raise', # type: str
772+
extra_environ=None, # type: Optional[Mapping[str, Any]]
792773
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
793774
log_failed_cmd=True # type: bool
794775
):
@@ -800,8 +781,9 @@ def run_command(
800781
"""
801782
cmd = make_command(cls.name, *cmd)
802783
try:
803-
return call_subprocess(cmd, show_stdout, cwd,
784+
return call_subprocess(cmd, cwd,
804785
on_returncode=on_returncode,
786+
extra_environ=extra_environ,
805787
extra_ok_returncodes=extra_ok_returncodes,
806788
log_failed_cmd=log_failed_cmd)
807789
except OSError as e:

0 commit comments

Comments
 (0)