about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/sudachidict/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/python-modules/sudachidict/default.nix')
-rw-r--r--nixpkgs/pkgs/development/python-modules/sudachidict/default.nix42
1 files changed, 42 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/python-modules/sudachidict/default.nix b/nixpkgs/pkgs/development/python-modules/sudachidict/default.nix
new file mode 100644
index 000000000000..72826908612c
--- /dev/null
+++ b/nixpkgs/pkgs/development/python-modules/sudachidict/default.nix
@@ -0,0 +1,42 @@
+{ buildPythonPackage
+, fetchFromGitHub
+, sudachidict
+, setuptools
+}:
+
+buildPythonPackage rec {
+  pname = "sudachidict-${sudachidict.dict-type}";
+  inherit (sudachidict) version meta;
+  pyproject = true;
+
+  src = fetchFromGitHub {
+    owner = "WorksApplications";
+    repo = "SudachiDict";
+    rev = "refs/tags/v${version}";
+    hash = "sha256-xJ/iPywOZA2kzHaVU43Bc8TUboj3OpDg1kLFMIc/T90=";
+  };
+
+  sourceRoot = "source/python";
+
+  # setup script tries to get data from the network but we use the nixpkgs' one
+  postPatch = ''
+    substituteInPlace setup.py \
+      --replace 'ZIP_NAME = urlparse(ZIP_URL).path.split("/")[-1]' "" \
+      --replace "not os.path.exists(RESOURCE_DIR)" "False"
+    substituteInPlace INFO.json \
+      --replace "%%VERSION%%" ${version} \
+      --replace "%%DICT_VERSION%%" ${version} \
+      --replace "%%DICT_TYPE%%" ${sudachidict.dict-type}
+  '';
+
+  nativeBuildInputs = [
+    setuptools
+  ];
+
+  # we need to prepare some files before the build
+  # https://github.com/WorksApplications/SudachiDict/blob/develop/package_python.sh
+  preBuild = ''
+    install -Dm644 ${sudachidict}/share/system.dic -t sudachidict_${sudachidict.dict-type}/resources
+    touch sudachidict_${sudachidict.dict-type}/__init__.py
+  '';
+}