Skip to content

Commit

Permalink
Replace pkg_resources with importlib.metadata
Browse files Browse the repository at this point in the history
It's been deprecated for quite a while. Additionally, it's coming
from an undeclared runtime dependency of `setuptools`.
  • Loading branch information
webknjaz committed Aug 14, 2024
1 parent 43a3d4a commit e12ba1a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
7 changes: 3 additions & 4 deletions awx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import warnings
from importlib.metadata import PackageNotFoundError, version as _get_version


def get_version():
Expand Down Expand Up @@ -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__']
Expand Down
4 changes: 2 additions & 2 deletions awx/main/db/profiled_pg/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -70,7 +70,7 @@ def write(self, query):
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 ('
Expand Down
7 changes: 5 additions & 2 deletions awx/main/models/credential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -52,7 +52,10 @@
__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.credential_plugins'))
credential_plugins = {
entry_point.name: entry_point.load()
for entry_point in entry_points(group='awx.credential_plugins')
}

HIDDEN_PASSWORD = '**********'

Expand Down
5 changes: 2 additions & 3 deletions awx/main/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import contextlib
import tempfile
import functools
from importlib.metadata import version as _get_version

# Django
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
Expand Down Expand Up @@ -222,9 +223,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__

Expand Down
4 changes: 2 additions & 2 deletions awxkit/awxkit/cli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import logging
import os
import pkg_resources
import sys
from importlib.metadata import version as _get_version

from requests.exceptions import RequestException

Expand All @@ -16,7 +16,7 @@
from awxkit.awx.utils import uses_sessions # noqa


__version__ = pkg_resources.get_distribution('awxkit').version
__version__ = _get_version('awxkit')


class CLI(object):
Expand Down
1 change: 0 additions & 1 deletion docs/docsite/rst/rest_api/_swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os

import jinja2
import pkg_resources
import yaml

from sphinx.util.osutil import copyfile, ensuredir
Expand Down
5 changes: 2 additions & 3 deletions tools/scripts/firehose.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import itertools
import json
import multiprocessing
import pkg_resources
import random
import site
import subprocess
import sys
from io import StringIO
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e12ba1a

Please sign in to comment.