Browse Source

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 <doug@doughellmann.com>
tags/3.3.0^0
Doug Hellmann 2 months ago
committed by Hervé Beraud
parent
commit
e8dd381e62
3 changed files with 9 additions and 2 deletions
  1. +1
    -0
      lower-constraints.txt
  2. +7
    -2
      osprofiler/__init__.py
  3. +1
    -0
      requirements.txt

+ 1
- 0
lower-constraints.txt View File

@@ -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


+ 7
- 2
osprofiler/__init__.py View File

@@ -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")

+ 1
- 0
requirements.txt View File

@@ -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

Loading…
Cancel
Save