Skip to content

Comments

Feature implementation from commits 57b8aa8..5dd80c3#5

Open
yashuatla wants to merge 1603 commits intofeature-base-5from
feature-head-5
Open

Feature implementation from commits 57b8aa8..5dd80c3#5
yashuatla wants to merge 1603 commits intofeature-base-5from
feature-head-5

Conversation

@yashuatla
Copy link
Owner

@yashuatla yashuatla commented Jun 22, 2025

PR Summary

Add Importlib Metadata Package with Comprehensive Documentation and Testing

Overview

This PR introduces the importlib_metadata package with comprehensive functionality for accessing package metadata, compatibility layers for different Python versions, utility classes, and extensive test coverage.

Change Types

Type Description
Feature New importlib_metadata package with metadata access functionality
Docs Sphinx documentation configuration with extlinks and intersphinx mappings
Test Comprehensive test files for API and main functionality

Affected Modules

Module / File Change Description
conf.py Added Sphinx documentation configuration with extlinks and intersphinx mappings
_adapters.py Added Message class extending email.message.Message for package metadata handling
_collections.py Added FreezableDefaultDict and Pair utility classes
_compat.py Added compatibility module with custom distribution finder functionality
compat/py311.py Added compatibility wrapper for pathlib's relative_to method
compat/py39.py Added compatibility layer for Python 3.8/3.9
diagnose.py Added diagnostic tool for inspecting Python package distributions
test_api.py Added comprehensive test cases for package functionality
test_main.py Added test cases for version retrieval, package discovery, and entry points

Notes for Reviewers

  • The package includes compatibility layers for Python 3.8, 3.9, and 3.11
  • Special handling for multiple-use keys according to PEP 566
  • PyPy-specific helper functions are included in the compatibility module

jherland and others added 30 commits March 19, 2023 03:44
The import names that were created by these tests were not valid Python
identifiers.

Fix that, and furthermore: add another check to verify that _all_ import
names returned from packages_distributions() are always valid Python
identifiers. Ideally we should check that all keys returned from
packages_distributions() are valid import names (i.e. can be imported),
but this is at least a step in the right direction.
pep8 states that comments should be limited to 72 characters.
add .get() to the PackageMetadata protocol

Fixes python#384.
…ers.

The main contstraint here for an importable module is that it must not contain a module separator ('.'). Other names that contain dashes or spaces cannot be imported with the 'import' statement, but can be imported with 'importlib.import_module' or invoked with 'runpy'.
Captures new failed expectation and verifies fix.
…port names"

This reverts commit 70ff991.

This behavior was adopted in 5e8260c and subsequently adapted as part of python#443.
…isting files for all the entries in RECORD"

This reverts commit fa9cca4.
…to build the metadata RECORD from the files definition.
Use jaraco.path for generating the record and files
jaraco and others added 28 commits August 19, 2024 15:35
- wallrusify
- add a note about deffered import
Speed up import time by deferring inspect
Re-sync jaraco.path 3.7.1.
…l' comment to delineate where the skeleton ends and the downstream begins.
# Conflicts:
#	docs/conf.py
#	mypy.ini
Update tests/_path.py with jaraco.path 3.7.2
) == '_frozen_importlib_external' and hasattr(finder, 'find_distributions')

for finder in filter(matches, sys.meta_path): # pragma: nocover
del finder.find_distributions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Critical: Monkey-patching Python's import system.

Deleting the find_distributions method from stdlib finders modifies Python's core import system in a way that could break compatibility with other packages.

Current Code (Diff):

-         del finder.find_distributions
+         try:
+             del finder.find_distributions
+         except (AttributeError, TypeError):
+             pass
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
del finder.find_distributions
try:
del finder.find_distributions
except (AttributeError, TypeError):
pass

Comment on lines +15 to +17
sys.meta_path.append(cls())
disable_stdlib_finder()
return cls
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Critical: Unconditional stdlib finder disabling.

The install function unconditionally disables stdlib finders without any fallback mechanism, which could cause system-wide import failures.

Current Code (Diff):

-     sys.meta_path.append(cls())
-     disable_stdlib_finder()
-     return cls
+     sys.meta_path.append(cls())
+     try:
+         disable_stdlib_finder()
+     except Exception:
+         # Log warning but continue - allows package to work even if disabling fails
+         import warnings
+         warnings.warn("Failed to disable stdlib finder, package may not work correctly")
+     return cls
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
sys.meta_path.append(cls())
disable_stdlib_finder()
return cls
sys.meta_path.append(cls())
try:
disable_stdlib_finder()
except Exception:
# Log warning but continue - allows package to work even if disabling fails
import warnings
warnings.warn("Failed to disable stdlib finder, package may not work correctly")
return cls

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.