Opened 2 years ago
Closed 2 years ago
#465 closed enhancement (fixed)
BibAuthorID: clean relative vs absolute imports
| Reported by: | simko | Owned by: | scarli |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | BibAuthorID | Version: | |
| Keywords: | Cc: |
Description
Due to usage of relative imports, one cannot run unit test before
installing them, as is usual for other modules:
$ python ./bibauthorid_tests.py
Traceback (most recent call last):
File "./bibauthorid_tests.py", line 21, in <module>
import bibauthorid_tables_utils as baidtu
File "/home/simko/private/src/invenio/modules/bibauthorid/lib/bibauthorid_tables_utils.py", line 30, in <module>
from search_engine import get_record
ImportError: No module named search_engine
If relative imports are wanted e.g. to be able to run BibAuthorID on
grid node where Invenio is not installed, then it may be interesting
to introduce conditional imports that will attempt to import needed
modules from local scope and in case of ImportError from global scope,
kind of like:
try:
from search_engine import get_record
except ImportError:
from invenio.search_engine import get_record
Change History (3)
comment:1 Changed 2 years ago by scarli
- Owner set to scarli
- Status changed from new to assigned
comment:2 Changed 2 years ago by scarli
- Status changed from assigned to in_merge
comment:3 Changed 2 years ago by Henning Weiler <henning.weiler@…>
- Resolution set to fixed
- Status changed from in_merge to closed
Note: See
TracTickets for help on using
tickets.

Non-Bibauthorid modules are now imported from the global scope in case the local import fails (not to affect grid-portability).
http://invenio-software.org/repo/personal/invenio-scarli/commit/?h=ticket-465-relative-imports-fix&id=0067a484705a362e5a71f8b9b4136df86b1418d3