Remove importlib-metadata dependency#5203
Merged
Merged
Conversation
xrmx
reviewed
May 13, 2026
herin049
reviewed
May 13, 2026
Remove the third-party importlib-metadata dependency in favor of the standard library's importlib.metadata, which is stable and available natively since Python >= 3.10. Implements a unified, branchless caching wrapper in `opentelemetry-api` that: - Bypasses standard `entry_points()` version-specific return type differences (SelectableGroups vs EntryPoints) by building a flat `EntryPoints` sequence directly from the low-level `distributions()` API. - Caches all resolved entry points in-memory on the first call to avoid severe startup performance degradation caused by repeated filesystem scans in standard library `importlib.metadata` (resulting in a 37x speedup on subsequent lookups and a 2x faster cold start). - Cleans up obsolete `importlib-metadata` and `zipp` requirements across 19 test and documentation configurations. Assisted-by: Gemini
a95351b to
d81c1ba
Compare
- Leverage stdlib `entry_points()` directly instead of the custom `distributions()` loop, ensuring standard library's `sys.path` shadowing resolution (uniqueness filtering) is perfectly preserved. - Map Python 3.10/3.11 `SelectableGroups` (dict-like object) to `EntryPoints` (sequence) using a compatibility helper `_as_entry_points`. - Cache the result of the no-argument stdlib `entry_points()` call via `@cache` to eliminate redundant disk-scanning on repeated lookups. - Add a compatibility unit test for `_as_entry_points` with dict-like input. Assisted-by: Gemini
herin049
approved these changes
May 13, 2026
herin049
reviewed
May 13, 2026
d81c1ba to
b4a11e4
Compare
Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com>
Assisted-by: Gemini
cdf7821 to
9fce4d5
Compare
- Revert the caching function name back to _original_entry_points_cached to avoid unnecessary churn. - Add a docstring to test_as_entry_points_selectable_groups_compat explaining the normalization of Python 3.10 SelectableGroups vs 3.11+. Assisted-by: Gemini
9fce4d5 to
6aca7fb
Compare
This was referenced May 13, 2026
Member
Author
|
Would like an approval from another maintainer and then we can merge |
6 tasks
xrmx
approved these changes
May 14, 2026
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3234
Remove the importlib-metadata dependency in favor of the standard library's
importlib.metadata. Since Python >= 3.10 is now required (#5076),importlib.metadatais stable enough and available across all supported versions.Adds a compatibility wrapper in
opentelemetry-apifor Python < 3.12 to handle entry point loading differences when called with no arguments (SelectableGroups vs EntryPoints), avoiding DeprecationWarning and ensuring uniform behavior.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: