python rework step 2

This commit is contained in:
TheK0tYaRa 2026-02-17 16:10:47 +02:00
parent 7fef92886f
commit 7febb7395f
3 changed files with 90 additions and 53 deletions

View file

@ -0,0 +1,8 @@
let
prefab = import ../../../lib/prefab.nix {
inherit lib fetchFromGitHub fetchPypi;
inherit (python.pkgs) buildPythonPackage setuptools wheel;
python = python;
};
in
prefab.mkPrefabsRec (import ./prefab-specs.nix)

View file

@ -53,19 +53,28 @@
torchvision,
wcwidth,
matplotlib,
pyyaml,
scipy,
psutil,
py-cpuinfo,
thop,
seaborn,
albumentations,
}:
rec {
self: {
raganything = {
url = "https://github.com/HKUDS/RAG-Anything/tree/v1.2.9";
hash = "sha256-yepiLYzPD6UcJRbAbovg/BwFE8nh903o/tHypiHGKSw=";
propagatedBuildDeps = [
huggingface-hub
lightrag-hku
self.lightrag-hku
tqdm
# mineru
]
++ mineru.optional-dependencies.core;
++ self.mineru.optional-dependencies.core;
pythonImportsCheck = [ "raganything" ];
meta = {
description = "RAGAnything: All-in-One RAG System";
@ -81,11 +90,11 @@ rec {
google-api-core
google-genai
json-repair
nano-vectordb
self.nano-vectordb
networkx
numpy
pandas
pipmaster
self.pipmaster
pydantic
pypinyin
python-dotenv
@ -103,7 +112,7 @@ rec {
hash = "sha256-IJ6VG4WvoEm584vbZDLTtRcEZekZh7HJto1hnABoodo=";
force.version = "1.1.0";
propagatedBuildDeps = [
ascii-colors
self.ascii-colors
];
meta = with lib; {
description = "A versatile Python package manager utility for simplifying package installation, updates, checks, and environment management.";
@ -150,21 +159,21 @@ rec {
pypdfium2
pypdf
reportlab
pdftext
self.pdftext
modelscope
huggingface-hub
json-repair
opencv-python
fast-langdetect
self.fast-langdetect
scikit-image
openai
beautifulsoup4
magika
mineru-vl-utils
qwen-vl-utils
self.mineru-vl-utils
self.qwen-vl-utils
];
optional-dependencies = {
core = [ doclayout-yolo ]
core = [ self.doclayout-yolo ]
# ++ (with mineru.optional-dependencies; [
# vlm
# pipeline
@ -174,7 +183,7 @@ rec {
;
vlm = [ ];
pipeline = [
doclayout-yolo
self.doclayout-yolo
];
api = [ ];
gradio = [ ];
@ -189,9 +198,26 @@ rec {
};
doclayout-yolo = {
# reason for creating fetcher construct
url = "https://github.com/opendatalab/DocLayout-YOLO/tree/main"; # master is 10 months old and last version was set in Oct 18, 2024
url = "https://pypi.org/project/doclayout-yolo/0.0.4/"; # master is 10 months old and last version was set in Oct 18, 2024
hash = "sha256-wLCmJuWyw7Gqou7awsHtxqVyr4AN+yJSkF0q3GUSQh8=";
force.version = "0.0.4"; # NOT 0.0.4 on github but fuck it we ball
# force.version = "0.0.4"; # NOT 0.0.4 on github but fuck it we ball
propagatedBuildDeps = [
matplotlib
opencv-python
pillow
pyyaml
requests
scipy
torch
torchvision
tqdm
psutil
py-cpuinfo
thop
pandas
seaborn
albumentations
];
meta = {
description = "DocLayout-YOLO: Enhancing Document Layout Analysis through Diverse Synthetic Data and Global-to-Local Adaptive Perception";
license = lib.licenses.agpl3Only;
@ -223,7 +249,7 @@ rec {
hash = "sha256-hpTW/1nwXPxfld4nx0XHZBMerWj+UL1vzDhYpwjezRU=";
propagatedBuildDeps = [
httpx
httpx-retries
self.httpx-retries
aiofiles
pillow
pydantic
@ -253,7 +279,7 @@ rec {
hash = "sha256-pj46gHG9cjkSjnYc88bSctL/1LAUe0jkBuM/GZWMsUI=";
propagatedBuildDeps = [
pdm-backend
robust-downloader
self.robust-downloader
requests
fasttext-predict
];

View file

@ -15,13 +15,14 @@ let
{
url,
hash,
force ? { }, # overrides: pname/version/rev/subdir/sourceRootBase/homepage/src
force ? { },
meta ? { },
passthru ? { },
propagatedBuildDeps ? [ ],
nativeBuildDeps ? [ ],
pythonRelaxDeps ? [ ],
pythonImportsCheck ? null,
optional-dependencies ? null,
optional-dependencies ? { },
}:
let
ref = parseRef url;
@ -52,8 +53,7 @@ let
(
assert (force.version or ref.version or null) != null;
fetchPypi {
inherit pname version;
inherit hash;
inherit pname version hash;
}
)
else
@ -66,50 +66,53 @@ let
imports = if pythonImportsCheck == null then defaultImports else pythonImportsCheck;
homepage = force.homepage or ref.homepage;
passthru' =
passthru
// lib.optionalAttrs (optional-dependencies != { }) {
optional-dependencies = optional-dependencies;
};
in
buildPythonPackage (
(
{
inherit pname version src;
pyproject = true;
({
inherit pname version src;
pyproject = true;
build-system = [
setuptools
wheel
]
++ nativeBuildDeps;
dependencies = propagatedBuildDeps;
pythonRelaxDeps = pythonRelaxDeps;
pythonImportsCheck = imports;
build-system = [
setuptools
wheel
]
++ nativeBuildDeps;
dependencies = propagatedBuildDeps;
pythonRelaxDeps = pythonRelaxDeps;
installCheckPhase = ''
runHook preInstallCheck
${builtins.concatStringsSep "\n" (
map (mod: ''
${python.interpreter} -c "import ${mod}; print(getattr(${mod},'__version__','unknown'))"
'') imports
)}
runHook postInstallCheck
'';
pythonImportsCheck = imports;
meta = {
inherit homepage;
}
// meta;
installCheckPhase = ''
runHook preInstallCheck
${builtins.concatStringsSep "\n" (
map (mod: ''
${python.interpreter} -c "import ${mod}; print(getattr(${mod},'__version__','unknown'))"
'') imports
)}
runHook postInstallCheck
'';
passthru = passthru';
meta = {
inherit homepage;
}
// lib.optionalAttrs (optional-dependencies != null) {
optional-dependencies = optional-dependencies;
}
)
// meta;
})
// lib.optionalAttrs (subdir != null && subdir != "") {
sourceRoot = "${sourceRootBase}/${subdir}";
}
);
# 핵: specs = { pkgA = { url=...; hash=...; ...; }; ...; }
# -> { pkgA = mkPrefab specs.pkgA; ...; }
mkPrefabs = specs: lib.mapAttrs (_: spec: mkPrefab spec) specs;
mkPrefabsRec = specsFn: lib.fix (self: mkPrefabs (specsFn self));
in
{
inherit mkPrefab mkPrefabs;
inherit mkPrefab mkPrefabs mkPrefabsRec;
}