Get rid of pkg_resources

... because it was removed in Python 3.12 [1].

[1] https://docs.python.org/3/whatsnew/3.12.html#ensurepip

Note:
Selectable entry points were introduced in importlib_metadata 3.6 and
Python 3.10 .

Change-Id: I1b478a63ad1d73f9f3528939362797ea1fc68534
This commit is contained in:
Takashi Kajinami 2024-10-03 21:26:30 +09:00
parent a8a9a4b922
commit b7fe561d09
4 changed files with 18 additions and 10 deletions

View File

@ -10,16 +10,21 @@
# License for the specific language governing permissions and limitations
# under the License.
import sys
from oslo_config import cfg
import pkg_resources
from neutron._i18n import _
if sys.version_info < (3, 10, 0):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points
MIGRATION_ENTRYPOINTS = 'neutron.db.alembic_migrations'
migration_entrypoints = {
entrypoint.name: entrypoint
for entrypoint in pkg_resources.iter_entry_points(MIGRATION_ENTRYPOINTS)
for entrypoint in entry_points(group=MIGRATION_ENTRYPOINTS)
}
INSTALLED_SUBPROJECTS = list(migration_entrypoints)

View File

@ -566,13 +566,13 @@ def _get_installed_entrypoint(subproject):
def _get_subproject_script_location(subproject):
'''Get the script location for the installed subproject.'''
entrypoint = _get_installed_entrypoint(subproject)
return ':'.join([entrypoint.module_name, entrypoint.attrs[0]])
return ':'.join([entrypoint.module, entrypoint.attr])
def _get_subproject_base(subproject):
'''Get the import base name for the installed subproject.'''
entrypoint = _get_installed_entrypoint(subproject)
return entrypoint.module_name.split('.')[0]
return entrypoint.module.split('.')[0]
def get_alembic_version_table(config):

View File

@ -14,6 +14,7 @@
# under the License.
import copy
import importlib.metadata
import os
import re
import sys
@ -28,7 +29,6 @@ import fixtures
from neutron_lib import fixture as lib_fixtures
from neutron_lib.utils import helpers
from oslo_utils import fileutils
import pkg_resources
import sqlalchemy as sa
from testtools import matchers
@ -143,13 +143,13 @@ class TestCli(base.BaseTestCase):
config = alembic_config.Config(ini)
config.set_main_option('neutron_project', project)
module_name = project.replace('-', '_') + '.db.migration'
attrs = ('alembic_migrations',)
script_location = ':'.join([module_name, attrs[0]])
script_location = ':'.join([module_name, 'alembic_migrations'])
config.set_main_option('script_location', script_location)
self.configs.append(config)
entrypoint = pkg_resources.EntryPoint(project,
module_name,
attrs=attrs)
entrypoint = importlib.metadata.EntryPoint(
name=project,
group='neutron.db.alembic_migrations',
value=script_location)
migration_cli.migration_entrypoints[project] = entrypoint
def _main_test_helper(self, argv, func_name, exp_kwargs=[{}]):

View File

@ -56,3 +56,6 @@ python-designateclient>=2.7.0 # Apache-2.0
os-vif>=3.1.0 # Apache-2.0
futurist>=1.2.0 # Apache-2.0
tooz>=1.58.0 # Apache-2.0
# TODO(tkajinam): Remove importlib_metadata when python 3.9 support is dropped
importlib_metadata>=3.6;python_version<"3.10" # Apache-2.0