Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/6513.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Include more details in the log message if ``pip freeze`` can't generate a
requirement string for a particular distribution.
10 changes: 7 additions & 3 deletions src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 12 additions & 5 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,19 @@ def fake_install(pkgname, dest):
'...{}==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
Expand Down