• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PyThaiNLP / pythainlp / 21666541177

04 Feb 2026 09:46AM UTC coverage: 65.208% (-0.01%) from 65.219%
21666541177

push

github

web-flow
Merge pull request #1274 from PyThaiNLP/copilot/add-type-annotations-coverage

Fix lazy import bugs and Python 3.9 type hint compatibility

147 of 237 new or added lines in 62 files covered. (62.03%)

6 existing lines in 6 files now uncovered.

5900 of 9048 relevant lines covered (65.21%)

0.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/pythainlp/cli/__init__.py
1
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
2
# SPDX-FileType: SOURCE
3
# SPDX-License-Identifier: Apache-2.0
4
"""Command line helpers."""
5

6
from __future__ import annotations
1✔
7

8
import io
1✔
9
import sys
1✔
10
from argparse import ArgumentError, ArgumentParser
1✔
11
from typing import TYPE_CHECKING
1✔
12

13
from pythainlp.cli import benchmark, data, misspell, soundex, tag, tokenize
1✔
14

15
if TYPE_CHECKING:
16
    from types import ModuleType
17

18
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")  # type: ignore[assignment]
1✔
19
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8")  # type: ignore[assignment]
1✔
20

21
# a command should start with a verb when possible
22
COMMANDS: list[str] = sorted(
1✔
23
    ["data", "soundex", "tag", "tokenize", "benchmark", "misspell"]
24
)
25

26
CLI_NAME: str = "thainlp"
1✔
27

28

29
def make_usage(command: str) -> dict[str, str]:
1✔
30
    prog = f"{CLI_NAME} {command}"
1✔
31

32
    return {"prog": prog, "usage": f"{prog} [options]"}
1✔
33

34

35
def exit_if_empty(command: str, parser: ArgumentParser) -> None:
1✔
36
    """Print help and exit if command is empty.
37

38
    :param command: command from command line
39
    :type command: str
40
    :param parser: parser object of the app
41
    :type parser: ArgumentParser
42
    """
43
    if not command:
1✔
44
        if parser:
1✔
45
            parser.print_help()
×
46
        raise ArgumentError(None, "No command provided.")
1✔
47

48

49
if __name__ == "__main__":
1✔
50
    # Create a simple mapping from command name to the imported module
NEW
51
    COMMAND_MAP: dict[str, ModuleType] = {
×
52
        "tokenize": tokenize,
53
        "soundex": soundex,
54
        "tag": tag,
55
        "benchmark": benchmark,
56
        "misspell": misspell,
57
        "data": data,
58
    }
59

60
    # Check if a command was provided and if it's one we know
61
    if len(sys.argv) > 1 and sys.argv[1] in COMMAND_MAP:
×
NEW
62
        command: str = sys.argv[1]
×
63
        COMMAND_MAP[command].run()
×
64
    else:
65
        if len(sys.argv) < 2:
×
66
            print(
×
67
                f"Error: No command provided. Choose one of: {list(COMMAND_MAP.keys())}",
68
                file=sys.stderr,
69
            )
70
        else:
71
            print(f"Error: Unknown command '{sys.argv[1]}'", file=sys.stderr)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc