From 6ec2c837e71012ff5935f73554cc125ce391687b Mon Sep 17 00:00:00 2001 From: TheK0tYaRa Date: Thu, 19 Feb 2026 02:26:16 +0200 Subject: [PATCH] thop is a horrible bastard of a package without sources for last version --- .../pythonPackages/prefab-specs.nix | 64 +++++++------ custom/pkgs/lib/parse-github-url.nix | 68 +++++++------- custom/pkgs/lib/prefab.nix | 89 ++++++++++--------- 3 files changed, 121 insertions(+), 100 deletions(-) diff --git a/custom/pkgs/by-category/pythonPackages/prefab-specs.nix b/custom/pkgs/by-category/pythonPackages/prefab-specs.nix index 3eb08fe..fcb8a9c 100644 --- a/custom/pkgs/by-category/pythonPackages/prefab-specs.nix +++ b/custom/pkgs/by-category/pythonPackages/prefab-specs.nix @@ -1,5 +1,6 @@ { lib, + # fetchPypi, hatchling, poetry-core, @@ -61,11 +62,14 @@ py-cpuinfo, seaborn, albumentations, + + distutils, + ninja, }: self: let - inherit (self) + inherit (self) # locally defined packages lightrag-hku mineru nano-vectordb @@ -90,8 +94,7 @@ in mineru tqdm ] - # ++ mineru.optional-dependencies.core - ; + ++ mineru.passthru.optional-dependencies.core; pythonImportsCheck = [ "raganything" ]; meta = { description = "RAGAnything: All-in-One RAG System"; @@ -189,22 +192,24 @@ in mineru-vl-utils qwen-vl-utils ]; - # optional-dependencies = { - # core = [ doclayout-yolo ] - # # ++ (with mineru.optional-dependencies; [ - # # vlm - # # pipeline - # # api - # # gradio - # # ]) - # ; - # vlm = [ ]; - # pipeline = [ - # doclayout-yolo - # ]; - # api = [ ]; - # gradio = [ ]; - # }; + optional-dependencies = { + core = with self; [ + doclayout-yolo + ] + # ++ (with mineru.optional-dependencies; [ + # vlm + # pipeline + # api + # gradio + # ]) + ; + # vlm = [ ]; + # pipeline = [ + # doclayout-yolo + # ]; + # api = [ ]; + # gradio = [ ]; + }; pythonRelaxDeps = [ "fast-langdetect" ]; @@ -214,10 +219,8 @@ in }; }; doclayout-yolo = { - # reason for creating fetcher construct - 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 + url = "https://pypi.org/project/doclayout-yolo/0.0.4/"; + hash = "sha256-gDEdEL7QPPiExb/MYkv+D9z/bnhLp2eZNHsCkNedy00="; propagatedBuildDeps = [ matplotlib opencv-python @@ -242,8 +245,19 @@ in }; thop = { url = "https://pypi.org/project/thop/0.1.1.post2209072238/"; - hash = ""; - force.version = "0.1.1"; + force = { + format = "wheel"; + python = "py3"; + dist = "py3"; + }; + hash = "sha256-AUc8IlIxkn0q1xg1H3jr98/+avO+1GTE8boe8PfN2ic="; + nativeBuildDeps = [ + ninja + ]; + propagatedBuildDeps = [ + distutils + torch + ]; meta = { description = "Count the MACs / FLOPs of your PyTorch model."; license = lib.licenses.mit; diff --git a/custom/pkgs/lib/parse-github-url.nix b/custom/pkgs/lib/parse-github-url.nix index 4645e78..3deb85a 100644 --- a/custom/pkgs/lib/parse-github-url.nix +++ b/custom/pkgs/lib/parse-github-url.nix @@ -1,40 +1,40 @@ -{ lib }: +# { lib }: -url: -let - u0 = builtins.head (builtins.split "[?#]" url); - u = lib.strings.removeSuffix "/" u0; +# url: +# let +# u0 = builtins.head (builtins.split "[?#]" url); +# u = lib.strings.removeSuffix "/" u0; - m = builtins.match "https://github.com/([^/]+)/([^/]+)(/(tree|tag|commit)/([^/]+)(/(.*))?)?" u; -in -assert m != null; -let - owner = builtins.elemAt m 0; - repo = builtins.elemAt m 1; +# m = builtins.match "https://github.com/([^/]+)/([^/]+)(/(tree|tag|commit)/([^/]+)(/(.*))?)?" u; +# in +# assert m != null; +# let +# owner = builtins.elemAt m 0; +# repo = builtins.elemAt m 1; - kind = builtins.elemAt m 3; - rev = builtins.elemAt m 4; +# kind = builtins.elemAt m 3; +# rev = builtins.elemAt m 4; - subdir = builtins.elemAt m 6; -in -{ - inherit - owner - repo - kind - rev - subdir - ; +# subdir = builtins.elemAt m 6; +# in +# { +# inherit +# owner +# repo +# kind +# rev +# subdir +# ; - version = - if rev == null then - null - else - let - vm = builtins.match "^.*([0-9]+(\\.[0-9]+)+).*$" rev; - in - if vm == null then null else builtins.elemAt vm 0; +# version = +# if rev == null then +# null +# else +# let +# vm = builtins.match "^.*([0-9]+(\\.[0-9]+)+).*$" rev; +# in +# if vm == null then null else builtins.elemAt vm 0; - pname = repo; - homepage = "https://github.com/${owner}/${repo}"; -} +# pname = repo; +# homepage = "https://github.com/${owner}/${repo}"; +# } diff --git a/custom/pkgs/lib/prefab.nix b/custom/pkgs/lib/prefab.nix index e95f1f5..3b12efb 100644 --- a/custom/pkgs/lib/prefab.nix +++ b/custom/pkgs/lib/prefab.nix @@ -18,7 +18,7 @@ let mkPrefab = { url, - hash, + hash ? "", force ? { }, meta ? { }, passthru ? { }, @@ -33,11 +33,9 @@ let pname = force.pname or ref.pname; - version0 = force.version or ref.version or null; - version = if version0 != null then version0 else "unstable"; + version = force.version or ref.version or "unstable"; - rawSubdir = force.subdir or ref.subdir or null; - subdir = if rawSubdir == null then null else lib.removeSuffix "/" (lib.removePrefix "/" rawSubdir); + isWheel = (force.format or null) == "wheel"; rev = force.rev or ref.rev or null; @@ -56,16 +54,21 @@ let else if ref.type == "pypi" then ( assert (force.version or ref.version or null) != null; - fetchPypi { - inherit pname version hash; - } + fetchPypi ( + lib.filterAttrs (_: v: v != null) { + pname = lib.replaceStrings [ "-" ] [ "_" ] pname; + inherit version hash; + format = force.format or null; + dist = force.dist or null; + python = force.python or null; + abi = force.abi or null; + platform = force.platform or null; + } + ) ) else throw "mkPrefab: unsupported ref.type=${ref.type}"; - sourceRootBase = - force.sourceRootBase or (if ref.type == "github" then src.name else "${pname}-${version}"); - defaultImports = [ (lib.toLower (lib.replaceStrings [ "-" ] [ "_" ] pname)) ]; imports = if pythonImportsCheck == null then defaultImports else pythonImportsCheck; @@ -77,40 +80,44 @@ let passthru.optional-dependencies = optional-dependencies; }; in - buildPythonPackage { - inherit pname version src; - pyproject = true; + buildPythonPackage ( + { + inherit pname version src; + 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; + passthru = passthru'; - 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; + meta = { + inherit homepage; + } + // meta; + sourceRoot = if ref.subdir != null then "source/${ref.subdir}" else null; } - // meta; - } - // lib.optionalAttrs (subdir != null && subdir != "") { - sourceRoot = "${sourceRootBase}/${subdir}"; - }; + // lib.optionalAttrs isWheel { + format = "wheel"; + nativeBuildInputs = nativeBuildDeps; + } + // lib.optionalAttrs (!isWheel) { + pyproject = true; + build-system = [ + setuptools + wheel + ] + ++ nativeBuildDeps; + } + ); mkPrefabs = specs: lib.mapAttrs (_: spec: mkPrefab spec) specs; mkPrefabsRec = specsFn: lib.fix (self: mkPrefabs (specsFn self));