Skip to content

Commit

Permalink
Remove pkg_resources
Browse files Browse the repository at this point in the history
Replaces all uses of pkg_resources with importlib, because the former
has been deprecated.

fixes pulp#865
  • Loading branch information
mdellweg committed Jan 16, 2024
1 parent ab5f324 commit a18d616
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import toml
from git import GitCommandError, Repo
from pkg_resources import parse_version
from packaging.version import parse as parse_version

# Read Towncrier settings
tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/collect_changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
git config user.email pulp-infra@redhat.com
- name: Collect changes
run: |
pip install GitPython toml
pip install GitPython packaging toml
python3 .ci/scripts/collect_changes.py
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
Expand Down
15 changes: 5 additions & 10 deletions pulp-glue/pulp_glue/common/i18n.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import gettext
from functools import lru_cache

import pkg_resources
from importlib.resources import files


# Need to call lru_cache() before using it as a decorator for python 3.7 compatibility
@lru_cache(maxsize=None)
def get_translation(name: str) -> gettext.NullTranslations:
"""
Return a translations object for a certain import path.
Expand All @@ -23,11 +24,5 @@ def get_translation(name: str) -> gettext.NullTranslations:
_ = translation.gettext
```
"""
localedir = pkg_resources.resource_filename(name, "locale")
return _get_translation_for_domain("messages", localedir)


# Need to call lru_cache() before using it as a decorator for python 3.7 compatibility
@lru_cache(maxsize=None)
def _get_translation_for_domain(domain: str, localedir: str) -> gettext.NullTranslations:
return gettext.translation(domain, localedir=localedir, fallback=True)
localedir = files(name) / "locale"
return gettext.translation("messages", localedir=str(localedir), fallback=True)
4 changes: 2 additions & 2 deletions pulp_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from importlib.metadata import entry_points
from types import ModuleType
from typing import Any, Dict, Optional

import click
import pkg_resources

__version__ = "0.23.0.dev"
_main: Optional[click.Group] = None
Expand All @@ -16,7 +16,7 @@ def load_plugins() -> click.Group:
# https://packaging.python.org/guides/creating-and-discovering-plugins/#using-package-metadata
discovered_plugins: Dict[str, ModuleType] = {
entry_point.name: entry_point.load()
for entry_point in pkg_resources.iter_entry_points("pulp_cli.plugins")
for entry_point in entry_points(group="pulp_cli.plugins")
}
_main = discovered_plugins["common"].main
assert isinstance(_main, click.Group)
Expand Down

0 comments on commit a18d616

Please sign in to comment.