python312Packages.carbon: fix routers.py

Changed files
+35 -8
pkgs
development
python-modules
+13 -8
pkgs/development/python-modules/carbon/default.nix
···
cachetools,
fetchPypi,
nixosTests,
-
pytestCheckHook,
-
pythonOlder,
setuptools,
twisted,
txamqp,
···
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.
···
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
];
+22
pkgs/development/python-modules/carbon/replace-imp.patch
···
+
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)
+