cihai-cli 0.25.0__tar.gz → 0.27.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/PKG-INFO +2 -2
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/pyproject.toml +13 -5
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/src/cihai_cli/__about__.py +2 -1
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/src/cihai_cli/cli.py +23 -16
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/conftest.py +11 -8
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/test_cli.py +11 -8
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/LICENSE +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/README.md +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/src/cihai_cli/__init__.py +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/__init__.py +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_DictionaryIndices.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_DictionaryLikeData.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_IRGSources.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_NumericValues.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_OtherMappings.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_RadicalStrokeCounts.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_Readings.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/Unihan_Variants.txt +0 -0
- {cihai_cli-0.25.0 → cihai_cli-0.27.0}/tests/fixtures/test_config.yml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cihai-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.27.0
|
|
4
4
|
Summary: Command line frontend for the cihai CJK language library
|
|
5
5
|
Home-page: https://cihai-cli.git-pull.com
|
|
6
6
|
License: MIT
|
|
@@ -25,7 +25,7 @@ Classifier: Topic :: Software Development :: Localization
|
|
|
25
25
|
Classifier: Topic :: System :: Shells
|
|
26
26
|
Classifier: Topic :: Utilities
|
|
27
27
|
Requires-Dist: PyYAML
|
|
28
|
-
Requires-Dist: cihai (>=0.
|
|
28
|
+
Requires-Dist: cihai (>=0.32.0,<0.33.0)
|
|
29
29
|
Project-URL: Bug Tracker, https://github.com/cihai/cihai-cli/issues
|
|
30
30
|
Project-URL: Documentation, https://cihai-cli.git-pull.com
|
|
31
31
|
Project-URL: Q & A, https://github.com/cihai/cihai-cli/discussions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "cihai-cli"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.27.0"
|
|
4
4
|
description = "Command line frontend for the cihai CJK language library"
|
|
5
5
|
license = "MIT"
|
|
6
6
|
authors = ["Tony Narlock <tony@git-pull.com>"]
|
|
@@ -58,7 +58,7 @@ Repository = "https://github.com/cihai/cihai-cli"
|
|
|
58
58
|
|
|
59
59
|
[tool.poetry.dependencies]
|
|
60
60
|
python = "^3.8"
|
|
61
|
-
cihai = "~0.
|
|
61
|
+
cihai = "~0.32.0"
|
|
62
62
|
PyYAML = "*"
|
|
63
63
|
|
|
64
64
|
[tool.poetry.group.docs.dependencies]
|
|
@@ -116,13 +116,18 @@ ignore_missing_imports = true
|
|
|
116
116
|
|
|
117
117
|
[tool.ruff]
|
|
118
118
|
target-version = "py38"
|
|
119
|
+
|
|
120
|
+
[tool.ruff.lint]
|
|
119
121
|
select = [
|
|
120
122
|
"E", # pycodestyle
|
|
121
123
|
"F", # pyflakes
|
|
122
124
|
"I", # isort
|
|
123
125
|
"UP", # pyupgrade
|
|
126
|
+
"A", # flake8-builtins
|
|
124
127
|
"B", # flake8-bugbear
|
|
125
128
|
"C4", # flake8-comprehensions
|
|
129
|
+
"COM", # flake8-commas
|
|
130
|
+
"EM", # flake8-errmsg
|
|
126
131
|
"Q", # flake8-quotes
|
|
127
132
|
"PTH", # flake8-use-pathlib
|
|
128
133
|
"SIM", # flake8-simplify
|
|
@@ -131,15 +136,18 @@ select = [
|
|
|
131
136
|
"RUF", # Ruff-specific rules
|
|
132
137
|
"D", # pydocstyle
|
|
133
138
|
]
|
|
139
|
+
ignore = [
|
|
140
|
+
"COM812", # missing trailing comma, ruff format conflict
|
|
141
|
+
]
|
|
134
142
|
|
|
135
|
-
[tool.ruff.isort]
|
|
143
|
+
[tool.ruff.lint.isort]
|
|
136
144
|
known-first-party = ["unihan_etl", "cihai"]
|
|
137
145
|
combine-as-imports = true
|
|
138
146
|
|
|
139
|
-
[tool.ruff.pydocstyle]
|
|
147
|
+
[tool.ruff.lint.pydocstyle]
|
|
140
148
|
convention = "numpy"
|
|
141
149
|
|
|
142
|
-
[tool.ruff.per-file-ignores]
|
|
150
|
+
[tool.ruff.lint.per-file-ignores]
|
|
143
151
|
"*/__init__.py" = ["F401"]
|
|
144
152
|
|
|
145
153
|
[tool.pytest.ini_options]
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""Metadata for cihai_cli package."""
|
|
2
|
+
|
|
2
3
|
__title__ = "cihai-cli"
|
|
3
4
|
__package_name__ = "cihai_cli"
|
|
4
|
-
__version__ = "0.
|
|
5
|
+
__version__ = "0.27.0"
|
|
5
6
|
__description__ = "Command line frontend for the cihai CJK language library"
|
|
6
7
|
__author__ = "Tony Narlock"
|
|
7
8
|
__email__ = "tony@git-pull.com"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""CLI functionality for cihai-cli."""
|
|
2
|
+
|
|
2
3
|
import argparse
|
|
3
4
|
import logging
|
|
4
5
|
import sys
|
|
@@ -12,6 +13,9 @@ from unihan_etl.__about__ import __version__ as unihan_etl_version
|
|
|
12
13
|
|
|
13
14
|
from .__about__ import __version__
|
|
14
15
|
|
|
16
|
+
log = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
15
19
|
#: fields which are human friendly
|
|
16
20
|
HUMAN_UNIHAN_FIELDS = [
|
|
17
21
|
"char",
|
|
@@ -59,7 +63,8 @@ def create_parser() -> argparse.ArgumentParser:
|
|
|
59
63
|
info_parser = subparsers.add_parser("info", help=INFO_SHORT_HELP)
|
|
60
64
|
create_info_subparser(info_parser)
|
|
61
65
|
reverse_parser = subparsers.add_parser(
|
|
62
|
-
"reverse",
|
|
66
|
+
"reverse",
|
|
67
|
+
help='Search all info for character matches, e.g. "good"',
|
|
63
68
|
)
|
|
64
69
|
create_reverse_subparser(reverse_parser)
|
|
65
70
|
|
|
@@ -89,18 +94,18 @@ def cli(_args: t.Optional[t.List[str]] = None) -> None:
|
|
|
89
94
|
c = Cihai.from_file(args.config_file) if args.config_file else Cihai()
|
|
90
95
|
|
|
91
96
|
if not c.unihan.is_bootstrapped:
|
|
92
|
-
|
|
97
|
+
log.info("Bootstrapping Unihan database")
|
|
93
98
|
c.unihan.bootstrap(options=c.config.get("unihan_options", {}))
|
|
94
99
|
|
|
95
100
|
if args.subparser_name is None:
|
|
96
101
|
parser.print_help()
|
|
97
102
|
return
|
|
98
|
-
|
|
103
|
+
if args.subparser_name == "info":
|
|
99
104
|
command_info(c=c, char=args.char, show_all=args.show_all)
|
|
100
105
|
elif args.subparser_name == "reverse":
|
|
101
106
|
command_reverse(c=c, char=args.char, show_all=args.show_all)
|
|
102
107
|
else:
|
|
103
|
-
|
|
108
|
+
log.info(f"No subparser for {args.subparser_name}")
|
|
104
109
|
|
|
105
110
|
|
|
106
111
|
def create_info_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
|
|
@@ -121,7 +126,7 @@ def command_info(c: Cihai, char: str, show_all: bool) -> None:
|
|
|
121
126
|
query = c.unihan.lookup_char(char).first()
|
|
122
127
|
attrs = {}
|
|
123
128
|
if not query:
|
|
124
|
-
|
|
129
|
+
log.info(f"No records found for {char}")
|
|
125
130
|
sys.exit()
|
|
126
131
|
for col, _, _ in query.__table__.columns._collection:
|
|
127
132
|
value = getattr(query, col)
|
|
@@ -129,8 +134,8 @@ def command_info(c: Cihai, char: str, show_all: bool) -> None:
|
|
|
129
134
|
if not show_all and str(col) not in HUMAN_UNIHAN_FIELDS:
|
|
130
135
|
continue
|
|
131
136
|
attrs[str(col)] = value
|
|
132
|
-
|
|
133
|
-
yaml.safe_dump(attrs, allow_unicode=True, default_flow_style=False).strip("\n")
|
|
137
|
+
log.info(
|
|
138
|
+
yaml.safe_dump(attrs, allow_unicode=True, default_flow_style=False).strip("\n"),
|
|
134
139
|
)
|
|
135
140
|
|
|
136
141
|
|
|
@@ -153,7 +158,7 @@ def command_reverse(c: Cihai, char: str, show_all: bool) -> None:
|
|
|
153
158
|
"""Lookup a word or phrase by searching definitions."""
|
|
154
159
|
query = c.unihan.reverse_char([char])
|
|
155
160
|
if not query.count():
|
|
156
|
-
|
|
161
|
+
log.info("No records found for %s" % char)
|
|
157
162
|
sys.exit()
|
|
158
163
|
for k in query:
|
|
159
164
|
attrs = {}
|
|
@@ -163,22 +168,24 @@ def command_reverse(c: Cihai, char: str, show_all: bool) -> None:
|
|
|
163
168
|
if not show_all and str(c) not in HUMAN_UNIHAN_FIELDS:
|
|
164
169
|
continue
|
|
165
170
|
attrs[str(c)] = value
|
|
166
|
-
|
|
171
|
+
log.info(
|
|
167
172
|
yaml.safe_dump(attrs, allow_unicode=True, default_flow_style=False).strip(
|
|
168
|
-
"\n"
|
|
169
|
-
)
|
|
173
|
+
"\n",
|
|
174
|
+
),
|
|
170
175
|
)
|
|
171
|
-
|
|
176
|
+
log.info("--------")
|
|
172
177
|
|
|
173
178
|
|
|
174
179
|
def setup_logger(
|
|
175
|
-
logger: t.Optional[logging.Logger] = None,
|
|
180
|
+
logger: t.Optional[logging.Logger] = None,
|
|
181
|
+
level: str = "INFO",
|
|
176
182
|
) -> None:
|
|
177
183
|
"""Configure logging for CLI use.
|
|
178
184
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
185
|
+
Parameters
|
|
186
|
+
----------
|
|
187
|
+
logger : :py:class:`Logger`
|
|
188
|
+
Instance of logger, if one set up.
|
|
182
189
|
"""
|
|
183
190
|
if not logger:
|
|
184
191
|
logger = logging.getLogger()
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Pytest configuration."""
|
|
2
|
+
|
|
2
3
|
import pathlib
|
|
3
4
|
import typing as t
|
|
4
5
|
import zipfile
|
|
@@ -11,31 +12,31 @@ if t.TYPE_CHECKING:
|
|
|
11
12
|
from cihai.types import UntypedDict as UnihanOptions
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
@pytest.fixture
|
|
15
|
+
@pytest.fixture()
|
|
15
16
|
def tests_path() -> pathlib.Path:
|
|
16
17
|
"""Return tests/ directory."""
|
|
17
18
|
return pathlib.Path(__file__).parent
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
@pytest.fixture
|
|
21
|
+
@pytest.fixture()
|
|
21
22
|
def fixture_path(tests_path: pathlib.Path) -> pathlib.Path:
|
|
22
23
|
"""Return tests/fixtures/ directory."""
|
|
23
24
|
return tests_path / "fixtures"
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
@pytest.fixture
|
|
27
|
+
@pytest.fixture()
|
|
27
28
|
def test_config_file(fixture_path: pathlib.Path) -> pathlib.Path:
|
|
28
29
|
"""Return test_config.yml file."""
|
|
29
30
|
return fixture_path / "test_config.yml"
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
@pytest.fixture
|
|
33
|
+
@pytest.fixture()
|
|
33
34
|
def zip_path(tmp_path: pathlib.Path) -> pathlib.Path:
|
|
34
35
|
"""Return Unihan.zip in temporary path."""
|
|
35
36
|
return tmp_path / "Unihan.zip"
|
|
36
37
|
|
|
37
38
|
|
|
38
|
-
@pytest.fixture
|
|
39
|
+
@pytest.fixture()
|
|
39
40
|
def zip_file(zip_path: pathlib.Path, fixture_path: pathlib.Path) -> zipfile.ZipFile:
|
|
40
41
|
"""Create and return ZipFile."""
|
|
41
42
|
_files = []
|
|
@@ -48,9 +49,11 @@ def zip_file(zip_path: pathlib.Path, fixture_path: pathlib.Path) -> zipfile.ZipF
|
|
|
48
49
|
return zf
|
|
49
50
|
|
|
50
51
|
|
|
51
|
-
@pytest.fixture
|
|
52
|
+
@pytest.fixture()
|
|
52
53
|
def unihan_options(
|
|
53
|
-
zip_file: zipfile.ZipFile,
|
|
54
|
+
zip_file: zipfile.ZipFile,
|
|
55
|
+
zip_path: pathlib.Path,
|
|
56
|
+
tmp_path: pathlib.Path,
|
|
54
57
|
) -> "UnihanOptions":
|
|
55
58
|
"""Return UnihanOptions for fixture."""
|
|
56
59
|
return {
|
|
@@ -60,7 +63,7 @@ def unihan_options(
|
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
|
|
63
|
-
@pytest.fixture(
|
|
66
|
+
@pytest.fixture()
|
|
64
67
|
def tmpdb_file(tmpdir: pathlib.Path) -> pathlib.Path:
|
|
65
68
|
"""Return test SQLite database."""
|
|
66
69
|
return tmpdir / "test.db"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""CLI tests for cihai-cli."""
|
|
2
|
+
|
|
2
3
|
import contextlib
|
|
3
4
|
import pathlib
|
|
4
5
|
import typing as t
|
|
@@ -36,6 +37,7 @@ def test_cli(
|
|
|
36
37
|
def test_cli_reflects_after_bootstrap(
|
|
37
38
|
tmp_path: pathlib.Path,
|
|
38
39
|
capsys: pytest.CaptureFixture[str],
|
|
40
|
+
caplog: pytest.LogCaptureFixture,
|
|
39
41
|
monkeypatch: pytest.MonkeyPatch,
|
|
40
42
|
tmpdb_file: pathlib.Path,
|
|
41
43
|
unihan_options: "UnihanOptions",
|
|
@@ -51,28 +53,30 @@ def test_cli_reflects_after_bootstrap(
|
|
|
51
53
|
}
|
|
52
54
|
config_file = tmp_path / "config.yml"
|
|
53
55
|
config_file.write_text(
|
|
54
|
-
yaml.dump(config, default_flow_style=False),
|
|
56
|
+
yaml.dump(config, default_flow_style=False),
|
|
57
|
+
encoding="utf-8",
|
|
55
58
|
)
|
|
56
59
|
|
|
57
60
|
try:
|
|
58
61
|
cli(["-c", str(config_file), "info", "㐀"])
|
|
59
62
|
except SystemExit:
|
|
60
|
-
|
|
61
|
-
output = "".join(list(result.out))
|
|
63
|
+
output = "".join(list(caplog.messages) + list(capsys.readouterr().out))
|
|
62
64
|
assert "Bootstrapping Unihan database" in output
|
|
63
65
|
|
|
66
|
+
caplog.clear()
|
|
67
|
+
|
|
64
68
|
try:
|
|
65
69
|
cli(["-c", str(config_file), "info"])
|
|
66
70
|
except SystemExit:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
assert "Bootstrapping" in output
|
|
71
|
+
output = "".join(list(capsys.readouterr().err))
|
|
72
|
+
assert "cihai info" in output
|
|
70
73
|
|
|
71
74
|
|
|
72
75
|
@pytest.mark.parametrize("flag", ["-V", "--version"])
|
|
73
76
|
def test_cli_version(
|
|
74
77
|
tmp_path: pathlib.Path,
|
|
75
78
|
capsys: pytest.CaptureFixture[str],
|
|
79
|
+
caplog: pytest.LogCaptureFixture,
|
|
76
80
|
monkeypatch: pytest.MonkeyPatch,
|
|
77
81
|
flag: str,
|
|
78
82
|
) -> None:
|
|
@@ -80,8 +84,7 @@ def test_cli_version(
|
|
|
80
84
|
try:
|
|
81
85
|
cli([flag])
|
|
82
86
|
except SystemExit:
|
|
83
|
-
|
|
84
|
-
output = "".join(list(result.out))
|
|
87
|
+
output = "".join(list(caplog.messages) + list(capsys.readouterr().out))
|
|
85
88
|
assert "cihai-cli" in output
|
|
86
89
|
assert "cihai" in output
|
|
87
90
|
assert "unihan-etl" in output
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|