Skip to content

Commit 1a33c69

Browse files
aabmassherin049xrmx
authored
Remove importlib-metadata dependency (open-telemetry#5203)
* Remove importlib-metadata dependency 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 * Refactor importlib.metadata caching wrapper to address PR comments - 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 * Apply suggestion from @herin049 Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com> * Add Sphinx RST module docstring to _importlib_metadata.py Assisted-by: Gemini * Undo rename of _original_entry_points_cached and document test behavior - 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 --------- Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com> Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
1 parent 4a85110 commit 1a33c69

26 files changed

Lines changed: 135 additions & 155 deletions

File tree

.changelog/3234.removed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`opentelemetry-api`: remove third-party importlib-metadata in favor of standard library since Python >= 3.10 is now required
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
importlib-metadata==6.11.0
21
iniconfig==2.0.0
32
packaging==24.0
43
pluggy==1.5.0
54
protobuf==6.31.1
65
pytest==7.4.4
76
tomli==2.0.1
87
typing_extensions==4.12.0
9-
zipp==3.19.2
108
grpcio==1.78.0
119
grpcio-tools==1.78.0
1210
-e codegen/opentelemetry-codegen-json

docs/getting_started/tests/requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ charset-normalizer==2.0.12
55
click==8.1.7
66
Flask==2.3.3
77
idna==3.7
8-
importlib-metadata==6.8.0
98
iniconfig==2.0.0
109
itsdangerous==2.1.2
1110
Jinja2==3.1.5
@@ -20,7 +19,6 @@ typing_extensions==4.12.0
2019
urllib3==1.26.19
2120
Werkzeug==3.0.6
2221
wrapt==1.15.0
23-
zipp==3.19.2
2422
-e opentelemetry-semantic-conventions
2523
-e opentelemetry-proto
2624
-e exporter/opentelemetry-exporter-otlp-proto-common

exporter/opentelemetry-exporter-opencensus/test-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
asgiref==3.7.2
22
grpcio==1.75.1
3-
importlib-metadata==6.11.0
43
iniconfig==2.0.0
54
opencensus-proto==0.1.0
65
packaging==24.0
@@ -11,7 +10,6 @@ pytest==7.4.4
1110
tomli==2.0.1
1211
typing_extensions==4.12.0
1312
wrapt==1.16.0
14-
zipp==3.19.2
1513
-e opentelemetry-api
1614
-e opentelemetry-sdk
1715
-e tests/opentelemetry-test-utils

exporter/opentelemetry-exporter-otlp-json-common/test-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
asgiref==3.7.2
2-
importlib-metadata==6.11.0
32
iniconfig==2.0.0
43
packaging==24.0
54
pluggy==1.6.0
@@ -9,7 +8,6 @@ pytest==7.4.4
98
tomli==2.0.1
109
typing_extensions==4.12.0
1110
wrapt==1.16.0
12-
zipp==3.19.2
1311
-e opentelemetry-api
1412
-e opentelemetry-sdk
1513
-e opentelemetry-semantic-conventions

exporter/opentelemetry-exporter-otlp-proto-common/test-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
asgiref==3.7.2
2-
importlib-metadata==6.11.0
32
iniconfig==2.0.0
43
packaging==24.0
54
pluggy==1.6.0
@@ -9,7 +8,6 @@ pytest==7.4.4
98
tomli==2.0.1
109
typing_extensions==4.12.0
1110
wrapt==1.16.0
12-
zipp==3.19.2
1311
-e opentelemetry-api
1412
-e opentelemetry-sdk
1513
-e opentelemetry-semantic-conventions

exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.latest.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ asgiref==3.7.2
3333
# via
3434
# -c dev-requirements.txt
3535
# opentelemetry-test-utils
36+
certifi==2026.4.22
37+
# via requests
38+
charset-normalizer==3.4.7
39+
# via requests
3640
colorama==0.4.6
3741
# via
3842
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
@@ -43,8 +47,8 @@ googleapis-common-protos==1.74.0
4347
# via opentelemetry-exporter-otlp-proto-grpc
4448
grpcio==1.80.0
4549
# via opentelemetry-exporter-otlp-proto-grpc
46-
importlib-metadata==8.7.1
47-
# via opentelemetry-api
50+
idna==3.14
51+
# via requests
4852
iniconfig==2.3.0
4953
# via
5054
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
@@ -66,6 +70,10 @@ pytest==7.4.4
6670
# via
6771
# -c dev-requirements.txt
6872
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
73+
requests==2.32.3
74+
# via
75+
# -c dev-requirements.txt
76+
# opentelemetry-test-utils
6977
tomli==2.4.1 ; python_full_version < '3.11'
7078
# via pytest
7179
typing-extensions==4.15.0
@@ -77,5 +85,5 @@ typing-extensions==4.15.0
7785
# opentelemetry-exporter-otlp-proto-grpc
7886
# opentelemetry-sdk
7987
# opentelemetry-semantic-conventions
80-
zipp==3.23.0
81-
# via importlib-metadata
88+
urllib3==2.7.0
89+
# via requests

exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.oldest.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ asgiref==3.7.2
3333
# via
3434
# -c dev-requirements.txt
3535
# opentelemetry-test-utils
36+
certifi==2017.4.17
37+
# via requests
38+
charset-normalizer==2.0.0
39+
# via requests
3640
colorama==0.4.6
3741
# via
3842
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
@@ -47,8 +51,8 @@ grpcio==1.66.2 ; python_full_version == '3.13.*'
4751
# via opentelemetry-exporter-otlp-proto-grpc
4852
grpcio==1.75.1 ; python_full_version >= '3.14'
4953
# via opentelemetry-exporter-otlp-proto-grpc
50-
importlib-metadata==6.0.0
51-
# via opentelemetry-api
54+
idna==2.5
55+
# via requests
5256
iniconfig==2.0.0
5357
# via
5458
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
@@ -70,6 +74,10 @@ pytest==7.4.4
7074
# via
7175
# -c dev-requirements.txt
7276
# -r exporter/opentelemetry-exporter-otlp-proto-grpc/test-requirements.in
77+
requests==2.32.3
78+
# via
79+
# -c dev-requirements.txt
80+
# opentelemetry-test-utils
7381
tomli==1.0.0 ; python_full_version < '3.11'
7482
# via pytest
7583
typing-extensions==4.6.0 ; python_full_version < '3.14'
@@ -86,5 +94,5 @@ typing-extensions==4.12.0 ; python_full_version >= '3.14'
8694
# opentelemetry-exporter-otlp-proto-grpc
8795
# opentelemetry-sdk
8896
# opentelemetry-semantic-conventions
89-
zipp==0.5.0
90-
# via importlib-metadata
97+
urllib3==1.21.1
98+
# via requests

exporter/opentelemetry-exporter-otlp-proto-http/test-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ certifi==2024.7.4
33
charset-normalizer==3.3.2
44
googleapis-common-protos==1.70.0
55
idna==3.7
6-
importlib-metadata==6.11.0
76
iniconfig==2.0.0
87
packaging==24.0
98
pluggy==1.6.0
@@ -17,7 +16,6 @@ tomli==2.0.1
1716
typing_extensions==4.12.0
1817
urllib3==2.2.2
1918
wrapt==1.16.0
20-
zipp==3.19.2
2119
-e opentelemetry-api
2220
-e tests/opentelemetry-test-utils
2321
-e exporter/opentelemetry-exporter-otlp-proto-common

exporter/opentelemetry-exporter-otlp/test-requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
asgiref==3.7.2
2-
importlib-metadata==6.11.0
32
iniconfig==2.0.0
43
packaging==24.0
54
pluggy==1.6.0
@@ -8,7 +7,6 @@ pytest==7.4.4
87
tomli==2.0.1
98
typing_extensions==4.12.0
109
wrapt==1.16.0
11-
zipp==3.19.2
1210
-e opentelemetry-api
1311
-e tests/opentelemetry-test-utils
1412
-e exporter/opentelemetry-exporter-otlp-proto-common

0 commit comments

Comments
 (0)