Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ocrd/ocrd/processor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,16 @@ def module(self):
"""
The top-level module this processor belongs to.
"""
return self.__module__.split('.')[0]
# find shortest prefix path that is not just a namespace package
fqname = ''
for name in self.__module__.split('.'):
if fqname:
fqname += '.'
fqname += name
if sys.modules[fqname].__file__:
return fqname
# fall-back
return self.__module__
Comment on lines +250 to +259
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kba unfortunately, this still does not seem to work:

ocrd resmgr list-installed -e ocrd-eynollah-segment
Traceback (most recent call last):
  File "/bin/ocrd-eynollah-segment", line 8, in <module>
    sys.exit(main())
  File "/lib/python3.6/site-packages/click/core.py", line 1134, in __call__
    return self.main(*args, **kwargs)
  File "/lib/python3.6/site-packages/click/core.py", line 1059, in main
    rv = self.invoke(ctx)
  File "/lib/python3.6/site-packages/click/core.py", line 1401, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/lib/python3.6/site-packages/click/core.py", line 767, in invoke
    return __callback(*args, **kwargs)
  File "/lib/python3.6/site-packages/qurator/eynollah/ocrd_cli.py", line 8, in main
    return ocrd_cli_wrap_processor(EynollahProcessor, *args, **kwargs)
  File "/lib/python3.6/site-packages/ocrd/decorators/__init__.py", line 51, in ocrd_cli_wrap_processor
    list_resources=list_resources
  File "/lib/python3.6/site-packages/qurator/eynollah/processor.py", line 30, in __init__
    super().__init__(*args, **kwargs)
  File "/lib/python3.6/site-packages/ocrd/processor/base.py", line 109, in __init__
    print(self.moduledir)
  File "/lib/python3.6/site-packages/ocrd/processor/base.py", line 266, in moduledir
    return resource_filename(self.module, '')
  File "/lib/python3.6/site-packages/ocrd/processor/base.py", line 256, in module
    if sys.modules[fqname].__file__:
AttributeError: module 'qurator' has no attribute '__file__'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #985 for a fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, I cannot reproduce this, I've tested it with 3.6 to 3.9 with fresh venvs, installed core and eynollah and

import qurator
qurator.__file__

never raises AttributeError for __file__. It is not set because it's a namespace module but a module not having `file at all seems very wrong to me. Are you sure this is not a broken installation or do you have an idea how to reproduce this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you tried 3.6, too? I can see __file__ from 3.7 onwards. (In other cases of namespace packages, I do get the attribute even in 3.6. Perhaps it depends on the concrete method of how it was declared?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not try it in a fresh 3.6 venv apparently. I did now and can reproduce (which took ages because of opencv compilation btw). Apparently namespace modules in Python <= 3.6 have only ['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__'] as attributes.

So I can confirm it is a problem in 3.6 and while we do not support it anymore, there's no reason to actively break it. So thanks, I'll merge the PR!


@property
def moduledir(self):
Expand Down
2 changes: 1 addition & 1 deletion repo/spec