mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 07:53:19 +00:00
8f94a33b38
Some derivations use lib.optional or lib.optionals when setting pre/post phase hooks. Ensure the proper lib.optionalString is used.
48 lines
1.5 KiB
Nix
48 lines
1.5 KiB
Nix
{ lib
|
|
, buildPythonPackage
|
|
, fetchurl
|
|
, jieba
|
|
, pymorphy2
|
|
, sentencepiece
|
|
, spacy
|
|
, spacy-pkuseg
|
|
, spacy-transformers }:
|
|
let
|
|
buildModelPackage = { pname, version, sha256, license }:
|
|
let
|
|
lang = builtins.substring 0 2 pname;
|
|
in buildPythonPackage {
|
|
inherit pname version;
|
|
|
|
src = fetchurl {
|
|
url = "https://github.com/explosion/spacy-models/releases/download/${pname}-${version}/${pname}-${version}.tar.gz";
|
|
inherit sha256;
|
|
};
|
|
|
|
propagatedBuildInputs = [ spacy ]
|
|
++ lib.optionals (lang == "zh") [ jieba spacy-pkuseg ]
|
|
++ lib.optionals (lib.hasSuffix "_trf" pname) [ spacy-transformers ]
|
|
++ lib.optionals (lang == "ru") [ pymorphy2 ]
|
|
++ lib.optionals (pname == "fr_dep_news_trf") [ sentencepiece ];
|
|
|
|
postPatch = lib.optionalString (pname == "fr_dep_news_trf") ''
|
|
substituteInPlace meta.json \
|
|
--replace "sentencepiece==0.1.91" "sentencepiece>=0.1.91"
|
|
'';
|
|
|
|
pythonImportsCheck = [ pname ];
|
|
|
|
meta = with lib; {
|
|
description = "Models for the spaCy NLP library";
|
|
homepage = "https://github.com/explosion/spacy-models";
|
|
license = licenses.${license};
|
|
maintainers = with maintainers; [ rvl ];
|
|
};
|
|
};
|
|
|
|
makeModelSet = models: with lib; listToAttrs (map (m: nameValuePair m.pname (buildModelPackage m)) models);
|
|
|
|
in makeModelSet (lib.importJSON ./models.json)
|
|
|
|
# cat models.json | jq -r '.[] | @uri "https://github.com/explosion/spacy-models/releases/download/\(.pname)-\(.version)/\(.pname)-\(.version).tar.gz"' | xargs -n1 nix-prefetch-url
|