Skip to content

Report invalid distributions in diagnose instead of crashing - #549

Merged
jaraco merged 1 commit into
mainfrom
bugfix/548-diagnose-invalid
Oct 21, 2026
Merged

jaraco merged 1 commit into
mainfrom
bugfix/548-diagnose-invalid

Conversation

@jaraco

@jaraco jaraco commented Oct 21, 2026

Copy link
Copy Markdown
Member

Closes #548.

diagnose.inspect built its report with ', '.join(dist.name for dist in dists). An empty metadata directory (a bare foo-1.0.dist-info left behind by a partial install) is still discovered as a PathDistribution, but it cannot name itself, so the diagnostic died on the very condition it exists to surface.

The failure mode has shifted since #532 but the crash remains:

  • no metadata file at all → MetadataNotFound
  • metadata present without a Name field → KeyError: 'Name' (from _adapters.Message.__getitem__)

Both are now caught by a new describe, which falls back to the location of the distribution's metadata:

Inspecting /Users/jaraco/draft
Found 2 packages: torch, /Users/jaraco/draft/torch-2.2.0.dist-info (no metadata)

_locate reads _path defensively so a non-path provider degrades to its repr rather than raising in turn.

The duplicate-metadata condition from the original python/cpython#100666 discussion is not addressed here; diagnose already survives it (listing the name twice), so flagging it would be a separate enhancement.

Note for downstream: diagnose.py and tests/test_main.py are both shared with CPython, so this needs porting to importlib.metadata.

🤖 Generated with Claude Code

An empty metadata directory is still discovered as a distribution, but
it cannot name itself, so the diagnostic died on the very condition it
exists to surface. Describe such distributions by the location of their
metadata instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jaraco
jaraco merged commit f6c72ab into main Oct 21, 2026
30 of 32 checks passed
@jaraco
jaraco deleted the bugfix/548-diagnose-invalid branch October 21, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnose crashes on empty metadata directory

1 participant