Merge "Remove final use of pkg_resources"

This commit is contained in:
Zuul 2022-07-18 18:49:03 +00:00 committed by Gerrit Code Review
commit f782f42b94
2 changed files with 9 additions and 17 deletions

View File

@ -13,6 +13,7 @@
import abc import abc
import inspect import inspect
import importlib_metadata
from stevedore import extension from stevedore import extension
from cliff import _argparse from cliff import _argparse
@ -27,26 +28,15 @@ def _get_distributions_by_modules():
distribution name (the name used with pip and PyPI) do not distribution name (the name used with pip and PyPI) do not
always match. We want to report which distribution caused the always match. We want to report which distribution caused the
command to be installed, so we need to look up the values. command to be installed, so we need to look up the values.
""" """
import pkg_resources
global _dists_by_mods global _dists_by_mods
if _dists_by_mods is None: if _dists_by_mods is None:
results = {} # There can be multiple distribution in the case of namespace packages
for dist in pkg_resources.working_set: # so we'll just grab the first one
try: _dists_by_mods = {
mod_names = dist.get_metadata('top_level.txt').strip() k: v[0] for k, v in
except Exception: importlib_metadata.packages_distributions().items()
# Could not retrieve metadata. Either the file is not }
# present or we cannot read it. Ignore the
# distribution.
pass
else:
# Distributions may include multiple top-level
# packages (see setuptools for an example).
for mod_name in mod_names.splitlines():
results[mod_name] = dist.project_name
_dists_by_mods = results
return _dists_by_mods return _dists_by_mods

View File

@ -1,4 +1,6 @@
autopage>=0.4.0 # Apache 2.0 autopage>=0.4.0 # Apache 2.0
# TODO: Drop this when Python 3.10 is our minimum supported version
importlib_metadata>=4.4 # Apache-2.0
cmd2>=1.0.0 # MIT cmd2>=1.0.0 # MIT
PrettyTable>=0.7.2 # BSD PrettyTable>=0.7.2 # BSD
stevedore>=2.0.1 # Apache-2.0 stevedore>=2.0.1 # Apache-2.0