OCR-D / ocrd_froc

Apache License 2.0
7 stars 2 forks source link

TypeError: 'ocrd_froc.processor' is not a package #10

Closed stweil closed 6 months ago

stweil commented 8 months ago

make checkfor ocrd_all fails with the error message TypeError: 'ocrd_froc.processor' is not a package since at least ocrd_all v2024-02-01.

I get the same error when I just run ocrd-froc-recognize without any argument:

$ ocrd-froc-recognize
Traceback (most recent call last):
  File "/home/stweil/src/github/OCR-D/ocrd_all_test/venv/bin/ocrd-froc-recognize", line 5, in <module>
    from ocrd_froc.cli.ocrd_cli import cli
  File "/home/stweil/src/github/OCR-D/ocrd_all_test/venv/lib/python3.11/site-packages/ocrd_froc/cli/ocrd_cli.py", line 7, in <module>
    from ..processor import FROCProcessor
  File "/home/stweil/src/github/OCR-D/ocrd_all_test/venv/lib/python3.11/site-packages/ocrd_froc/processor.py", line 24, in <module>
    OCRD_TOOL = loads(resource_string(__name__, 'ocrd-tool.json'))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stweil/src/github/OCR-D/ocrd_all_test/venv/lib/python3.11/site-packages/ocrd_utils/introspect.py", line 58, in resource_string
    with open(resource_filename(pkg, fname), 'r', encoding='utf-8') as f:
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stweil/src/github/OCR-D/ocrd_all_test/venv/lib/python3.11/site-packages/ocrd_utils/introspect.py", line 54, in resource_filename
    ref = importlib_resources.files(pkg) / fname
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/resources/_common.py", line 22, in files
    return from_package(get_package(package))
                        ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/resources/_common.py", line 55, in get_package
    raise TypeError(f'{package!r} is not a package')
TypeError: 'ocrd_froc.processor' is not a package
stweil commented 8 months ago

The TypeError was introduced by commit 644bf7050d64b0847ce8bef0cda88004c37ee692:

644bf7050d64b0847ce8bef0cda88004c37ee692 is the first bad commit
commit 644bf7050d64b0847ce8bef0cda88004c37ee692
Author: Konstantin Baierer <unixprog@gmail.com>
Date:   Wed Jan 31 11:54:03 2024 +0100

    method -> ocr_method, make OCR optional ("none")

 Makefile                 |  5 +++++
 README.md                | 38 ++++++++++++++++++++------------------
 ocrd_froc/froc.py        | 14 ++++++++------
 ocrd_froc/network.py     |  6 ++----
 ocrd_froc/ocrd-tool.json | 29 ++++++++++++++++++++++++-----
 ocrd_froc/processor.py   | 27 ++++++++++++++-------------
 6 files changed, 73 insertions(+), 46 deletions(-)
 create mode 100644 Makefile
stweil commented 8 months ago

@kba, I narrowed down the TypeError further: if I revert the changes in ocrd_froc/processor.py, it no longer occurs.

kba commented 7 months ago

I don't understand why I cannot reproduce the problem, because there is indeed the top-level __init__.py missing. Nonetheless I'll prepare a PR which should fix the issue.

stweil commented 7 months ago

That PR does not fix the issue. I added a CI test which allows to reproduce it.

stweil commented 7 months ago

@kba, you could not reproduce the error because it does not occur with Python 3.7 and Python 3.8 as I just noticed. It requires Python 3.9 or later, but then occurs on macOS and Ubuntu. See https://github.com/stweil/ocrd_froc/actions/runs/8678819215/job/23796379466 for test results with different combinations of OS and Python version.

Those test results also show that running ocrd-froc-recognize terminates with an error (1) even with Python 3.7 and Python 3.8. Running ocrd without an argument returns success (0).

A modified CI which runs ocrd-froc-recognize --help passes with Python 3.7 and Python 3.8 (see https://github.com/stweil/ocrd_froc/actions/runs/8678879366).

stweil commented 7 months ago

The issue can be closed as soon as pull request #14 was merged.