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 f511aa5
Show file tree
Hide file tree
Showing 71 changed files with 96 additions and 88 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
1 change: 1 addition & 0 deletions CHANGES/865.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove dependency on `pkg_resources` that failed some installations but is deprecated anyway.
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/ansible/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from pulp_glue.common.i18n import get_translation

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/certguard/context.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pulp_glue.common.context import PluginRequirement, PulpContentGuardContext
from pulp_glue.common.i18n import get_translation

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pulp_glue.common.i18n import get_translation
from pulp_glue.common.openapi import OpenAPI, OpenAPIError

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext

DEFAULT_LIMIT = 25
Expand Down
20 changes: 10 additions & 10 deletions pulp-glue/pulp_glue/common/i18n.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import gettext
import sys
from functools import lru_cache

import pkg_resources
if sys.version_info >= (3, 9):
from importlib.resources import files
else:
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 @@ -19,15 +25,9 @@ def get_translation(name: str) -> gettext.NullTranslations:
```
from pulp_glue.common.i18n import get_translation
translation = get_translation(__name__)
translation = get_translation(__package__)
_ = 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)
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/common/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pulp_glue.common import __version__
from pulp_glue.common.i18n import get_translation

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext

UploadType = Union[bytes, IO[bytes]]
Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/container/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from pulp_glue.common.i18n import get_translation

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from pulp_glue.common.i18n import get_translation

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/file/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pulp_glue.common.openapi import OpenAPI
from pulp_glue.core.context import PulpArtifactContext

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/python/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pulp_glue.common.i18n import get_translation
from pulp_glue.common.openapi import OpenAPI

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulp-glue/pulp_glue/rpm/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)
from pulp_glue.common.i18n import get_translation

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
21 changes: 11 additions & 10 deletions pulp-glue/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ authors = [
{name = "Pulp Team", email = "pulp-list@redhat.com"},
]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: System :: Software Distribution",
"Typing :: Typed",
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: System :: Software Distribution",
"Typing :: Typed",
]
dependencies = [
"packaging>=20.0,<24",
"requests>=2.24.0,<2.32",
"packaging>=20.0,<24",
"requests>=2.24.0,<2.32",
"importlib_resources>=5.4,<6.2;python_version<'3.9'",
]

[project.urls]
Expand Down
9 changes: 7 additions & 2 deletions pulp_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import sys
from types import ModuleType
from typing import Any, Dict, Optional

import click
import pkg_resources

if sys.version_info >= (3, 10):
from importlib.metadata import entry_points
else:
from importlib_metadata import entry_points

__version__ = "0.23.0.dev"
_main: Optional[click.Group] = None
Expand All @@ -16,7 +21,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
2 changes: 1 addition & 1 deletion pulpcore/cli/ansible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pulpcore.cli.ansible.repository import repository
from pulpcore.cli.common.generic import pulp_group

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/ansible/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/ansible/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/ansible/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
update_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/ansible/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
)
from pulpcore.cli.core.generic import task_command

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

__version__ = "0.23.0.dev"

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/common/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
update_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pulpcore.cli.common.generic import pulp_group

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext

_T = TypeVar("_T")
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/common/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
pulp_group,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
PYGMENTS = True
PYGMENTS_STYLE = "solarized-dark"

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pulpcore.cli.container.remote import remote
from pulpcore.cli.container.repository import repository

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/container/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/container/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/container/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
update_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/container/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from pulpcore.cli.container.content import show_options
from pulpcore.cli.core.generic import task_command

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext
VALID_TAG_REGEX = r"^[A-Za-z0-9][A-Za-z0-9._-]*$"

Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
update_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pulpcore.cli.common.generic import PulpCLIContext, list_command, pass_pulp_context, pulp_group

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/content_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
update_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
update_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext

pass_export_context = click.make_pass_decorator(PulpExportContext)
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
show_command,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext

pass_exporter_context = click.make_pass_decorator(PulpExporterContext)
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
resource_option,
)

translation = get_translation(__name__)
translation = get_translation(__package__)
_ = translation.gettext


Expand Down
Loading

0 comments on commit f511aa5

Please sign in to comment.