summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSviatoslav Sydorenko (Святослав Сидоренко) <wk@sydorenko.org.ua>2024-09-13 19:39:14 +0200
committerGitHub <noreply@github.com>2024-09-13 19:39:14 +0200
commite68370f2aa2dc0fb435de39835beb0edc1c55225 (patch)
tree6a3b7fa8675ae5bf4eda61d2890edf44246ff84e
parent🧪 Upload the `devel` branch coverage to Codecov (#15507) (diff)
downloadawx-e68370f2aa2dc0fb435de39835beb0edc1c55225.tar.xz
awx-e68370f2aa2dc0fb435de39835beb0edc1c55225.zip
Replace `pkg_resources` with `importlib.metadata` (#15441)
-rw-r--r--awx/__init__.py7
-rw-r--r--awx/main/db/profiled_pg/base.py4
-rw-r--r--awx/main/models/credential.py4
-rw-r--r--awx/main/utils/common.py5
-rwxr-xr-xawxkit/awxkit/cli/client.py4
-rw-r--r--docs/docsite/rst/rest_api/_swagger/swagger.py1
-rwxr-xr-xtools/scripts/firehose.py5
7 files changed, 13 insertions, 17 deletions
diff --git a/awx/__init__.py b/awx/__init__.py
index 4a9ddd1c1e..be80b58614 100644
--- a/awx/__init__.py
+++ b/awx/__init__.py
@@ -5,6 +5,7 @@ from __future__ import absolute_import, unicode_literals
import os
import sys
import warnings
+from importlib.metadata import PackageNotFoundError, version as _get_version
def get_version():
@@ -34,10 +35,8 @@ def version_file():
try:
- import pkg_resources
-
- __version__ = pkg_resources.get_distribution('awx').version
-except pkg_resources.DistributionNotFound:
+ __version__ = _get_version('awx')
+except PackageNotFoundError:
__version__ = get_version()
__all__ = ['__version__']
diff --git a/awx/main/db/profiled_pg/base.py b/awx/main/db/profiled_pg/base.py
index 4c50f564b9..da49f290fb 100644
--- a/awx/main/db/profiled_pg/base.py
+++ b/awx/main/db/profiled_pg/base.py
@@ -1,9 +1,9 @@
import os
-import pkg_resources
import sqlite3
import sys
import traceback
import uuid
+from importlib.metadata import version as _get_version
from django.core.cache import cache
from django.core.cache.backends.locmem import LocMemCache
@@ -70,7 +70,7 @@ class RecordedQueryLog(object):
else:
progname = os.path.basename(sys.argv[0])
filepath = os.path.join(self.dest, '{}.sqlite'.format(progname))
- version = pkg_resources.get_distribution('awx').version
+ version = _get_version('awx')
log = sqlite3.connect(filepath, timeout=3)
log.execute(
'CREATE TABLE IF NOT EXISTS queries ('
diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py
index 1d6e4c1501..2f4a56a890 100644
--- a/awx/main/models/credential.py
+++ b/awx/main/models/credential.py
@@ -5,7 +5,7 @@ import functools
import inspect
import logging
import os
-from pkg_resources import iter_entry_points
+from importlib.metadata import entry_points
import re
import stat
import tempfile
@@ -56,7 +56,7 @@ from awx_plugins.credentials import injectors as builtin_injectors
__all__ = ['Credential', 'CredentialType', 'CredentialInputSource', 'build_safe_env']
logger = logging.getLogger('awx.main.models.credential')
-credential_plugins = dict((ep.name, ep.load()) for ep in iter_entry_points('awx_plugins.credentials'))
+credential_plugins = {entry_point.name: entry_point.load() for entry_point in entry_points(group='awx_plugins.credentials')}
HIDDEN_PASSWORD = '**********'
diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py
index f9ba624339..f283b8ec90 100644
--- a/awx/main/utils/common.py
+++ b/awx/main/utils/common.py
@@ -18,6 +18,7 @@ import threading
import contextlib
import tempfile
import functools
+from importlib.metadata import version as _get_version
# Django
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
@@ -230,9 +231,7 @@ def get_awx_version():
from awx import __version__
try:
- import pkg_resources
-
- return pkg_resources.require('awx')[0].version
+ return _get_version('awx')
except Exception:
return __version__
diff --git a/awxkit/awxkit/cli/client.py b/awxkit/awxkit/cli/client.py
index 46dc4fa333..de790e184e 100755
--- a/awxkit/awxkit/cli/client.py
+++ b/awxkit/awxkit/cli/client.py
@@ -2,8 +2,8 @@ from __future__ import print_function
import logging
import os
-import pkg_resources
import sys
+from importlib.metadata import version as _get_version
from requests.exceptions import RequestException
@@ -16,7 +16,7 @@ from awxkit.cli.utils import HelpfulArgumentParser, cprint, disable_color, color
from awxkit.awx.utils import uses_sessions # noqa
-__version__ = pkg_resources.get_distribution('awxkit').version
+__version__ = _get_version('awxkit')
class CLI(object):
diff --git a/docs/docsite/rst/rest_api/_swagger/swagger.py b/docs/docsite/rst/rest_api/_swagger/swagger.py
index 02391be6fb..6f4029fc85 100644
--- a/docs/docsite/rst/rest_api/_swagger/swagger.py
+++ b/docs/docsite/rst/rest_api/_swagger/swagger.py
@@ -3,7 +3,6 @@ import json
import os
import jinja2
-import pkg_resources
import yaml
from sphinx.util.osutil import copyfile, ensuredir
diff --git a/tools/scripts/firehose.py b/tools/scripts/firehose.py
index 4755cdf463..69a1c40ec8 100755
--- a/tools/scripts/firehose.py
+++ b/tools/scripts/firehose.py
@@ -30,8 +30,7 @@ import datetime
import itertools
import json
import multiprocessing
-import pkg_resources
-import random
+import site
import subprocess
import sys
from io import StringIO
@@ -132,7 +131,7 @@ def cleanup(sql):
def generate_jobs(jobs, batch_size, time_delta):
print(f'inserting {jobs} job(s)')
- sys.path.insert(0, pkg_resources.get_distribution('awx').module_path)
+ sys.path[:0] = site.getsitepackages()
from awx import prepare_env
prepare_env()