ndlocr-lite 2.0.0.dev0__tar.gz → 2.0.0.dev1__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.
- {ndlocr_lite-2.0.0.dev0/src/ndlocr_lite.egg-info → ndlocr_lite-2.0.0.dev1}/PKG-INFO +1 -1
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/pyproject.toml +1 -1
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1/src/ndlocr_lite.egg-info}/PKG-INFO +1 -1
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndlocr_lite.egg-info/SOURCES.txt +1 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ocr.py +13 -3
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/version.py +1 -1
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/tests/test_cli_arguments.py +27 -0
- ndlocr_lite-2.0.0.dev1/tests/test_output_directory.py +74 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/tests/test_set_version.py +9 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/LICENCE +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/LICENCE_DEPENDENCEIES +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/MANIFEST.in +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/README.md +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/ndlocr-lite-gui/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/ndlocr-lite-gui/assets/icon.png +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/ndlocr-lite-gui/gui_config.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/ndlocr-lite-gui/main.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/requirements.txt +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/setup.cfg +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/setup.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/cli.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/config/NDLmoji.yaml +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/config/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/config/ndl.yaml +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/deim.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/model/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/model_download.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndl_parser.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndlocr_lite.egg-info/dependency_links.txt +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndlocr_lite.egg-info/entry_points.txt +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndlocr_lite.egg-info/requires.txt +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndlocr_lite.egg-info/top_level.txt +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/optional_features/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/optional_features/table_structure.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/parseq.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/pdf_output_utils.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/order/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/order/parse_xml.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/order/reorder.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/order/smooth_order.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/order/warichu_block.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/order/wrap_dataset.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/utils/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/utils/file.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/utils/logger.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/utils/time.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/utils/xml.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/xy_cut/__init__.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/xy_cut/block_xy_cut.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/reading_order/xy_cut/eval.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/tcy_wrapper.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/tools/ndlkoten2tei.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/uicomponent/localelabel.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/uicomponent/textdaisy.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/tests/test_gui_command.py +0 -0
- {ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/tests/test_model_download.py +0 -0
|
@@ -1448,8 +1448,11 @@ def process(args):
|
|
|
1448
1448
|
if len(inputpathlist)==0:
|
|
1449
1449
|
print("Images are not found.")
|
|
1450
1450
|
return
|
|
1451
|
-
|
|
1452
|
-
|
|
1451
|
+
try:
|
|
1452
|
+
os.makedirs(args.output, exist_ok=True)
|
|
1453
|
+
except OSError as exc:
|
|
1454
|
+
print(f"Failed to create output directory: {args.output}")
|
|
1455
|
+
print(f"Error: {exc}")
|
|
1453
1456
|
return
|
|
1454
1457
|
|
|
1455
1458
|
detector=get_detector(args)
|
|
@@ -1590,7 +1593,14 @@ def process(args):
|
|
|
1590
1593
|
|
|
1591
1594
|
def main(download_models=False):
|
|
1592
1595
|
import argparse
|
|
1596
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
1593
1597
|
from pathlib import Path
|
|
1598
|
+
application_version = __version__
|
|
1599
|
+
if download_models:
|
|
1600
|
+
try:
|
|
1601
|
+
application_version = version("ndlocr-lite")
|
|
1602
|
+
except PackageNotFoundError:
|
|
1603
|
+
pass
|
|
1594
1604
|
base_dir = Path(__file__).resolve().parent
|
|
1595
1605
|
parser = argparse.ArgumentParser(description="Arguments for NDLkotenOCR-Lite")
|
|
1596
1606
|
if download_models:
|
|
@@ -1620,7 +1630,7 @@ def main(download_models=False):
|
|
|
1620
1630
|
parser.add_argument("--device", type=str, required=False, help="Device use (cpu or cuda)", choices=["cpu", "cuda"], default="cpu")
|
|
1621
1631
|
parser.add_argument("--enable-tcy", action="store_true", dest="enable_tcy", default=False, help="Enable tate-chuu-yoko (縦中横) detection for vertical text (e.g. newspaper OCR)")
|
|
1622
1632
|
parser.add_argument("--json-only", action="store_true", help="Disable .xml and .txt output and only output JSON")
|
|
1623
|
-
parser.add_argument("--version", action="version", version=f"%(prog)s {
|
|
1633
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {application_version}")
|
|
1624
1634
|
if download_models:
|
|
1625
1635
|
from model_download import MODELS, resolve_model_paths
|
|
1626
1636
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import contextlib
|
|
2
2
|
import io
|
|
3
|
+
from importlib.metadata import PackageNotFoundError
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
import sys
|
|
5
6
|
import unittest
|
|
@@ -106,6 +107,32 @@ class CliArgumentsTest(unittest.TestCase):
|
|
|
106
107
|
ocr.main(download_models=True)
|
|
107
108
|
self.assertIn("ndlocr-lite gui", output.getvalue())
|
|
108
109
|
|
|
110
|
+
def test_packaged_version_uses_distribution_metadata(self):
|
|
111
|
+
with patch.object(sys, "argv", ["ndlocr-lite", "--version"]), patch(
|
|
112
|
+
"importlib.metadata.version", return_value="2.1.0.dev3"
|
|
113
|
+
) as version, patch("model_download.resolve_model_paths") as resolve, patch.object(
|
|
114
|
+
ocr, "process"
|
|
115
|
+
) as process, contextlib.redirect_stdout(io.StringIO()) as output:
|
|
116
|
+
with self.assertRaises(SystemExit) as error:
|
|
117
|
+
ocr.main(download_models=True)
|
|
118
|
+
self.assertEqual(error.exception.code, 0)
|
|
119
|
+
self.assertEqual(output.getvalue(), "ndlocr-lite 2.1.0.dev3\n")
|
|
120
|
+
version.assert_called_once_with("ndlocr-lite")
|
|
121
|
+
resolve.assert_not_called()
|
|
122
|
+
process.assert_not_called()
|
|
123
|
+
|
|
124
|
+
def test_version_without_distribution_uses_source_version(self):
|
|
125
|
+
for download_models in (False, True):
|
|
126
|
+
with self.subTest(download_models=download_models), patch.object(
|
|
127
|
+
sys, "argv", ["ndlocr-lite", "--version"]
|
|
128
|
+
), patch(
|
|
129
|
+
"importlib.metadata.version", side_effect=PackageNotFoundError("ndlocr-lite")
|
|
130
|
+
), contextlib.redirect_stdout(io.StringIO()) as output:
|
|
131
|
+
with self.assertRaises(SystemExit) as error:
|
|
132
|
+
ocr.main(download_models=download_models)
|
|
133
|
+
self.assertEqual(error.exception.code, 0)
|
|
134
|
+
self.assertEqual(output.getvalue(), f"ndlocr-lite {ocr.__version__}\n")
|
|
135
|
+
|
|
109
136
|
def test_download_error_does_not_start_processing(self):
|
|
110
137
|
argv = ["ndlocr-lite", "--sourceimg", "sample.png", "--output", "output"]
|
|
111
138
|
with patch.object(sys, "argv", argv), patch.object(ocr, "process") as process, patch(
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import contextlib
|
|
3
|
+
import io
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import sys
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
from unittest.mock import patch
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
12
|
+
import ocr
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OutputDirectoryTest(unittest.TestCase):
|
|
16
|
+
def setUp(self):
|
|
17
|
+
directory = tempfile.TemporaryDirectory()
|
|
18
|
+
self.addCleanup(directory.cleanup)
|
|
19
|
+
self.root = Path(directory.name)
|
|
20
|
+
self.args = argparse.Namespace(
|
|
21
|
+
sourcedir=None,
|
|
22
|
+
sourceimg="sample.png",
|
|
23
|
+
sourcepdf=None,
|
|
24
|
+
output=str(self.root / "parent" / "output"),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
def assert_processing_starts(self):
|
|
28
|
+
with patch.object(
|
|
29
|
+
ocr, "get_detector", side_effect=RuntimeError("model initialization reached")
|
|
30
|
+
) as detector:
|
|
31
|
+
with self.assertRaisesRegex(RuntimeError, "model initialization reached"):
|
|
32
|
+
ocr.process(self.args)
|
|
33
|
+
detector.assert_called_once_with(self.args)
|
|
34
|
+
|
|
35
|
+
def test_missing_output_and_parents_are_created(self):
|
|
36
|
+
self.assert_processing_starts()
|
|
37
|
+
self.assertTrue(Path(self.args.output).is_dir())
|
|
38
|
+
|
|
39
|
+
def test_existing_directory_contents_are_preserved(self):
|
|
40
|
+
output = Path(self.args.output)
|
|
41
|
+
output.mkdir(parents=True)
|
|
42
|
+
existing = output / "existing.txt"
|
|
43
|
+
existing.write_text("keep", encoding="utf-8")
|
|
44
|
+
self.assert_processing_starts()
|
|
45
|
+
self.assertEqual(existing.read_text(encoding="utf-8"), "keep")
|
|
46
|
+
|
|
47
|
+
def test_output_file_is_reported_without_starting_models(self):
|
|
48
|
+
output = self.root / "file"
|
|
49
|
+
output.write_text("keep", encoding="utf-8")
|
|
50
|
+
self.args.output = str(output)
|
|
51
|
+
with patch.object(ocr, "get_detector") as detector, contextlib.redirect_stdout(
|
|
52
|
+
io.StringIO()
|
|
53
|
+
) as messages:
|
|
54
|
+
ocr.process(self.args)
|
|
55
|
+
detector.assert_not_called()
|
|
56
|
+
self.assertIn(f"Failed to create output directory: {output}", messages.getvalue())
|
|
57
|
+
self.assertIn("Error:", messages.getvalue())
|
|
58
|
+
self.assertEqual(output.read_text(encoding="utf-8"), "keep")
|
|
59
|
+
|
|
60
|
+
def test_creation_permission_error_is_reported_without_starting_models(self):
|
|
61
|
+
with patch.object(
|
|
62
|
+
ocr.os, "makedirs", side_effect=PermissionError("permission denied")
|
|
63
|
+
), patch.object(ocr, "get_detector") as detector, contextlib.redirect_stdout(
|
|
64
|
+
io.StringIO()
|
|
65
|
+
) as messages:
|
|
66
|
+
ocr.process(self.args)
|
|
67
|
+
detector.assert_not_called()
|
|
68
|
+
self.assertIn("Failed to create output directory:", messages.getvalue())
|
|
69
|
+
self.assertIn("permission denied", messages.getvalue())
|
|
70
|
+
self.assertFalse(Path(self.args.output).exists())
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
unittest.main()
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
+
import runpy
|
|
2
3
|
import subprocess
|
|
3
4
|
import sys
|
|
4
5
|
import tempfile
|
|
6
|
+
import tomllib
|
|
5
7
|
import unittest
|
|
6
8
|
|
|
7
9
|
|
|
@@ -9,6 +11,13 @@ SCRIPT = Path(__file__).resolve().parents[1] / "src" / "set_version.py"
|
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
class SetVersionTest(unittest.TestCase):
|
|
14
|
+
def test_source_version_matches_project_version(self):
|
|
15
|
+
root = SCRIPT.parents[1]
|
|
16
|
+
with (root / "pyproject.toml").open("rb") as stream:
|
|
17
|
+
project = tomllib.load(stream)
|
|
18
|
+
namespace = runpy.run_path(str(root / "src" / "version.py"))
|
|
19
|
+
self.assertEqual(namespace["__version__"], project["project"]["version"])
|
|
20
|
+
|
|
12
21
|
def run_version(self, version, *options):
|
|
13
22
|
with tempfile.TemporaryDirectory() as directory:
|
|
14
23
|
root = Path(directory)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ndlocr_lite-2.0.0.dev0 → ndlocr_lite-2.0.0.dev1}/src/ndlocr_lite.egg-info/dependency_links.txt
RENAMED
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|