-
Notifications
You must be signed in to change notification settings - Fork 273
Closed
Description
With the "old" way of importing applications being deprecated, we now should find a common solution for importing the python scripts
Previously we had to do:
import KratosMultiphysics.FluidDynamicsApplication
import vms_solvernow we have several options:
import KratosMultiphysics.FluidDynamicsApplication.vms_solver as vms_solver
from KratosMultiphysics.FluidDynamicsApplication import vms_solverHowever, what is also possible and where we had several discussions (e.g. here and here) are explicit relative imports:
# in vms_sovler.py:
from KratosMultiphysics.FluidDynamicsApplication import fluid_solver # absolute import
# OR:
from . import fluid_solver # explicit relative importfrom PEP8:
"Absolute imports are recommended, as they are usually more readable and tend to be better behaved ..."
"However, explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose"
I tried both ways already and suggest (up for discussion the following):
- By default I would go for absolute imports, just as PEP8 suggests.
- Since however Kratos has a relatively large/complex file structure I would also allow explicit relative imports, if the developer decides to use it, since it does shorten the paths quite a bit (e.g. here)
=> especially when there is a subfolder-structure insidepython_scripts(which is now possible and already in use, see CoSimApp and HDF5App) since it can make the paths much shorter - What I would not allow is to use explicit relative imports across directories (e.g. importing from parent directory etc), bcs this becomes really unreadable then example