Skip to content

Stop importing packaging in the distro; vendor a dependency-free replacement - #53

Merged
mmanciop merged 1 commit into
mainfrom
issue_48_remove_packaging
Aug 6, 2026
Merged

Stop importing packaging in the distro; vendor a dependency-free replacement#53
mmanciop merged 1 commit into
mainfrom
issue_48_remove_packaging

Conversation

@ocelotl

@ocelotl ocelotl commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What

Removes the distribution's own runtime use of packaging. The injector bootstrap script (sitecustomize.py) used packaging.Requirement/packaging.Version for its dependency-conflict check, which made the distro's own code depend on packaging being 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._packaging and imports Requirement/Version from there instead. The copy is verbatim except for rewritten internal import paths.

⚠️ Temporary — to be removed

This vendored copy is to be removed once the same local implementation is added to opentelemetry-instrumentation. Vendoring (rather than importing opentelemetry.instrumentation._packaging directly) is deliberate: the upstream removal (contrib #4883) is not guaranteed to land. Once opentelemetry-instrumentation ships _packaging in a release this distribution pins, delete the vendored package together with its tests/test_packaging_*.py and repoint the imports in sitecustomize.py (and the tests) to opentelemetry.instrumentation._packaging.

This note is recorded in-code in dash0/opentelemetry/injector/_packaging/__init__.py and at the sitecustomize.py import site.

Notes

  • sitecustomize.py uses SpecifierSet.contains() rather than the in operator, matching upstream — 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 upstream test_packaging_* 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 and the verify_pyproto.py allowlist stay: packaging is still pulled in transitively via opentelemetry-instrumentation, so check_pinned_dependencies still requires it declared. Both can be removed once that transitive dependency is gone (contrib #4883 + #4884-4887 and a distro version bump).
  • Distro version bumped 0.3.10.3.2 (packaged files changed).

Refs #48

@ocelotl
ocelotl requested a review from a team as a code owner August 5, 2026 21:27
…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
ocelotl force-pushed the issue_48_remove_packaging branch from ca43e50 to 44aa8a9 Compare August 5, 2026 21:47
@mmanciop
mmanciop merged commit 0a3e613 into main Aug 6, 2026
10 checks passed
@mmanciop
mmanciop deleted the issue_48_remove_packaging branch August 6, 2026 06:36
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.

2 participants