Repository navigation
Expand file tree
/
Copy pathpyproject.toml
More file actions
678 lines (585 loc) · 17.3 KB
/
Copy pathpyproject.toml
File metadata and controls
678 lines (585 loc) · 17.3 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# SPDX-FileCopyrightText: 2016-present PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "pythainlp"
version = "5.4.0"
description = "Thai Natural Language Processing library"
readme = "README.md"
requires-python = ">=3.10"
license = "Apache-2.0"
authors = [
{ name = "Wannaphong Phatthiyaphaibun", email = "wannaphong@pythainlp.org" },
{ name = "Korakot Chaovavanich" },
{ name = "Charin Polpanumas" },
{ name = "Arthit Suriyawongkul", email = "suriyawa@tcd.ie" },
{ name = "Lalita Lowphansirikul" },
{ name = "Pattarawat Chormai" },
{ name = "Peerat Limkonchotiwat" },
{ name = "Thanathip Suntorntip" },
{ name = "Can Udomcharoenchaikit" },
]
maintainers = [
{ name = "Wannaphong Phatthiyaphaibun", email = "wannaphong@pythainlp.org" },
{ name = "Arthit Suriyawongkul", email = "suriyawa@tcd.ie" },
]
keywords = [
"pythainlp",
"NLP",
"natural language processing",
"tokenization",
"text processing",
"linguistics",
"localization",
"computational linguistics",
"ThaiNLP",
"Thai NLP",
"Thai language",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Intended Audience :: Developers",
"Natural Language :: Thai",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Software Development :: Localization",
"Topic :: Text Processing",
"Topic :: Text Processing :: General",
"Topic :: Text Processing :: Linguistic",
]
# Core dependencies
dependencies = [
"importlib_resources; python_version < '3.11'",
"tzdata; sys_platform == 'win32'",
]
[project.optional-dependencies]
## 1) Development ########################################
dev = [
# Some tools drop Python 3.10 in newer releases. Use the latest version
# for each Python range. bandit 1.8.x reports false positives for B615
# (revision is a variable).
"bandit>=1.9.4",
"build>=1.6.1",
"bump-my-version>=1.8.1",
"coverage>=7.16.2;python_version<'3.11'",
"coverage>=7.17.2;python_version>='3.11'",
"diff-cover>=10.6.0;python_version<'3.11'",
"diff-cover>=11.0.1;python_version>='3.11'",
"flake8>=7.4.1;python_version<'3.11'",
"flake8>=7.5.0;python_version>='3.11'",
"flake8-cognitive-complexity>=0.1.0",
# Same as CI.
"mypy==2.4.1",
"pylint>=4.1.3",
"ruff>=0.17.4",
"tox>=4.65.0;python_version<'3.11'",
"tox>=4.67.13;python_version>='3.11'",
]
docs = [
"Sphinx>=6.2",
"sphinx-copybutton>=0.5.2",
"sphinx-rtd-theme>=3.1.0",
]
## 2) Feature sets #######################################
abbreviation = ["khamyo>=0.2.0"]
attacut = ["attacut>=1.0.6"]
attaparse = ["attaparse>=1.0.0"]
benchmarks = ["numpy>=1.22", "pandas>=0.24", "PyYAML>=5.4.1"]
budoux = ["budoux>=0.7.0"]
coreference_resolution = ["fastcoref>=2.1.5", "spacy>=3.0"]
dependency_parsing = [
"attaparse>=1.0.0",
"spacy_thai>=0.7.1",
"transformers>=4.22.1",
"ufal.chu-liu-edmonds>=1.0.2",
]
el = ["multiel>=0.5"]
esupar = ["esupar>=1.3.8", "numpy>=1.22", "transformers>=4.22.1"]
generate = ["fastai<2.0"]
icu = ["pyicu>=2.3"]
ipa = ["epitran>=1.1"]
ml = ["numpy>=1.22", "torch>=1.0.0"]
mt5 = ["sentencepiece>=0.1.91", "transformers>=4.22.1"]
nlpo3 = ["nlpo3>=1.4.0"]
onnx = ["numpy>=1.22", "onnxruntime>=1.10.0", "sentencepiece>=0.1.91"]
oskut = ["oskut>=1.3"]
qwen3 = ["torch>=1.9.0", "transformers>=4.22.1"]
sefr_cut = ["sefr_cut>=1.1"]
spacy_thai = ["spacy_thai>=0.7.1"]
spell = ["phunspell>=0.1.6", "symspellpy>=6.7.6"]
ssg = ["ssg>=0.0.8"]
textaugment = ["bpemb>=0.3.2", "gensim>=4.0.0"]
thai_nner = ["thai_nner>=0.3"]
thai2fit = ["emoji>=0.5.1", "gensim>=4.0.0", "numpy>=1.22"]
thai2rom = ["numpy>=1.22", "torch>=1.0.0"]
translate = [
'fairseq>=0.10.0,<0.13;python_version<"3.11"',
'fairseq-fixed==0.12.3.1,<0.13;python_version>="3.11"',
"sacremoses>=0.0.41",
"sentencepiece>=0.1.91",
"torch>=1.0.0",
"transformers>=4.22.1",
"word2word>=1.0.0",
]
transformers_ud = ["transformers>=4.22.1", "ufal.chu-liu-edmonds>=1.0.2"]
wangchanberta = ["sentencepiece>=0.1.91", "transformers>=4.22.1"]
wangchanglm = ["pandas>=0.24", "sentencepiece>=0.1.91", "transformers>=4.22.1"]
word_approximation = ["panphon>=0.20.0"]
wordnet = ["nltk>=3.3"]
wsd = ["sentence-transformers>=2.2.2"]
wtp = ["transformers>=4.22.1", "wtpsplit>=1.0.1"]
wunsen = ["wunsen>=0.0.3"]
## 3) Testing ############################################
# Below are dependency groups for each defined test suites
# Compact dependencies - for tests.compact modules
# Safe small set of optional dependencies
# for common tasks like tokenization and tagging.
compact = [
"nlpo3>=1.4.0",
"numpy>=1.26.0",
"pyicu>=2.3",
"python-crfsuite>=0.9.7",
"PyYAML>=5.4.1",
]
# Extra dependencies - for tests.extra modules
extra = [
"bpemb>=0.3.2",
"budoux>=0.7.0",
"gensim>=4.0.0",
"nltk>=3.3",
"pandas>=0.24",
"ssg>=0.0.8",
"symspellpy>=6.7.6",
# tltk 1.11 pins scikit-learn~=1.2.0, which has no wheel for Python 3.13+
"tltk>=1.10,!=1.11",
]
# Noauto test dependencies - for tests.noauto_* modules
# These are further grouped by dependency framework to avoid conflicts
# PyTorch-based dependencies - for tests.noauto_torch
noauto-torch = [
"attacut>=1.0.6",
"numpy>=1.26.0",
"sentencepiece>=0.1.91",
"thai-nner>=0.3",
# tltk 1.11 pins scikit-learn~=1.2.0, which has no wheel for Python 3.13+
"tltk>=1.10,!=1.11",
"torch>=1.13.1",
"transformers>=4.22.1",
"wtpsplit>=1.0.1",
]
# TensorFlow-based dependencies - for tests.noauto_tensorflow
noauto-tensorflow = [
"numpy>=1.26.0",
]
# ONNX Runtime-based dependencies - for tests.noauto_onnx
noauto-onnx = [
"numpy>=1.26.0",
"onnxruntime>=1.10.0",
"oskut>=1.3",
"sefr_cut>=1.1",
]
# Cython-based dependencies - for tests.noauto_cython
noauto-cython = [
"phunspell>=0.1.6",
]
# Network-dependent tests - for tests.noauto_network
# These tests require network access but minimal dependencies
noauto-network = [
"huggingface-hub>=0.16.0",
]
# Full dependencies - pinned where available
full = [
"attacut==1.0.6",
"attaparse==1.0.0",
"bpemb>=0.3.6,<0.4",
"budoux==0.9.3",
"epitran==1.35.3",
"esupar>=1.3.9,<2",
'fairseq>=0.10.0,<0.13;python_version<"3.11"',
'fairseq-fixed==0.12.3.1,<0.13;python_version>="3.11"',
"fastai>=1.0.61,<2",
"fastcoref==2.1.6",
"gensim>=4.3.3,<5",
"khamyo>=0.3.0",
"khanaa>=0.1.1,<1",
"nlpo3>=1.4.0",
"nltk>=3.6.6,<4",
"numpy>=1.26.0,<3",
"onnxruntime>=1.10.0",
"oskut>=1.3",
"pandas>=2.2.0,<3",
"panphon==0.22.2",
"phunspell==0.1.6",
"pyicu>=2.15.2,<3",
"python-crfsuite==0.9.12",
"PyYAML>=5.4.1,<6.0.2",
"sacremoses==0.1.1",
"sentence-transformers>=2.7.0,<3",
"sentencepiece==0.2.3",
"spacy==3.8.7,<4",
"spacy_thai==0.7.8",
"ssg==0.0.8",
"sefr_cut>=1.1",
"symspellpy==6.10.2",
"thai-nner==0.3",
# tltk 1.11 pins scikit-learn~=1.2.0, which has no wheel for Python 3.13+
"tltk>=1.10,!=1.11,<2",
"torch>=1.13.1,<3",
"transformers==5.20.2",
"ufal.chu-liu-edmonds==1.0.3",
"word2word>=1.0.0,<2",
"wtpsplit==1.3.0",
"wunsen==0.0.3",
]
[project.urls]
homepage = "https://pythainlp.org/"
source = "https://github.com/PyThaiNLP/pythainlp.git"
download = "https://pypi.org/project/pythainlp/#files"
changelog = "https://github.com/PyThaiNLP/pythainlp/blob/dev/CHANGELOG.md"
releasenotes = "https://github.com/PyThaiNLP/pythainlp/releases"
documentation = "https://pythainlp.org/docs/"
issues = "https://github.com/PyThaiNLP/pythainlp/issues"
"Tutorials" = "https://pythainlp.org/tutorials/"
[project.scripts]
thainlp = "pythainlp.__main__:main"
[tool.hatch.build.targets.wheel]
packages = ["pythainlp"]
[tool.hatch.build.targets.sdist]
include = [
"pythainlp/",
"tests/",
"LICENSE",
"README.md",
]
[tool.bandit]
# Skip tests that produce known false positives or are accepted risks.
# B110: Try/Except/Pass. Accepted pattern in optional-dependency loading.
skips = ["B110"]
[tool.bumpversion]
current_version = "5.4.0"
commit = true
# Tag the merged commit on main by hand (see release.md).
tag = false
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+)(?P<build>\\d+))?"
serialize = [
"{major}.{minor}.{patch}-{release}{build}",
"{major}.{minor}.{patch}",
]
[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'
[[tool.bumpversion.files]]
filename = "pythainlp/__init__.py"
search = '__version__ = "{current_version}"'
replace = '__version__ = "{new_version}"'
[[tool.bumpversion.files]]
filename = "CITATION.cff"
search = 'version: {current_version}'
replace = 'version: {new_version}'
[[tool.bumpversion.files]]
filename = "CITATION.cff"
regex = true
search = 'date-released: \d{{4}}-\d{{2}}-\d{{2}}'
replace = 'date-released: {now:%Y-%m-%d}'
[[tool.bumpversion.files]]
filename = "codemeta.json"
search = '"version": "{current_version}"'
replace = '"version": "{new_version}"'
[[tool.bumpversion.files]]
filename = "codemeta.json"
regex = true
search = '"dateModified": "\d{{4}}-\d{{2}}-\d{{2}}"'
replace = '"dateModified": "{now:%Y-%m-%d}"'
[[tool.bumpversion.files]]
filename = "README.md"
search = '[{current_version}](https://github.com/PyThaiNLP/pythainlp/releases)'
replace = '[{new_version}](https://github.com/PyThaiNLP/pythainlp/releases)'
[[tool.bumpversion.files]]
filename = "README.md"
search = 'compare/v{current_version}...HEAD'
replace = 'compare/v{new_version}...HEAD'
[[tool.bumpversion.files]]
filename = "README_TH.md"
search = '[{current_version}](https://github.com/PyThaiNLP/pythainlp/releases)'
replace = '[{new_version}](https://github.com/PyThaiNLP/pythainlp/releases)'
[[tool.bumpversion.files]]
filename = "README_TH.md"
search = 'compare/v{current_version}...HEAD'
replace = 'compare/v{new_version}...HEAD'
[tool.bumpversion.parts.release]
optional_value = "prod"
first_value = "dev"
values = ["dev", "beta", "prod"]
# Test coverage expectations:
# - Overall: at least 80%.
# - New and changed code: at least 95%. CI (diff-cover,
# .github/workflows/unittest.yml) gates it, except in the noauto modules
# listed in tests/diff-cover-noauto.txt. CI cannot run those, so it only
# reports them.
# - AI agents: aim at near 100% line and branch coverage of the code they
# add or change, and cover every function they touch.
[tool.coverage.run]
source = ["pythainlp"]
[[tool.pitloom.creator]]
name = "Wannaphong Phatthiyaphaibun"
email = "wannaphong@pythainlp.org"
type = "person"
# Read by the Pitloom GitHub Action in .github/workflows/pypi-publish.yml.
# "magika" fails the SBOM generation if magika is not installed, instead of
# falling back to guessing from the file extension.
[tool.pitloom.content-type]
enabled = true
method = "magika"
# CRFsuite models: magika has no label for them and guesses STL or NumPy.
# CRFsuite has no registered media type.
[[tool.pitloom.content-type.override]]
pattern = "pythainlp/corpus/*.crfsuite"
content-type = "application/octet-stream"
[[tool.pitloom.content-type.override]]
pattern = "pythainlp/corpus/*.model"
content-type = "application/octet-stream"
# magika detects SQLite, but Pitloom gives application/octet-stream.
[[tool.pitloom.content-type.override]]
pattern = "pythainlp/corpus/*.db"
content-type = "application/vnd.sqlite3"
# Docstring checks run by Codacy (pydocstyle); same as .pydocstyle.ini.
# Summary on the second line (D213) is the project style, so D212 is off.
# D211 is used over D203.
[tool.pydocstyle]
ignore = ["D203", "D212"]
[tool.ruff]
indent-width = 4
line-length = 79
target-version = "py39"
[tool.ruff.format]
docstring-code-format = true
indent-style = "space"
line-ending = "auto"
quote-style = "double"
skip-magic-trailing-comma = false
[tool.ruff.lint]
# See the test coverage targets at [tool.coverage.run].
# Flag errors (`C901`) whenever the complexity level exceeds this value.
# The limit is 10. Unrefactored functions carry a `# noqa: C901` marked
# `# phase2-todo`.
mccabe.max-complexity = 10
# flake8 owns the CCR (cognitive complexity) codes; keep their `# noqa`.
external = ["CCR"]
select = [
"D1",
"D200",
"D202",
"D205",
"D209",
"D213",
"D214",
"D300",
"D400",
"D401",
"D413",
"D415",
"A002",
"E",
"EXE001",
"F",
"I",
"ICN001",
"INP001",
"W",
"S",
"TC",
"B",
"BLE001",
"C4",
"FA100",
"FLY002",
"FURB",
"ISC",
"PGH003",
"PERF401",
"PERF402",
"PERF403",
"PIE",
"PLE",
"PLW2901",
"PYI034",
"RET",
"RUF005",
"RUF012",
"RUF010",
"RUF022",
"RUF100",
"RUF102",
"SIM",
"SLOT000",
"UP006",
"UP015",
"UP031",
"UP033",
"UP035",
"UP037",
"C901",
"F401",
"F811",
"F841",
"W291",
"W293",
]
# Some rules are ignored for now; we can consider enabling them in the future.
# B905 (zip strict=) needs Python 3.10.
# RET504 (assign then return), SIM108 (ternary), and SIM117 (nested with)
# are style choices that often hurt readability.
extend-ignore = ["B905", "E501", "RET504", "SIM108", "SIM117"]
[tool.ruff.lint.per-file-ignores]
# E402: these packages import in a fixed order to avoid circular imports.
"pythainlp/__init__.py" = ["E402"]
"pythainlp/corpus/__init__.py" = ["E402"]
"pythainlp/corpus/wordnet.py" = ["E402"]
"pythainlp/soundex/__init__.py" = ["E402"]
"pythainlp/spell/__init__.py" = ["E402"]
"pythainlp/summarize/__init__.py" = ["E402"]
"pythainlp/tokenize/__init__.py" = ["E402"]
# S101 (assert) is not allowed in production code. Tests and notebooks may use it.
# B010 (setattr) is for attributes that tests set on purpose.
# D1 (missing docstring) applies to the pythainlp package only.
"tests/**" = ["B010", "D1", "S101"]
"notebooks/**" = ["D1", "S101"]
"examples/**" = ["D1", "INP001"]
"build_tools/**" = ["D1"]
"docs/**" = ["D1"]
[tool.tox]
env_list = ["py39", "py310", "py311", "py312", "py313", "py314", "pypy310", "pypy311", "ruff", "flake8", "mypy"]
skip_missing_interpreters = true
[tool.tox.env_run_base]
commands = [["python", "-m", "unittest", "tests.core", "tests.compact"]]
extras = ["compact"]
[tool.tox.env.pypy310]
basepython = "pypy3.10"
[tool.tox.env.pypy311]
basepython = "pypy3.11"
# The lint environments below mirror .github/workflows/lint.yml and mypy.yml.
[tool.tox.env.ruff]
basepython = ["python"]
commands = [
["ruff", "check", "--config", "pyproject.toml", "pythainlp", "tests", "examples", "notebooks"],
["ruff", "format", "--check", "--config", "pyproject.toml", "pythainlp", "tests", "examples", "notebooks"],
]
deps = ["ruff==0.17.4"]
skip_install = true
[tool.tox.env.flake8]
basepython = ["python"]
commands = [["flake8", "pythainlp"]]
deps = [
"flake8==7.4.1; python_version < '3.11'",
"flake8==7.5.0; python_version >= '3.11'",
"flake8-cognitive-complexity==0.1.0",
]
skip_install = true
[tool.tox.env.mypy]
commands = [["mypy", "pythainlp", "tests"]]
# Same version as mypy.yml.
deps = ["mypy==2.4.1"]
extras = []
[tool.mypy]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
pretty = true
python_version = "3.10"
show_column_numbers = true
show_error_code_links = true
show_error_context = true
strict = true
strict_bytes = true
strict_equality = true
strict_equality_for_none = true
strict_optional = true
warn_no_return = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true
[[tool.mypy.overrides]]
module = ["tests.*"]
disallow_untyped_defs = false
# Treat optional dependencies as untyped, whether installed or not.
# Without "follow_imports = skip", mypy analyzes installed packages
# (for example, torch) with python_version = "3.10" and fails on
# newer syntax.
[[tool.mypy.overrides]]
module = [
"attacut.*",
"attaparse.*",
"bpemb.*",
"budoux.*",
"emoji.*",
"epitran.*",
"esupar.*",
"fairseq.*",
"fastai.*",
"fastcoref.*",
"gensim.*",
"huggingface_hub.*",
"icu.*",
"importlib_resources",
"importlib_resources.*",
"khamyo.*",
"khanaa.*",
"multiel.*",
"nltk.*",
"nlpo3.*",
"numpy.*",
"onnx.*",
"onnxruntime.*",
"oskut.*",
"pandas.*",
"panphon.*",
"phunspell.*",
"pycrfsuite.*",
"pyicu.*",
"sacremoses.*",
"sefr_cut.*",
"sentencepiece.*",
"sentence_transformers.*",
"spacy.*",
"spacy_thai.*",
"ssg.*",
"stanza.*",
"symspellpy.*",
"thai_nner.*",
"tltk.*",
"torch.*",
"tqdm.*",
"transformers.*",
"ufal.*",
"ufal.chu_liu_edmonds.*",
"word2word.*",
"wtpsplit.*",
"wunsen.*",
"yaml.*",
]
follow_imports = "skip"
ignore_missing_imports = true
[tool.pylint.main]
disable = [
"import-error",
"no-name-in-module",
"too-few-public-methods",
"too-many-arguments",
"too-many-locals",
"too-many-branches",
"too-many-statements",
]