Browse Source

drop use of pkg_resources

Importing pkg_resources scans all of the installed modules for data
that won't be used. Switch to using importlib.metdata, which more
efficiently loads the metadata for a package.

Change-Id: I1709952cf0d0329e9b56c20edef50eff1696af22
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
changes/35/743035/1
Doug Hellmann 2 weeks ago
parent
commit
6522756115
No known key found for this signature in database GPG Key ID: 3B6D06A0C428437A
2 changed files with 10 additions and 3 deletions
  1. +9
    -3
      cinderlib/__init__.py
  2. +1
    -0
      requirements.txt

+ 9
- 3
cinderlib/__init__.py View File

@@ -12,7 +12,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# 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

from cinderlib import _fake_packages # noqa F401
from cinderlib import cinderlib
@@ -21,8 +27,8 @@ from cinderlib import serialization
from cinderlib import workarounds # noqa

try:
__version__ = pkg_resources.get_distribution('cinderlib').version
except pkg_resources.DistributionNotFound:
__version__ = importlib_metadata.version('cinderlib')
except importlib_metadata.PackageNotFoundError:
__version__ = '0.0.0'

DEFAULT_PROJECT_ID = objects.DEFAULT_PROJECT_ID


+ 1
- 0
requirements.txt View File

@@ -1 +1,2 @@
cinder>=15.0.0 # Apache-2.0
importlib_metadata>=1.7.0;python_version<'3.8' # Apache-2.0

Loading…
Cancel
Save