Fixing python3 imports for UFO models
Hi authors,
I'd really like to see if we can improve upon the current find_ufo_path:
https:/
to make the importing of models a bit more pythonic. That'd be a nice step towards giving us a little more power over the organization of our models. For a typical python module, you can do an:
import my_module
my_module.__path__
to get back the path to the model in case that's needed for anything. That means we could do something like
try:
import my_model
return my_model.__path__
Of course, please let me know if there's something fundamental I'm missing here that would make this a very bad idea. Assuming it's not, that works nicely in python2, e.g.:
>>> import vector_LQ_UFO
>>> vector_
['/cvmfs/
In python3, relative imports are no longer allowed (see e.g. https:/
>>> import vector_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/cvmfs/
import object_library
ModuleNotFoundE
because the __init__.py of the UFO models use a whole bunch of relative imports:
import object_library
import particles
import couplings
import lorentz
instead of absolute imports, like:
from . import object_library
from . import particles
from . import couplings
from . import lorentz
This model is otherwise "python3-ready", except for the relative imports that show up everywhere (and this seems generically true for all the UFO models we use, I'm not just picking on whoever wrote this particular model).
The question is: is there any issue with changing these to absolute imports and moving in a direction where this is a bit more pythonic? As I said, I'm happy to help implement some of these changes, and to have them protected behind e.g. try/except blocks so that they won't affect users who don't want to use them, but I think it'd be a nice thing to do.
Thanks,
Zach
Question information
- Language:
- English Edit question
- Status:
- Expired
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: