From c33668e2d3c63f3ef1c503938dc72e175d307d85 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Thu, 27 Mar 2025 02:25:33 +0100 Subject: [PATCH] python312Packages.carbon: fix routers.py --- .../python-modules/carbon/default.nix | 21 +++++++++++------- .../python-modules/carbon/replace-imp.patch | 22 +++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 pkgs/development/python-modules/carbon/replace-imp.patch diff --git a/pkgs/development/python-modules/carbon/default.nix b/pkgs/development/python-modules/carbon/default.nix index 4b253740d6d6..76ff891182ec 100644 --- a/pkgs/development/python-modules/carbon/default.nix +++ b/pkgs/development/python-modules/carbon/default.nix @@ -4,8 +4,6 @@ cachetools, fetchPypi, nixosTests, - pytestCheckHook, - pythonOlder, setuptools, twisted, txamqp, @@ -18,13 +16,17 @@ buildPythonPackage rec { version = "1.1.10"; pyproject = true; - disabled = pythonOlder "3.10"; - src = fetchPypi { inherit pname version; hash = "sha256-wTtbqRHMWBcM2iFN95yzwCf/BQ+EK0vp5MXT4mKX3lw="; }; + patches = [ + # imp has been removed from python since version 3.12 + # This patch replaces it with distutils.utils + ./replace-imp.patch + ]; + # Carbon-s default installation is /opt/graphite. This env variable ensures # carbon is installed as a regular Python module. GRAPHITE_NO_PREFIX = "True"; @@ -51,14 +53,17 @@ buildPythonPackage rec { inherit (nixosTests) graphite; }; - pythonImportsCheck = [ "carbon" ]; + pythonImportsCheck = [ + "carbon" + "carbon.routers" + ]; - meta = with lib; { + meta = { description = "Backend data caching and persistence daemon for Graphite"; homepage = "https://github.com/graphite-project/carbon"; changelog = "https://github.com/graphite-project/carbon/releases/tag/${version}"; - license = licenses.asl20; - maintainers = with maintainers; [ + license = lib.licenses.asl20; + maintainers = with lib.maintainers; [ offline basvandijk ]; diff --git a/pkgs/development/python-modules/carbon/replace-imp.patch b/pkgs/development/python-modules/carbon/replace-imp.patch new file mode 100644 index 000000000000..426d44891f67 --- /dev/null +++ b/pkgs/development/python-modules/carbon/replace-imp.patch @@ -0,0 +1,22 @@ +diff --git a/lib/carbon/routers.py b/lib/carbon/routers.py +index d1c47b7..1a70d7e 100644 +--- a/lib/carbon/routers.py ++++ b/lib/carbon/routers.py +@@ -1,4 +1,4 @@ +-import imp ++import importlib.util + from carbon.hashing import ConsistentHashRing, carbonHash + from carbon.util import PluginRegistrar + from six import with_metaclass +@@ -130,9 +130,8 @@ class ConsistentHashingRouter(DatapointRouter): + + def setKeyFunctionFromModule(self, keyfunc_spec): + module_path, func_name = keyfunc_spec.rsplit(':', 1) +- module_file = open(module_path, 'U') +- description = ('.py', 'U', imp.PY_SOURCE) +- module = imp.load_module('keyfunc_module', module_file, module_path, description) ++ spec = importlib.util.spec_from_file_location("keyfunc_module", module_path) ++ module = importlib.util.module_from_spec(spec) + keyfunc = getattr(module, func_name) + self.setKeyFunction(keyfunc) +