Drop use of pkg_resources

This updates version handling in zuul-client to drop the use of
pkg_resources. We adopt the version handling approach used by zuul which
relies on importlib.metadata to fetch details that pbr writes to the
zuul-client package. Notably, we also drop the use of pbr.version as it
isn't necessary to read the data out of package metadata.

The motivation behind this is that pkg_resources is going to go away.
Setuptools keeps threatening to delete it entirely. Get ahead of that by
replacing it now.

Note that importlib.metadata is in python stdlib as of python3.8. We
only test with 3.11 and 3.12 and setup.cfg lists 3.8 as the oldest
supported version so this should be ok.

Change-Id: I508eab5967a1a52d0a003f88d3e7b93f653bf70a
This commit is contained in:
Clark Boylan
2025-11-06 14:13:12 -08:00
parent 2ffd2e47a3
commit bf53eda595
2 changed files with 7 additions and 8 deletions

View File

@@ -58,8 +58,8 @@ class ZuulClient():
self.config = None
def _get_version(self):
from zuulclient.version import version_info
return "Zuul-client version: %s" % version_info.release_string()
from zuulclient.version import release_string
return "Zuul-client version: %s" % release_string
def createParser(self):
parser = argparse.ArgumentParser(

View File

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