Stop importing packaging in the distro; vendor a dependency-free replacement - #53
Merged
Conversation
…acement The injector bootstrap script (sitecustomize.py) used packaging.Requirement and packaging.Version for its dependency-conflict check, making the distro's own code depend on packaging being importable in the injected process. Vendor the small PEP 440/508 implementation from opentelemetry.instrumentation._packaging (open-telemetry/opentelemetry-python-contrib#4883) as dash0.opentelemetry.injector._packaging and import Requirement/Version from there instead. The copy is verbatim except for rewritten internal import paths. TO BE REMOVED: once the same local implementation is available in opentelemetry-instrumentation (i.e. it ships _packaging in a release this distribution pins), delete the vendored package and its tests and repoint the imports in sitecustomize.py and the tests to opentelemetry.instrumentation._packaging. The note is recorded in the vendored _packaging/__init__.py and at the sitecustomize.py import site. sitecustomize.py uses SpecifierSet.contains() rather than the `in` operator, matching upstream, since the vendored specifiers deliberately do not implement __contains__. The two tests that imported packaging (test_sitecustomize.py, test_instrumentations.py) now import from the vendored module; the vendored upstream tests are included. The vendored code and its tests are excluded from ruff, as with the other vendored packages. The packaging == 26.2 pin in pyproject.toml stays: packaging is still pulled in transitively via opentelemetry-instrumentation, so check_pinned_dependencies still requires it declared. It can be removed once that transitive dependency is gone. Bump the distro version 0.3.1 -> 0.3.2 (packaged files changed). Refs #48
ocelotl
force-pushed
the
issue_48_remove_packaging
branch
from
August 5, 2026 21:47
ca43e50 to
44aa8a9
Compare
mmanciop
approved these changes
Aug 6, 2026
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.
What
Removes the distribution's own runtime use of
packaging. The injector bootstrap script (sitecustomize.py) usedpackaging.Requirement/packaging.Versionfor its dependency-conflict check, which made the distro's own code depend onpackagingbeing importable in the injected process.Following the approach in open-telemetry/opentelemetry-python-contrib#4883, this vendors that PR's small PEP 440/508 implementation into the distro at
dash0.opentelemetry.injector._packagingand importsRequirement/Versionfrom there instead. The copy is verbatim except for rewritten internal import paths.This vendored copy is to be removed once the same local implementation is added to
opentelemetry-instrumentation. Vendoring (rather than importingopentelemetry.instrumentation._packagingdirectly) is deliberate: the upstream removal (contrib #4883) is not guaranteed to land. Onceopentelemetry-instrumentationships_packagingin a release this distribution pins, delete the vendored package together with itstests/test_packaging_*.pyand repoint the imports insitecustomize.py(and the tests) toopentelemetry.instrumentation._packaging.This note is recorded in-code in
dash0/opentelemetry/injector/_packaging/__init__.pyand at thesitecustomize.pyimport site.Notes
sitecustomize.pyusesSpecifierSet.contains()rather than theinoperator, matching upstream — the vendored specifiers deliberately do not implement__contains__.packaging(test_sitecustomize.py,test_instrumentations.py) now import from the vendored module; the upstreamtest_packaging_*tests are included. The vendored code and its tests are excluded from ruff, as with the other vendored packages.packaging == 26.2pin inpyproject.tomland theverify_pyproto.pyallowlist stay:packagingis still pulled in transitively viaopentelemetry-instrumentation, socheck_pinned_dependenciesstill requires it declared. Both can be removed once that transitive dependency is gone (contrib #4883 + #4884-4887 and a distro version bump).0.3.1→0.3.2(packaged files changed).Refs #48