Skip to content

Commit 5a00ac4

Browse files
authored
Merge pull request #6383 from cjerdonek/fix-freeze-debug-message
Fix a freeze debug log message.
2 parents 58c93ac + 7e10908 commit 5a00ac4

File tree

7 files changed

+87
-62
lines changed

7 files changed

+87
-62
lines changed

news/6383.bugfix

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a debug log message when freezing an editable, non-version controlled
2+
requirement.

src/pip/_internal/operations/freeze.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def get_requirement_info(dist):
178178
if not vc_type:
179179
req = dist.as_requirement()
180180
logger.debug(
181-
'No VCS found for editable requirement {!r} in: {!r}', req,
181+
'No VCS found for editable requirement "%s" in: %r', req,
182182
location,
183183
)
184184
comments = [

tests/functional/test_freeze.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_freeze_editable_not_vcs(script, tmpdir):
126126
# as a VCS directory.
127127
os.rename(os.path.join(pkg_path, '.git'), os.path.join(pkg_path, '.bak'))
128128
script.pip('install', '-e', pkg_path)
129-
result = script.pip('freeze', expect_stderr=True)
129+
result = script.pip('freeze')
130130

131131
# We need to apply os.path.normcase() to the path since that is what
132132
# the freeze code does.

tests/functional/test_install_vcs_git.py

+23-50
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _get_branch_remote(script, package_name, branch):
4040
return result.stdout.strip()
4141

4242

43-
def _github_checkout(url_path, temp_dir, egg=None, scheme=None):
43+
def _github_checkout(url_path, temp_dir, rev=None, egg=None, scheme=None):
4444
"""
4545
Call local_checkout() with a GitHub URL, and return the resulting URL.
4646
@@ -56,6 +56,8 @@ def _github_checkout(url_path, temp_dir, egg=None, scheme=None):
5656
scheme = 'https'
5757
url = 'git+{}://github.com/{}'.format(scheme, url_path)
5858
local_url = local_checkout(url, temp_dir.join('cache'))
59+
if rev is not None:
60+
local_url += '@{}'.format(rev)
5961
if egg is not None:
6062
local_url += '#egg={}'.format(egg)
6163

@@ -150,7 +152,7 @@ def test_install_editable_from_git_with_https(script, tmpdir):
150152
"""
151153
url_path = 'pypa/pip-test-package.git'
152154
local_url = _github_checkout(url_path, tmpdir, egg='pip-test-package')
153-
result = script.pip('install', '-e', local_url, expect_error=True)
155+
result = script.pip('install', '-e', local_url)
154156
result.assert_installed('pip-test-package', with_files=['.git'])
155157

156158

@@ -184,9 +186,7 @@ def test_git_with_sha1_revisions(script):
184186
'git', 'rev-parse', 'HEAD~1',
185187
cwd=version_pkg_path,
186188
).stdout.strip()
187-
version = _install_version_pkg(
188-
script, version_pkg_path, rev=sha1, expect_stderr=True,
189-
)
189+
version = _install_version_pkg(script, version_pkg_path, rev=sha1)
190190
assert '0.1' == version
191191

192192

@@ -200,9 +200,7 @@ def test_git_with_short_sha1_revisions(script):
200200
'git', 'rev-parse', 'HEAD~1',
201201
cwd=version_pkg_path,
202202
).stdout.strip()[:7]
203-
version = _install_version_pkg(
204-
script, version_pkg_path, rev=sha1, expect_stderr=True,
205-
)
203+
version = _install_version_pkg(script, version_pkg_path, rev=sha1)
206204
assert '0.1' == version
207205

208206

@@ -212,11 +210,7 @@ def test_git_with_branch_name_as_revision(script):
212210
"""
213211
version_pkg_path = _create_test_package(script)
214212
branch = 'test_branch'
215-
script.run(
216-
'git', 'checkout', '-b', branch,
217-
expect_stderr=True,
218-
cwd=version_pkg_path,
219-
)
213+
script.run('git', 'checkout', '-b', branch, cwd=version_pkg_path)
220214
_change_test_package_version(script, version_pkg_path)
221215
version = _install_version_pkg(script, version_pkg_path, rev=branch)
222216
assert 'some different version' == version
@@ -227,11 +221,7 @@ def test_git_with_tag_name_as_revision(script):
227221
Git backend should be able to install from tag names
228222
"""
229223
version_pkg_path = _create_test_package(script)
230-
script.run(
231-
'git', 'tag', 'test_tag',
232-
expect_stderr=True,
233-
cwd=version_pkg_path,
234-
)
224+
script.run('git', 'tag', 'test_tag', cwd=version_pkg_path)
235225
_change_test_package_version(script, version_pkg_path)
236226
version = _install_version_pkg(script, version_pkg_path, rev='test_tag')
237227
assert '0.1' == version
@@ -241,7 +231,7 @@ def _add_ref(script, path, ref):
241231
"""
242232
Add a new ref to a repository at the given path.
243233
"""
244-
script.run('git', 'update-ref', ref, 'HEAD', expect_stderr=True, cwd=path)
234+
script.run('git', 'update-ref', ref, 'HEAD', cwd=path)
245235

246236

247237
def test_git_install_ref(script):
@@ -253,7 +243,7 @@ def test_git_install_ref(script):
253243
_change_test_package_version(script, version_pkg_path)
254244

255245
version = _install_version_pkg(
256-
script, version_pkg_path, rev='refs/foo/bar', expect_stderr=True,
246+
script, version_pkg_path, rev='refs/foo/bar',
257247
)
258248
assert '0.1' == version
259249

@@ -267,14 +257,12 @@ def test_git_install_then_install_ref(script):
267257
_add_ref(script, version_pkg_path, 'refs/foo/bar')
268258
_change_test_package_version(script, version_pkg_path)
269259

270-
version = _install_version_pkg(
271-
script, version_pkg_path, expect_stderr=True,
272-
)
260+
version = _install_version_pkg(script, version_pkg_path)
273261
assert 'some different version' == version
274262

275263
# Now install the ref.
276264
version = _install_version_pkg(
277-
script, version_pkg_path, rev='refs/foo/bar', expect_stderr=True,
265+
script, version_pkg_path, rev='refs/foo/bar',
278266
)
279267
assert '0.1' == version
280268

@@ -286,14 +274,13 @@ def test_git_with_tag_name_and_update(script, tmpdir):
286274
"""
287275
url_path = 'pypa/pip-test-package.git'
288276
local_url = _github_checkout(url_path, tmpdir, egg='pip-test-package')
289-
result = script.pip('install', '-e', local_url, expect_error=True)
277+
result = script.pip('install', '-e', local_url)
290278
result.assert_installed('pip-test-package', with_files=['.git'])
291279

292280
new_local_url = _github_checkout(url_path, tmpdir)
293281
new_local_url += '@0.1.2#egg=pip-test-package'
294282
result = script.pip(
295283
'install', '--global-option=--version', '-e', new_local_url,
296-
expect_error=True,
297284
)
298285
assert '0.1.2' in result.stdout
299286

@@ -306,7 +293,7 @@ def test_git_branch_should_not_be_changed(script, tmpdir):
306293
"""
307294
url_path = 'pypa/pip-test-package.git'
308295
local_url = _github_checkout(url_path, tmpdir, egg='pip-test-package')
309-
script.pip('install', '-e', local_url, expect_error=True)
296+
script.pip('install', '-e', local_url)
310297
branch = _get_editable_branch(script, 'pip-test-package')
311298
assert 'master' == branch
312299

@@ -316,11 +303,11 @@ def test_git_with_non_editable_unpacking(script, tmpdir):
316303
"""
317304
Test cloning a git repository from a non-editable URL with a given tag.
318305
"""
319-
url_path = 'pypa/[email protected]#egg=pip-test-package'
320-
local_url = _github_checkout(url_path, tmpdir)
321-
result = script.pip(
322-
'install', '--global-option=--version', local_url, expect_error=True,
306+
url_path = 'pypa/pip-test-package.git'
307+
local_url = _github_checkout(
308+
url_path, tmpdir, rev='0.1.2', egg='pip-test-package',
323309
)
310+
result = script.pip('install', '--global-option=--version', local_url)
324311
assert '0.1.2' in result.stdout
325312

326313

@@ -388,13 +375,8 @@ def test_editable__branch_with_sha_same_as_default(script):
388375
"""
389376
version_pkg_path = _create_test_package(script)
390377
# Create a second branch with the same SHA.
391-
script.run(
392-
'git', 'branch', 'develop', expect_stderr=True,
393-
cwd=version_pkg_path,
394-
)
395-
_install_version_pkg_only(
396-
script, version_pkg_path, rev='develop', expect_stderr=True
397-
)
378+
script.run('git', 'branch', 'develop', cwd=version_pkg_path)
379+
_install_version_pkg_only(script, version_pkg_path, rev='develop')
398380

399381
branch = _get_editable_branch(script, 'version-pkg')
400382
assert branch == 'develop'
@@ -410,16 +392,11 @@ def test_editable__branch_with_sha_different_from_default(script):
410392
"""
411393
version_pkg_path = _create_test_package(script)
412394
# Create a second branch.
413-
script.run(
414-
'git', 'branch', 'develop', expect_stderr=True,
415-
cwd=version_pkg_path,
416-
)
395+
script.run('git', 'branch', 'develop', cwd=version_pkg_path)
417396
# Add another commit to the master branch to give it a different sha.
418397
_change_test_package_version(script, version_pkg_path)
419398

420-
version = _install_version_pkg(
421-
script, version_pkg_path, rev='develop', expect_stderr=True
422-
)
399+
version = _install_version_pkg(script, version_pkg_path, rev='develop')
423400
assert version == '0.1'
424401

425402
branch = _get_editable_branch(script, 'version-pkg')
@@ -437,10 +414,7 @@ def test_editable__non_master_default_branch(script):
437414
version_pkg_path = _create_test_package(script)
438415
# Change the default branch of the remote repo to a name that is
439416
# alphabetically after "master".
440-
script.run(
441-
'git', 'checkout', '-b', 'release', expect_stderr=True,
442-
cwd=version_pkg_path,
443-
)
417+
script.run('git', 'checkout', '-b', 'release', cwd=version_pkg_path)
444418
_install_version_pkg_only(script, version_pkg_path)
445419

446420
branch = _get_editable_branch(script, 'version-pkg')
@@ -492,7 +466,6 @@ def test_check_submodule_addition(script):
492466
update_result = script.pip(
493467
'install', '-e', 'git+' + module_path + '#egg=version_pkg',
494468
'--upgrade',
495-
expect_error=True,
496469
)
497470

498471
assert (

tests/functional/test_vcs_git.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def get_head_sha(script, dest):
1919

2020

2121
def checkout_ref(script, repo_dir, ref):
22-
script.run('git', 'checkout', ref, cwd=repo_dir, expect_stderr=True)
22+
script.run('git', 'checkout', ref, cwd=repo_dir)
2323

2424

2525
def checkout_new_branch(script, repo_dir, branch):
2626
script.run(
27-
'git', 'checkout', '-b', branch, cwd=repo_dir, expect_stderr=True,
27+
'git', 'checkout', '-b', branch, cwd=repo_dir,
2828
)
2929

3030

@@ -87,7 +87,7 @@ def test_get_remote_url(script, tmpdir):
8787
do_commit(script, source_dir)
8888

8989
repo_dir = str(tmpdir / 'repo')
90-
script.run('git', 'clone', source_url, repo_dir, expect_stderr=True)
90+
script.run('git', 'clone', source_url, repo_dir)
9191

9292
remote_url = Git.get_remote_url(repo_dir)
9393
assert remote_url == source_url

tests/lib/__init__.py

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
from contextlib import contextmanager
4+
from textwrap import dedent
45
import os
56
import sys
67
import re
@@ -263,6 +264,17 @@ def assert_installed(self, pkg_name, editable=True, with_files=[],
263264
)
264265

265266

267+
def make_check_stderr_message(stderr, line, reason):
268+
"""
269+
Create an exception message to use inside check_stderr().
270+
"""
271+
return dedent("""\
272+
{reason}:
273+
Caused by line: {line!r}
274+
Complete stderr: {stderr}
275+
""").format(stderr=stderr, line=line, reason=reason)
276+
277+
266278
def check_stderr(
267279
stderr, allow_stderr_warning=None, allow_stderr_error=None,
268280
):
@@ -293,22 +305,34 @@ def check_stderr(
293305

294306
lines = stderr.splitlines()
295307
for line in lines:
308+
# First check for logging errors which are sent directly to stderr
309+
# and so bypass any configured log formatter. The
310+
# "--- Logging error ---" string is used in Python 3.4+, and
311+
# "Logged from file " is used in Python 2.
312+
if (line.startswith('--- Logging error ---') or
313+
line.startswith('Logged from file ')):
314+
reason = 'stderr has a logging error, which is never allowed'
315+
msg = make_check_stderr_message(stderr, line=line, reason=reason)
316+
raise RuntimeError(msg)
317+
296318
if line.startswith('ERROR: '):
297-
raise RuntimeError(
319+
reason = (
298320
'stderr has an unexpected error '
299-
'(pass allow_stderr_error=True to permit this): {}'
300-
.format(line)
321+
'(pass allow_stderr_error=True to permit this)'
301322
)
323+
msg = make_check_stderr_message(stderr, line=line, reason=reason)
324+
raise RuntimeError(msg)
302325
if allow_stderr_warning:
303326
continue
304327

305328
if (line.startswith('WARNING: ') or
306329
line.startswith(DEPRECATION_MSG_PREFIX)):
307-
raise RuntimeError(
330+
reason = (
308331
'stderr has an unexpected warning '
309-
'(pass allow_stderr_warning=True to permit this): {}'
310-
.format(line)
332+
'(pass allow_stderr_warning=True to permit this)'
311333
)
334+
msg = make_check_stderr_message(stderr, line=line, reason=reason)
335+
raise RuntimeError(msg)
312336

313337

314338
class PipTestEnvironment(TestFileEnvironment):

tests/lib/test_lib.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def assert_error_startswith(exc_type, expected_start):
2020
with pytest.raises(exc_type) as err:
2121
yield
2222

23-
assert str(err.value).startswith(expected_start)
23+
assert str(err.value).startswith(expected_start), (
24+
'full message: {}'.format(err.value)
25+
)
2426

2527

2628
def test_tmp_dir_exists_in_env(script):
@@ -78,6 +80,18 @@ def test_as_import(script):
7880

7981
class TestPipTestEnvironment:
8082

83+
def run_with_log_command(self, script, sub_string):
84+
"""
85+
Call run() on a command that logs a "%"-style format string using
86+
the given substring as the string's replacement field.
87+
"""
88+
command = (
89+
"import logging; logging.basicConfig(level='INFO'); "
90+
"logging.getLogger().info('sub: {}', 'foo')"
91+
).format(sub_string)
92+
args = [sys.executable, '-c', command]
93+
script.run(*args)
94+
8195
def run_stderr_with_prefix(self, script, prefix, **kwargs):
8296
"""
8397
Call run() that prints stderr with the given prefix.
@@ -139,6 +153,18 @@ def test_run__unexpected_stderr(self, script, prefix, expected_start):
139153
with assert_error_startswith(RuntimeError, expected_start):
140154
self.run_stderr_with_prefix(script, prefix)
141155

156+
def test_run__logging_error(self, script):
157+
"""
158+
Test calling run() with an unexpected logging error.
159+
"""
160+
# Pass a good substitution string.
161+
self.run_with_log_command(script, sub_string='%r')
162+
163+
expected_start = 'stderr has a logging error, which is never allowed'
164+
with assert_error_startswith(RuntimeError, expected_start):
165+
# Pass a bad substitution string.
166+
self.run_with_log_command(script, sub_string='{!r}')
167+
142168
def test_run__allow_stderr_error_false_error_with_expect_error(
143169
self, script,
144170
):

0 commit comments

Comments
 (0)