python312Packages.carbon: fix routers.py

This commit is contained in:
Gaetan Lepage
2025-03-27 02:26:40 +01:00
parent 3a3e15f998
commit c33668e2d3
2 changed files with 35 additions and 8 deletions
@@ -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
];
@@ -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)