Merge "Get rid of pkg_resources"

This commit is contained in:
Zuul 2024-10-04 16:40:01 +00:00 committed by Gerrit Code Review
commit 0ac6cbec75
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