Skip to content

Commit

Permalink
Stop using pkg_resources
Browse files Browse the repository at this point in the history
This refactors the use of pkg_resource to the more modern
importlib_resources, that is supposed to be superseeded by
importlib.resources eventually.
In the fallout, the dependency on setuptools was dropped.

[noissue]
  • Loading branch information
mdellweg committed Aug 5, 2024
1 parent 734e471 commit 4f65152
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
12 changes: 9 additions & 3 deletions pulpcore/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from importlib import import_module
from logging import getLogger
from pathlib import Path
from pkg_resources import iter_entry_points

from cryptography.fernet import Fernet
from django.core.exceptions import ImproperlyConfigured
Expand All @@ -30,6 +29,13 @@
except ImportError:
pass

if sys.version_info < (3, 10):
# Python 3.9 has a rather different interface for `entry_points`.
# Let's use a compatibility version.
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points

# Build paths inside the project like this: BASE_DIR / ...
BASE_DIR = Path(__file__).absolute().parent

Expand Down Expand Up @@ -93,9 +99,9 @@
# Enumerate the installed Pulp plugins during the loading process for use in the status API
INSTALLED_PULP_PLUGINS = []

for entry_point in iter_entry_points("pulpcore.plugin"):
for entry_point in entry_points(group="pulpcore.plugin"):
plugin_app_config = entry_point.load()
INSTALLED_PULP_PLUGINS.append(entry_point.module_name)
INSTALLED_PULP_PLUGINS.append(entry_point.name)
INSTALLED_APPS.append(plugin_app_config)

# Optional apps that help with development, or augment Pulp in some non-critical way
Expand Down
5 changes: 2 additions & 3 deletions pulpcore/app/tasks/replica.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
import platform
from pkg_resources import get_distribution
import sys
from tempfile import NamedTemporaryFile

from pulpcore.app.apps import pulp_plugin_configs
from pulpcore.app.apps import pulp_plugin_configs, PulpAppConfig
from pulpcore.app.models import UpstreamPulp, TaskGroup
from pulpcore.app.replica import ReplicaContext

Expand All @@ -15,7 +14,7 @@ def user_agent():
"""
Produce a User-Agent string to identify Pulp and relevant system info.
"""
pulp_version = get_distribution("pulpcore").version
pulp_version = PulpAppConfig.version
python = "{} {}.{}.{}-{}{}".format(sys.implementation.name, *sys.version_info)
uname = platform.uname()
system = f"{uname.system} {uname.machine}"
Expand Down
4 changes: 2 additions & 2 deletions pulpcore/download/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from gettext import gettext as _
from multidict import MultiDict
import platform
from pkg_resources import get_distribution
import ssl
import sys
from tempfile import NamedTemporaryFile
from urllib.parse import urlparse

import aiohttp

from pulpcore.app.apps import PulpAppConfig
from .http import HttpDownloader
from .file import FileDownloader

Expand Down Expand Up @@ -80,7 +80,7 @@ def user_agent():
"""
Produce a User-Agent string to identify Pulp and relevant system info.
"""
pulp_version = get_distribution("pulpcore").version
pulp_version = PulpAppConfig.version
python = "{} {}.{}.{}-{}{}".format(sys.implementation.name, *sys.version_info)
uname = platform.uname()
system = f"{uname.system} {uname.machine}"
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pyparsing>=3.1.0,<=3.1.2
python-gnupg>=0.5,<=0.5.2
PyYAML>=5.1.1,<=6.0.1
redis>=4.3,<5.0.8
setuptools>=39.2,<71.2.0
tablib<3.6.0
url-normalize>=1.4.3,<=1.4.3
uuid6>=2023.5.2,<=2024.7.10
Expand Down

0 comments on commit 4f65152

Please sign in to comment.