Replace pbr and pkg_resource version info with importlib.metadata

This updates zuul-sphinx to retrieve version info from package metadata
using importlib.metadata instead of the now removed pkg_resources
library. This is necessary to run doc builds on top of python3.12 which
removed setuptools and pkg_resources by default.

An altnerative would be to explicitly require setuptools as a dependency
but stdlib importlib should be sufficient so we don't bother.

Change-Id: I5d73e7cc728188e7978e30eb5eb53d73e74b9ce2
This commit is contained in:
Clark Boylan 2024-11-12 12:40:04 -08:00
parent f51dd26d25
commit f8b00a88f2

View File

@ -14,17 +14,15 @@
import json import json
import pbr.version from importlib import metadata as importlib_metadata
import pkg_resources
version_info = pbr.version.VersionInfo('zuul-sphinx') zuul_sphinx_distribution = importlib_metadata.distribution('zuul-sphinx')
release_string = version_info.release_string() release_string = zuul_sphinx_distribution.version
is_release = None is_release = None
git_version = None git_version = None
try: try:
_metadata = json.loads( _metadata = json.loads(zuul_distribution.read_text('pbr.json'))
pkg_resources.get_distribution('zuul-sphinx').get_metadata('pbr.json'))
if _metadata: if _metadata:
is_release = _metadata['is_release'] is_release = _metadata['is_release']
git_version = _metadata['git_version'] git_version = _metadata['git_version']