python3Packages.stopit: fix build

This commit is contained in:
Lein Matsumaru
2026-07-16 21:17:20 -04:00
committed by Michael Daniels
parent bc6b6b3647
commit 132f3c43c3
2 changed files with 93 additions and 5 deletions
@@ -6,29 +6,36 @@
}:
buildPythonPackage rec {
buildPythonPackage (finalAttrs: {
pname = "stopit";
version = "1.1.2";
format = "setuptools";
pyproject = true;
__structuredAttrs = true;
# tests are missing from the PyPi tarball
src = fetchFromGitHub {
owner = "glenfant";
repo = "stopit";
rev = version;
tag = finalAttrs.version;
hash = "sha256-uXJUA70JOGWT2NmS6S7fPrTWAJZ0mZ/hICahIUzjfbw=";
};
propagatedBuildInputs = [
build-system = [
setuptools # for pkg_resources
];
patches = [
# https://github.com/glenfant/stopit/pull/34
./import_lib.patch
];
pythonImportsCheck = [ "stopit" ];
meta = {
description = "Raise asynchronous exceptions in other thread, control the timeout of blocks or callables with a context manager or a decorator";
homepage = "https://github.com/glenfant/stopit";
changelog = "https://github.com/glenfant/stopit/blob/${finalAttrs.version}/CHANGES.rst";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ veprbl ];
};
}
})
@@ -0,0 +1,81 @@
From 9204d1de2ae294b878ed726c8278b28696a91f87 Mon Sep 17 00:00:00 2001
From: Jonathan Kamens <jik@jik6.kamens.us>
Date: Wed, 25 Sep 2024 15:52:03 -0400
Subject: [PATCH 1/2] Use importlib instead of pkg_resources to determine
package version
`pkg_resources` is deprecated and no longer available for import by
default as of Python 3.12.
---
src/stopit/__init__.py | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/stopit/__init__.py b/src/stopit/__init__.py
index 6ca0180..d2fb01e 100644
--- a/src/stopit/__init__.py
+++ b/src/stopit/__init__.py
@@ -7,19 +7,25 @@
Public resources from ``stopit``
"""
-import pkg_resources
+try:
+ from importlib.metadata import version
+ __version__ = version(__name__)
+except Exception:
+ # pkg_resources is deprecated as of Python 3.12 and no longer available for
+ # import by default.
+ try:
+ import pkg_resources
+ except Exception:
+ LOG.warning(
+ "Could not get the package version from importlib or pkg_resources")
+ __version__ = 'unknown'
+ else:
+ __version__ = pkg_resources.get_distribution(__name__).version
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
-except:
- LOG.warning("Could not get the package version from pkg_resources")
- __version__ = 'unknown'
-
__all__ = (
'ThreadingTimeout', 'async_raise', 'threading_timeoutable',
'SignalTimeout', 'signal_timeoutable'
From a2f6bde8a29cd281577426800b186802c68dbd86 Mon Sep 17 00:00:00 2001
From: Jonathan Kamens <jik@jik7>
Date: Mon, 28 Jul 2025 09:13:25 -0400
Subject: [PATCH 2/2] Import LOG before trying to use it
---
src/stopit/__init__.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/stopit/__init__.py b/src/stopit/__init__.py
index d2fb01e..bbf7068 100644
--- a/src/stopit/__init__.py
+++ b/src/stopit/__init__.py
@@ -7,6 +7,8 @@
Public resources from ``stopit``
"""
+from .utils import LOG, TimeoutException
+
try:
from importlib.metadata import version
__version__ = version(__name__)
@@ -22,7 +24,6 @@
else:
__version__ = pkg_resources.get_distribution(__name__).version
-from .utils import LOG, TimeoutException
from .threadstop import ThreadingTimeout, async_raise, threading_timeoutable
from .signalstop import SignalTimeout, signal_timeoutable