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 Change-Id: I7bcbaade79f3d3662487b801263f446f4d30d88f
This commit is contained in:
parent
ceb3aa5ef2
commit
a5db32d800
@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pkg_resources
|
||||
import importlib.metadata
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
@ -145,8 +145,8 @@ class Config(object):
|
||||
|
||||
if project:
|
||||
try:
|
||||
version = pkg_resources.get_distribution(project).version
|
||||
except pkg_resources.DistributionNotFound:
|
||||
version = importlib.metadata.version(project)
|
||||
except importlib.metadata.PackageNotFoundError:
|
||||
version = "unknown"
|
||||
|
||||
project = "%s/%s " % (project, version)
|
||||
|
@ -1997,8 +1997,8 @@ class TestAuthPluginUserAgentGeneration(BaseAuthTokenMiddlewareTest):
|
||||
self._assert_user_agent(app, project, ksm_version)
|
||||
|
||||
def _create_app(self, conf, project_version, ksm_version):
|
||||
fake_pkg_resources = mock.Mock()
|
||||
fake_pkg_resources.get_distribution().version = project_version
|
||||
fake_im = mock.Mock()
|
||||
fake_im.return_value = project_version
|
||||
|
||||
fake_version_info = mock.Mock()
|
||||
fake_version_info.version_string.return_value = ksm_version
|
||||
@ -2007,10 +2007,10 @@ class TestAuthPluginUserAgentGeneration(BaseAuthTokenMiddlewareTest):
|
||||
|
||||
body = uuid.uuid4().hex
|
||||
|
||||
at_im = 'keystonemiddleware._common.config.importlib.metadata.version'
|
||||
at_pbr = 'keystonemiddleware._common.config.pbr.version'
|
||||
|
||||
with mock.patch('keystonemiddleware._common.config.pkg_resources',
|
||||
new=fake_pkg_resources):
|
||||
with mock.patch(at_im, new=fake_im):
|
||||
with mock.patch(at_pbr, new=fake_pbr_version):
|
||||
return self.create_simple_middleware(body=body, conf=conf)
|
||||
|
||||
|
@ -75,12 +75,12 @@ class TestAuthPluginLocalOsloConfig(base.BaseAuthTokenTestCase):
|
||||
if not project_version:
|
||||
project_version = uuid.uuid4().hex
|
||||
|
||||
fake_pkg_resources = mock.Mock()
|
||||
fake_pkg_resources.get_distribution().version = project_version
|
||||
fake_im = mock.Mock()
|
||||
fake_im.return_value = project_version
|
||||
|
||||
body = uuid.uuid4().hex
|
||||
with mock.patch('keystonemiddleware._common.config.pkg_resources',
|
||||
new=fake_pkg_resources):
|
||||
at_im = 'keystonemiddleware._common.config.importlib.metadata.version'
|
||||
with mock.patch(at_im, new=fake_im):
|
||||
# use_global_conf is poorly named. What it means is
|
||||
# don't use the config created in test setUp.
|
||||
return self.create_simple_middleware(body=body, conf=conf,
|
||||
|
Loading…
x
Reference in New Issue
Block a user