summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/nlpo3/default.nix
blob: c0fc956df12f73856ec146c43f4b679687ecee8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
  lib,
  stdenv,
  buildPythonPackage,
  pythonAtLeast,
  unittestCheckHook,
  rustPlatform,
  fetchFromGitHub,
  rustc,
  cargo,
  libiconv,
  setuptools,
  setuptools-rust,
}:

buildPythonPackage rec {
  pname = "nlpo3";
  version = "1.4.0-unstable-2024-11-11";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "PyThaiNLP";
    repo = "nlpo3";
    rev = "280c47b7f98e88319c1a4ac2c7a2e5f273c00621";
    hash = "sha256-bEN2SaINfqvTIPSROXApR3zoLdjZY0h6bdAzbMHrJdM=";
  };

  postPatch = ''
    substituteInPlace tests/test_tokenize.py \
      --replace-fail "data/test_dict.txt" "$src/nlpo3-python/tests/data/test_dict.txt"
  '';

  sourceRoot = "${src.name}/nlpo3-python";

  cargoDeps = rustPlatform.fetchCargoVendor {
    inherit src sourceRoot;
    hash = "sha256-S5nDOz/3ZenvMs8ruybEu5ULefeYGPIKO8kCW3dTa+E=";
  };

  preCheck = ''
    rm -r nlpo3
  '';

  nativeBuildInputs = [
    rustPlatform.cargoSetupHook
    rustc
    cargo
  ];

  buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];

  build-system = [
    setuptools
    setuptools-rust
  ];

  nativeCheckInputs = [ unittestCheckHook ];

  unittestFlagsArray = [
    "-s"
    "tests"
    "-v"
  ];

  pythonImportsCheck = [ "nlpo3" ];

  meta = {
    description = "Thai Natural Language Processing library in Rust, with Python and Node bindings";
    homepage = "https://github.com/PyThaiNLP/nlpo3";
    changelog = "https://github.com/PyThaiNLP/nlpo3/releases/tag/nlpo3-python-v${version}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ vizid ];
  };
}