Conversation
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
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 last uses of the deprecated
pkg_resourcesfrom the backend, replacing them withimportlib.metadatafrom 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 likekitconcept.core.testing). Now usesimportlib.metadata.version()/PackageNotFoundError.kitconcept/core/tools/migration.py— carried a near-duplicatepackage_version(). Removed; it now imports the shared helper.Why
pkg_resourcesis deprecated (and a notably slow import).importlib.metadatais 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 raisedDistributionNotFoundif 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@systemendpoint rather than a traceback. That seemed like the better behavior for a diagnostics endpoint; happy to make it loud again if you disagree.Testing
test_coreVersionsexercises every distribution lookup and asserts exact values forZopeandCMFPlone, which confirms the name normalization works.make formatandmake lintclean (pylama 10/10).Issue
https://gitlab.kitconcept.io/kitconcept/distribution-kitconcept-intranet/-/issues/502