Relative imports are not supported by Python configuration loading system
If a configuration file is a resource in a package, it should be possible to do relative imports. For that, the module name should be correctly set (and not be a fixed string).
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- André Anjos mentioned in commit 18cbe57d
mentioned in commit 18cbe57d
- André Anjos mentioned in merge request !61 (merged)
mentioned in merge request !61 (merged)
- Amir MOHAMMADI closed via merge request !61 (merged)
closed via merge request !61 (merged)
- André Anjos closed via commit 18cbe57d
closed via commit 18cbe57d
- Amir MOHAMMADI closed via commit 04e6ecdb
closed via commit 04e6ecdb
- Owner
@andre.anjos this is not working when several configs are loaded at the same time. See for example:
>>> from bob.extension.config import load >>> mod = load(['lbp-svm'], entry_point_group='bob.bio.config') >>> mod = load(['oulunpu'], entry_point_group='bob.bio.config') >>> mod = load(['oulunpu', 'lbp-svm'], entry_point_group='bob.bio.config') Traceback (most recent call last): File "<ipython-input-10-e1c251438d54>", line 1, in <module> mod = load(['oulunpu', 'lbp-svm'], entry_point_group='bob.bio.config') File "/home/amir/idiap/git/bobs/deep/src/bob.extension/bob/extension/config.py", line 184, in load ctxt = _load_context(k, mod) File "/home/amir/idiap/git/bobs/deep/src/bob.extension/bob/extension/config.py", line 44, in _load_context exec(compile(open(path, "rb").read(), path, 'exec'), mod.__dict__) File "/home/amir/idiap/git/bobs/deep/src/bob.pad.face/bob/pad/face/config/lbp_svm.py", line 23, in <module> from ..preprocessor import VideoFaceCrop ImportError: No module named preprocessor
The configurations are coming from two different packages:
['bob.db.oulunpu.config', 'bob.pad.face.config.lbp_svm']
Edited by Amir MOHAMMADI - Amir MOHAMMADI reopened
reopened
- Author Owner
In order to avoid a misunderstanding, could you please create a test case that reflects this problem in the simplest possible way in this package?
- Owner
The problem is my configurations are coming from two packages. I don't know how can I implement such a test in one package (bob.extension)
- Owner
It works like
mod = load(['lbp-svm', 'oulunpu'], entry_point_group='bob.bio.config')
too. Loadinglbp-svm
first.Edited by Amir MOHAMMADI - Owner
but if I put a relative import in
oulunpu
, that one breaks instead if it is loaded second. - Owner
got it. When you do
mod.__dict__.update(ctxt.__dict__)
there is something also calledmod.__package__
which changes to the last context. So I get something like this:ipdb> mod.__name__ 'bob.pad.face.config.lbp_svm' ipdb> mod.__package__ 'bob.db.oulunpu'
where the module name is correct but the package information is incrorrect.
How do you think this should be fixed?
- Author Owner
By first writing a test
- Owner
Here is the test: bob.bio.base!126 (closed)
- Amir MOHAMMADI mentioned in merge request !65 (merged)
mentioned in merge request !65 (merged)
- André Anjos closed via merge request !65 (merged)
closed via merge request !65 (merged)
- Amir MOHAMMADI mentioned in commit 04e6ecdb
mentioned in commit 04e6ecdb