From 9a559afdba924c444cc02fd258548029aacedd3c Mon Sep 17 00:00:00 2001 From: Antti Kajander Date: Fri, 17 Nov 2023 22:21:00 +0200 Subject: [PATCH] Remove runtime setuptools dependency Prefer importlib.metadata core library on Python >= 3.8 This gets rid of setuptools dependency from stopit users. Recent setuptools versions output a massive deprecation warning about pkg_resources usage: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html Also: update supported Python versions in setup.py with versions I have used stopit successfully on --- setup.py | 5 +++++ src/stopit/__init__.py | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index e42d400..f0149eb 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,11 @@ def read(*names): "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Operating System :: OS Independent", "License :: OSI Approved :: MIT License", "Intended Audience :: Developers", diff --git a/src/stopit/__init__.py b/src/stopit/__init__.py index 6ca0180..c75e5e3 100644 --- a/src/stopit/__init__.py +++ b/src/stopit/__init__.py @@ -7,18 +7,21 @@ Public resources from ``stopit`` """ -import pkg_resources - from .utils import LOG, TimeoutException from .threadstop import ThreadingTimeout, async_raise, threading_timeoutable from .signalstop import SignalTimeout, signal_timeoutable # PEP 396 style version marker try: - __version__ = pkg_resources.get_distribution(__name__).version + from importlib.metadata import version # Python >=3.8 + __version__ = version(__name__) except: - LOG.warning("Could not get the package version from pkg_resources") - __version__ = 'unknown' + try: + import pkg_resources # Deprecated in recent setuptools + __version__ = pkg_resources.get_distribution(__name__).version + except: + LOG.warning("Could not get the package version from importlib or pkg_resources") + __version__ = 'unknown' __all__ = ( 'ThreadingTimeout', 'async_raise', 'threading_timeoutable',