Skip to content

Commit 2ccfe3a

Browse files
authored
rabbit: unbreak the package (#390659)
2 parents 1547499 + 399baf3 commit 2ccfe3a

File tree

2 files changed

+85
-3
lines changed

2 files changed

+85
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From 3488de815355051d2e369c7fe48a35dabf695cfc Mon Sep 17 00:00:00 2001
2+
From: Pol Dellaiera <[email protected]>
3+
Date: Mon, 17 Mar 2025 16:52:25 +0100
4+
Subject: [PATCH] fix file loading
5+
6+
---
7+
rabbit.py | 17 ++++++++---------
8+
1 file changed, 8 insertions(+), 9 deletions(-)
9+
10+
diff --git a/rabbit.py b/rabbit.py
11+
index a1826d3..697c880 100644
12+
--- a/rabbit.py
13+
+++ b/rabbit.py
14+
@@ -9,6 +9,7 @@ from sklearn.ensemble import GradientBoostingClassifier
15+
import joblib
16+
import site
17+
from tqdm import tqdm
18+
+from importlib.resources import files
19+
20+
import GenerateActivities as gat
21+
import ExtractEvent as eev
22+
@@ -59,15 +60,13 @@ def get_model():
23+
'''
24+
25+
model_file = 'bimbas.joblib'
26+
- for dir in site.getsitepackages():
27+
- if dir.endswith('site-packages'):
28+
- target_dir = dir
29+
- else:
30+
- target_dir = site.getsitepackages()[0]
31+
- bot_identification_model = joblib.load(f'{target_dir}/{model_file}')
32+
- # bot_identification_model = joblib.load(model_file)
33+
-
34+
- return(bot_identification_model)
35+
+ try:
36+
+ resource_path = files("rabbit").joinpath(model_file)
37+
+ bot_identification_model = joblib.load(resource_path)
38+
+ except Exception as e:
39+
+ raise RuntimeError(f"Failed to load the model: {e}")
40+
+
41+
+ return bot_identification_model
42+
43+
def compute_confidence(probability_value):
44+
'''
45+
--
46+
2.48.1
47+

pkgs/by-name/ra/rabbit/package.nix

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,39 @@
22
lib,
33
python3,
44
fetchFromGitHub,
5+
fetchPypi,
56
}:
67

7-
python3.pkgs.buildPythonApplication rec {
8+
let
9+
python3' =
10+
let
11+
packageOverrides = self: super: {
12+
scikit-learn = super.scikit-learn.overridePythonAttrs (old: {
13+
version = "1.5.2";
14+
15+
src = fetchPypi {
16+
pname = "scikit_learn";
17+
version = "1.5.2";
18+
hash = "sha256-tCN+17P90KSIJ5LmjvJUXVuqUKyju0WqffRoE4rY+U0=";
19+
};
20+
21+
# There are 2 tests that are failing, disabling the tests for now.
22+
# - test_csr_polynomial_expansion_index_overflow[csr_array-False-True-2-65535]
23+
# - test_csr_polynomial_expansion_index_overflow[csr_array-False-True-3-2344]
24+
doCheck = false;
25+
});
26+
};
27+
in
28+
python3.override {
29+
inherit packageOverrides;
30+
self = python3;
31+
};
32+
in
33+
python3'.pkgs.buildPythonApplication rec {
834
pname = "rabbit";
35+
# Make sure to check for which version of scikit-learn this project was built
36+
# Currently version 2.3.1 is made with scikit-learn 1.5.2
37+
# Upgrading to newer versions of scikit-learn break the project
938
version = "2.3.1";
1039
pyproject = true;
1140

@@ -16,6 +45,12 @@ python3.pkgs.buildPythonApplication rec {
1645
hash = "sha256-QmP6yfVnlYoNVa4EUtKR9xbCnQW2V6deV0+hN9IGtic=";
1746
};
1847

48+
patches = [
49+
# Fix file loading, to be removed at the next bump.
50+
# The author has been notified about the issue and currently working on it.
51+
./fix-file-loading.patch
52+
];
53+
1954
pythonRelaxDeps = [
2055
"numpy"
2156
"scikit-learn"
@@ -24,11 +59,11 @@ python3.pkgs.buildPythonApplication rec {
2459
"urllib3"
2560
];
2661

27-
build-system = with python3.pkgs; [
62+
build-system = with python3'.pkgs; [
2863
setuptools
2964
];
3065

31-
dependencies = with python3.pkgs; [
66+
dependencies = with python3'.pkgs; [
3267
joblib
3368
numpy
3469
pandas

0 commit comments

Comments
 (0)