Skip to content

Commit f84f91a

Browse files
authored
Merge pull request #7969 from deveshks/fix-svn-version-check
2 parents c36826a + 5c615aa commit f84f91a

File tree

8 files changed

+144
-49
lines changed

8 files changed

+144
-49
lines changed

news/7968.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The VCS commands run by pip as subprocesses don't merge stdout and stderr anymore, improving the output parsing by subsequent commands.

src/pip/_internal/cli/base_command.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CommandError,
2929
InstallationError,
3030
PreviousBuildDirError,
31+
SubProcessError,
3132
UninstallationError,
3233
)
3334
from pip._internal.utils.deprecation import deprecated
@@ -201,7 +202,8 @@ def _main(self, args):
201202
logger.debug('Exception information:', exc_info=True)
202203

203204
return PREVIOUS_BUILD_DIR_ERROR
204-
except (InstallationError, UninstallationError, BadCommand) as exc:
205+
except (InstallationError, UninstallationError, BadCommand,
206+
SubProcessError) as exc:
205207
logger.critical(str(exc))
206208
logger.debug('Exception information:', exc_info=True)
207209

src/pip/_internal/exceptions.py

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class CommandError(PipError):
8484
"""Raised when there is an error in command-line arguments"""
8585

8686

87+
class SubProcessError(PipError):
88+
"""Raised when there is an error raised while executing a
89+
command in subprocess"""
90+
91+
8792
class PreviousBuildDirError(PipError):
8893
"""Raised when there's a previous conflicting build directory"""
8994

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

+15-12
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
@@ -134,8 +134,13 @@ def get_revision_sha(cls, dest, rev):
134134
rev: the revision name.
135135
"""
136136
# Pass rev to pre-filter the list.
137-
output = cls.run_command(['show-ref', rev], cwd=dest,
138-
show_stdout=False, on_returncode='ignore')
137+
138+
output = ''
139+
try:
140+
output = cls.run_command(['show-ref', rev], cwd=dest)
141+
except SubProcessError:
142+
pass
143+
139144
refs = {}
140145
for line in output.strip().splitlines():
141146
try:
@@ -286,7 +291,7 @@ def get_remote_url(cls, location):
286291
# exits with return code 1 if there are no matching lines.
287292
stdout = cls.run_command(
288293
['config', '--get-regexp', r'remote\..*\.url'],
289-
extra_ok_returncodes=(1, ), show_stdout=False, cwd=location,
294+
extra_ok_returncodes=(1, ), cwd=location,
290295
)
291296
remotes = stdout.splitlines()
292297
try:
@@ -306,7 +311,7 @@ def get_revision(cls, location, rev=None):
306311
if rev is None:
307312
rev = 'HEAD'
308313
current_rev = cls.run_command(
309-
['rev-parse', rev], show_stdout=False, cwd=location,
314+
['rev-parse', rev], cwd=location,
310315
)
311316
return current_rev.strip()
312317

@@ -319,7 +324,7 @@ def get_subdirectory(cls, location):
319324
# find the repo root
320325
git_dir = cls.run_command(
321326
['rev-parse', '--git-dir'],
322-
show_stdout=False, cwd=location).strip()
327+
cwd=location).strip()
323328
if not os.path.isabs(git_dir):
324329
git_dir = os.path.join(location, git_dir)
325330
repo_root = os.path.abspath(os.path.join(git_dir, '..'))
@@ -378,15 +383,13 @@ def get_repository_root(cls, location):
378383
r = cls.run_command(
379384
['rev-parse', '--show-toplevel'],
380385
cwd=location,
381-
show_stdout=False,
382-
on_returncode='raise',
383386
log_failed_cmd=False,
384387
)
385388
except BadCommand:
386389
logger.debug("could not determine if %s is under git control "
387390
"because git is not available", location)
388391
return None
389-
except InstallationError:
392+
except SubProcessError:
390393
return None
391394
return os.path.normpath(r.rstrip('\r\n'))
392395

src/pip/_internal/vcs/mercurial.py

+7-10
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,13 @@ def get_repository_root(cls, location):
145144
r = cls.run_command(
146145
['root'],
147146
cwd=location,
148-
show_stdout=False,
149-
on_returncode='raise',
150147
log_failed_cmd=False,
151148
)
152149
except BadCommand:
153150
logger.debug("could not determine if %s is under hg control "
154151
"because hg is not available", location)
155152
return None
156-
except InstallationError:
153+
except SubProcessError:
157154
return None
158155
return os.path.normpath(r.rstrip('\r\n'))
159156

src/pip/_internal/vcs/subversion.py

+5-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,8 @@ 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=False)
217+
version = self.run_command(['--version'])
218+
219219
if not version.startswith(version_prefix):
220220
return ()
221221

@@ -297,7 +297,7 @@ def export(self, location, url):
297297
'export', self.get_remote_call_options(),
298298
rev_options.to_args(), url, location,
299299
)
300-
self.run_command(cmd_args, show_stdout=False)
300+
self.run_command(cmd_args)
301301

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

0 commit comments

Comments
 (0)