-
Notifications
You must be signed in to change notification settings - Fork 32
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
Processor.module: handle namespace pkg case #917
Conversation
CI failure is only on macos, and very strange: all tests seem to pass, but the overall status is still failure. I don't have permissions to rerun on CircleCI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had not considered namespace packages as used by @qurator-spk, also for the binarization and the old textline detector. Elegant solution LGTM
# 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__ |
There was a problem hiding this comment.
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__'
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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!
fixes #916