From 15930d4d4b7174e7426d1f53c2408aa8e88d793a Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Mon, 28 Nov 2022 15:14:08 +0000 Subject: [PATCH] Avoid runtime setuptools dependency Using `pkg_resources` meant that setuptools had to be available during runtime, but this dependency was undeclared. Switch to importlib.metadata which is in stdlib since Python 3.8. Fixes: https://github.com/liskin/strava-offline/issues/8 --- setup.cfg | 1 + src/strava_offline/__init__.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index f8a6293..0c58f93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,6 +33,7 @@ install_requires = click ~= 8.0 click-config-file click-option-group + importlib-metadata; python_version<'3.8' platformdirs >= 2.1 requests requests_oauthlib diff --git a/src/strava_offline/__init__.py b/src/strava_offline/__init__.py index 91bf2a9..f07d9b9 100644 --- a/src/strava_offline/__init__.py +++ b/src/strava_offline/__init__.py @@ -1,7 +1,10 @@ -# isort: skip_file -from pkg_resources import get_distribution, DistributionNotFound try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: + from importlib.metadata import version, PackageNotFoundError # type: ignore # isort: skip +except ImportError: + from importlib_metadata import version, PackageNotFoundError # type: ignore # isort: skip + +try: + __version__ = version(__name__) +except PackageNotFoundError: # package is not installed pass