Merge pull request #6538 from cjerdonek/issue-6513-freeze-requirement-error

Include more details in a pip freeze warning message
This commit is contained in:
Chris Jerdonek 2019-05-25 11:17:23 -07:00 committed by GitHub
commit 98a77a9317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

2
news/6513.bugfix Normal file
View File

@ -0,0 +1,2 @@
Include more details in the log message if ``pip freeze`` can't generate a
requirement string for a particular distribution.

View File

@ -60,10 +60,14 @@ def freeze(
user_only=user_only):
try:
req = FrozenRequirement.from_dist(dist)
except RequirementParseError:
except RequirementParseError as exc:
# We include dist rather than dist.project_name because the
# dist string includes more information, like the version and
# location. We also include the exception message to aid
# troubleshooting.
logger.warning(
"Could not parse requirement: %s",
dist.project_name
'Could not generate requirement for distribution %r: %s',
dist, exc
)
continue
if exclude_editable and req.editable:

View File

@ -108,12 +108,19 @@ def test_freeze_with_invalid_names(script):
'...{}==1.0...'.format(pkgname.replace('_', '-'))
)
for pkgname in invalid_pkgnames:
_check_output(
result.stderr,
'...Could not parse requirement: {}\n...'.format(
pkgname.replace('_', '-')
)
# Check that the full distribution repr is present.
dist_repr = '{} 1.0 ('.format(pkgname.replace('_', '-'))
expected = (
'...Could not generate requirement for '
'distribution {}...'.format(dist_repr)
)
_check_output(result.stderr, expected)
# Also check that the parse error details occur at least once.
# We only need to find one occurrence to know that exception details
# are logged.
expected = '...site-packages): Parse error at "...'
_check_output(result.stderr, expected)
@pytest.mark.git