summaryrefslogtreecommitdiff
path: root/osprofiler/__init__.py
diff options
context:
space:
mode:
authorDoug Hellmann <doug@doughellmann.com>2020-07-05 19:35:41 -0400
committerHervé Beraud <hberaud@redhat.com>2020-07-06 11:07:17 +0200
commite8dd381e626d48f11c6b8c9e296433b23e88124b (patch)
tree2d20d4970fdd86ed65effa14c8ea0ca0f8ec401f /osprofiler/__init__.py
parent61a0ff8ace87e917d31231f28f3be6b21a113624 (diff)
downloadosprofiler-e8dd381e626d48f11c6b8c9e296433b23e88124b.tar.gz
switch to importlib.metadata to find package version3.3.0
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 <doug@doughellmann.com>
Diffstat (limited to 'osprofiler/__init__.py')
-rw-r--r--osprofiler/__init__.py9
1 files changed, 7 insertions, 2 deletions
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")