From 132f3c43c3d02a30948ad656e15bb0bc35bd2527 Mon Sep 17 00:00:00 2001 From: Lein Matsumaru Date: Tue, 14 Jul 2026 16:20:51 +0000 Subject: [PATCH] python3Packages.stopit: fix build --- .../python-modules/stopit/default.nix | 17 ++-- .../python-modules/stopit/import_lib.patch | 81 +++++++++++++++++++ 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/python-modules/stopit/import_lib.patch diff --git a/pkgs/development/python-modules/stopit/default.nix b/pkgs/development/python-modules/stopit/default.nix index d7803cc4b1fc..5f839255addf 100644 --- a/pkgs/development/python-modules/stopit/default.nix +++ b/pkgs/development/python-modules/stopit/default.nix @@ -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 ]; }; -} +}) diff --git a/pkgs/development/python-modules/stopit/import_lib.patch b/pkgs/development/python-modules/stopit/import_lib.patch new file mode 100644 index 000000000000..240e4b408e68 --- /dev/null +++ b/pkgs/development/python-modules/stopit/import_lib.patch @@ -0,0 +1,81 @@ +From 9204d1de2ae294b878ed726c8278b28696a91f87 Mon Sep 17 00:00:00 2001 +From: Jonathan Kamens +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 +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 +