Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stweil opened this issue Mar 15, 2024 · 6 comments · Fixed by #14
Closed

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

stweil opened this issue Mar 15, 2024 · 6 comments · Fixed by #14
Assignees

Comments

@stweil
Copy link
Contributor

stweil commented Mar 15, 2024

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
Copy link
Contributor Author

stweil commented Mar 15, 2024

The TypeError was introduced by commit 644bf70:

644bf7050d64b0847ce8bef0cda88004c37ee692 is the first bad commit
commit 644bf7050d64b0847ce8bef0cda88004c37ee692
Author: Konstantin Baierer <[email protected]>
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
Copy link
Contributor Author

stweil commented Mar 15, 2024

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

@kba
Copy link
Member

kba commented Apr 11, 2024

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.

kba added a commit that referenced this issue Apr 11, 2024
stweil pushed a commit to stweil/ocrd_froc that referenced this issue Apr 14, 2024
@stweil
Copy link
Contributor Author

stweil commented Apr 14, 2024

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

stweil pushed a commit to stweil/ocrd_froc that referenced this issue Apr 14, 2024
@stweil
Copy link
Contributor Author

stweil commented Apr 14, 2024

@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).

kba added a commit that referenced this issue Apr 15, 2024
@kba kba mentioned this issue Apr 15, 2024
stweil pushed a commit to stweil/ocrd_froc that referenced this issue Apr 15, 2024
stweil pushed a commit to stweil/ocrd_froc that referenced this issue Apr 15, 2024
@stweil stweil closed this as completed Apr 15, 2024
@stweil stweil reopened this Apr 15, 2024
@stweil
Copy link
Contributor Author

stweil commented Apr 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants