1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonAtLeast,
6 unittestCheckHook,
7 rustPlatform,
8 fetchFromGitHub,
9 rustc,
10 cargo,
11 libiconv,
12 setuptools,
13 setuptools-rust,
14}:
15
16buildPythonPackage rec {
17 pname = "nlpo3";
18 version = "1.4.0-unstable-2024-11-11";
19 pyproject = true;
20
21 src = fetchFromGitHub {
22 owner = "PyThaiNLP";
23 repo = "nlpo3";
24 rev = "280c47b7f98e88319c1a4ac2c7a2e5f273c00621";
25 hash = "sha256-bEN2SaINfqvTIPSROXApR3zoLdjZY0h6bdAzbMHrJdM=";
26 };
27
28 postPatch = ''
29 substituteInPlace tests/test_tokenize.py \
30 --replace-fail "data/test_dict.txt" "$src/nlpo3-python/tests/data/test_dict.txt"
31 '';
32
33 sourceRoot = "${src.name}/nlpo3-python";
34
35 cargoDeps = rustPlatform.fetchCargoVendor {
36 inherit src sourceRoot;
37 hash = "sha256-S5nDOz/3ZenvMs8ruybEu5ULefeYGPIKO8kCW3dTa+E=";
38 };
39
40 preCheck = ''
41 rm -r nlpo3
42 '';
43
44 nativeBuildInputs = [
45 rustPlatform.cargoSetupHook
46 rustc
47 cargo
48 ];
49
50 buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
51
52 build-system = [
53 setuptools
54 setuptools-rust
55 ];
56
57 nativeCheckInputs = [ unittestCheckHook ];
58
59 unittestFlagsArray = [
60 "-s"
61 "tests"
62 "-v"
63 ];
64
65 pythonImportsCheck = [ "nlpo3" ];
66
67 meta = {
68 description = "Thai Natural Language Processing library in Rust, with Python and Node bindings";
69 homepage = "https://github.com/PyThaiNLP/nlpo3";
70 changelog = "https://github.com/PyThaiNLP/nlpo3/releases/tag/nlpo3-python-v${version}";
71 license = lib.licenses.asl20;
72 maintainers = with lib.maintainers; [ vizid ];
73 };
74}