From e8dd381e626d48f11c6b8c9e296433b23e88124b Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Sun, 5 Jul 2020 19:35:41 -0400 Subject: switch to importlib.metadata to find package version Importing pkg_resources has a side-effect of reading all of the metadata for every installed python package. The newer importlib.metadata module can load the metadata for one package at a time, which makes this library load more quickly and improves the startup-time performance of applications that use it such as python-openstackclient. importlib.metadata is part of the python 3.8 standard library and is distributed separately for other versions of python. Change-Id: Ib1870a3d102116f84c7677601fd44fdac41a13a6 Signed-off-by: Doug Hellmann --- lower-constraints.txt | 1 + osprofiler/__init__.py | 9 +++++++-- requirements.txt | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index a857357..2ced6ac 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -2,6 +2,7 @@ coverage===4.0 ddt===1.0.1 dulwich===0.15.0 elasticsearch===2.0.0 +importlib_metadata==1.7.0 jaeger-client==3.8.0 netaddr===0.7.18 openstackdocstheme==2.2.1 diff --git a/osprofiler/__init__.py b/osprofiler/__init__.py index 22bedd3..e9adf59 100644 --- a/osprofiler/__init__.py +++ b/osprofiler/__init__.py @@ -13,6 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import pkg_resources +try: + # For Python 3.8 and later + import importlib.metadata as importlib_metadata +except ImportError: + # For everyone else + import importlib_metadata -__version__ = pkg_resources.get_distribution("osprofiler").version +__version__ = importlib_metadata.version("osprofiler") diff --git a/requirements.txt b/requirements.txt index 2239282..7719bc4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ PrettyTable<0.8,>=0.7.2 # BSD requests>=2.14.2 # Apache-2.0 six>=1.10.0 # MIT WebOb>=1.7.1 # MIT +importlib_metadata>=1.7.0;python_version<'3.8' # Apache-2.0 -- cgit v1.2.1