Skip to content

Remove dependency on pkg_resources - #135

Merged
ericof merged 1 commit into
mainfrom
issue-502
Jul 28, 2026
Merged

Remove dependency on pkg_resources#135
ericof merged 1 commit into
mainfrom
issue-502

Conversation

@ericof

@ericof ericof commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

Removes the last uses of the deprecated pkg_resources from the backend, replacing them with importlib.metadata from the standard library.

Two call sites existed, not one:

  • kitconcept/core/utils/packages.py — the robust helper (empty-name guard, walk-up fallback for sub-packages like kitconcept.core.testing). Now uses importlib.metadata.version() / PackageNotFoundError.
  • kitconcept/core/tools/migration.py — carried a near-duplicate package_version(). Removed; it now imports the shared helper.

Why

pkg_resources is deprecated (and a notably slow import). importlib.metadata is stdlib and normalizes distribution names itself, so the dotted names used here — Products.CMFPlone, Products.CMFCore, plone.restapi, plone.volto, pillow — resolve unchanged.

Behavior change

MigrationTool.coreVersions() previously raised DistributionNotFound if a package was missing. It now inherits the shared helper's fallback and reports - instead. All seven call sites pass real installed distributions, so nothing changes in practice — but a genuinely missing package would surface as - in the @system endpoint rather than a traceback. That seemed like the better behavior for a diagnostics endpoint; happy to make it loud again if you disagree.

Testing

  • Full backend suite: 288 passed.
  • test_coreVersions exercises every distribution lookup and asserts exact values for Zope and CMFPlone, which confirms the name normalization works.
  • make format and make lint clean (pylama 10/10).

Issue

https://gitlab.kitconcept.io/kitconcept/distribution-kitconcept-intranet/-/issues/502

Replace `pkg_resources.get_distribution()` with `importlib.metadata.version()`
in `kitconcept.core.utils.packages`, and drop the near-duplicate
`package_version()` helper from `kitconcept.core.tools.migration` in favour of
the shared one.

`pkg_resources` is deprecated and slow to import; `importlib.metadata` is in the
standard library and handles the dotted distribution names used here
(`Products.CMFPlone`, `plone.restapi`) via its own name normalization.

Note: `MigrationTool.coreVersions()` now inherits the shared helper's fallback,
so an uninstalled package reports `-` instead of raising `DistributionNotFound`.

Refs https://gitlab.kitconcept.io/kitconcept/distribution-kitconcept-intranet/-/issues/502
@ericof
ericof requested a review from fredvd July 28, 2026 07:41
@ericof
ericof merged commit 41f67d9 into main Jul 28, 2026
12 checks passed
@ericof
ericof deleted the issue-502 branch July 28, 2026 08:43
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.

1 participant