Skip to content

Migrate from pkg_resources#372

Merged
rcritten merged 1 commit intofreeipa:masterfrom
rcritten:issue_273
Jan 5, 2026
Merged

Migrate from pkg_resources#372
rcritten merged 1 commit intofreeipa:masterfrom
rcritten:issue_273

Conversation

@rcritten
Copy link
Collaborator

@rcritten rcritten commented Sep 17, 2025

The usage of pkg_resources (subpackage of setuptools distribution) is discouraged.

https://setuptools.pypa.io/en/latest/pkg_resources.html:

Use of pkg_resources is discouraged in favor of importlib.resources,
importlib.metadata, and their backports (importlib_resources,
importlib_metadata). Please consider using those libraries instead
of pkg_resources.

freeipa-healthcheck uses several points of pkg_resources:

Compatibility note: importlib.metadata is in stdlib since Python 3.8: https://docs.python.org/3/library/importlib.metadata.html

Fixes: #273

Summary by Sourcery

Migrate the project from pkg_resources to importlib.metadata (and its backport) and update setup configuration accordingly

Enhancements:

  • Replace pkg_resources.iter_entry_points and get_distribution calls with importlib.metadata.entry_points and version functions
  • Remove pkg_resources namespace package declarations
  • Simplify entry point loading by using importlib_metadata.load()

Build:

  • Add importlib-metadata dependency for Python versions earlier than 3.8
  • Update python_requires to >=3.6 and extend supported Python classifiers through 3.11

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/ipahealthcheck/core/core.py:35-40` </location>
<code_context>
def find_registries(entry_points):
    # Loading the resources may reset the log level, save it.
    log_level = logger.level
    registries = {}
    for entry_point in entry_points:
        registries.update({
            ep.name: ep.load()
            for ep in importlib_metadata.entry_points().select(
                group=entry_point
            )
        })
    logger.setLevel(log_level)
    return registries

</code_context>

<issue_to_address>
**issue (code-quality):** Merge dictionary updates via the union operator ([`dict-assign-update-to-union`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/dict-assign-update-to-union/))
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 35 to 40
registries.update({
ep.name: ep.resolve()
for ep in pkg_resources.iter_entry_points(entry_point)
ep.name: ep.load()
for ep in importlib_metadata.entry_points().select(
group=entry_point
)
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Merge dictionary updates via the union operator (dict-assign-update-to-union)

# Copyright (C) 2019 FreeIPA Contributors see COPYING for license
#

__import__('pkg_resources').declare_namespace(__name__)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that those are namespace packages, have you considered removing the __init__.py files following PEP 420 – Implicit Namespace Packages available since Python 3.3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped both instances of a namespace init.py, thanks.

@rcritten rcritten force-pushed the issue_273 branch 2 times, most recently from aa45267 to 144d24d Compare October 2, 2025 19:54
The usage of pkg_resources (subpackage of setuptools distribution)
is discouraged.

https://setuptools.pypa.io/en/latest/pkg_resources.html:

  Use of pkg_resources is discouraged in favor of importlib.resources,
  importlib.metadata, and their backports (importlib_resources,
  importlib_metadata). Please consider using those libraries instead
  of pkg_resources.

freeipa-healthcheck uses several points of pkg_resources:

 * pkg_resources.iter_entry_points to access entry points.
   migration: https://importlib-metadata.readthedocs.io/en/latest/migration.html#pkg-resources-iter-entry-points
 * pkg_resources.get_distribution to access a distribution.
   migration: https://importlib-metadata.readthedocs.io/en/latest/migration.html#pkg-resources-get-distribution
 * __import__('pkg_resources').declare_namespace
   https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#creating-a-namespace-package

Compatibility note: importlib.metadata is in stdlib since Python 3.8:
https://docs.python.org/3/library/importlib.metadata.html

Fixes: freeipa#273

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
@rcritten rcritten merged commit f3e7a9f into freeipa:master Jan 5, 2026
8 checks passed
@rcritten
Copy link
Collaborator Author

rcritten commented Jan 5, 2026

rawhide build with this patch created, freeipa-healthcheck-0.19-3.fc44

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.

Migrate from pkg_resources

2 participants