wmayer wrote: ↑
Sat Nov 09, 2019 6:21 pm
In the long-term we should get rid of the habit to add all our module paths to sys.path. But I don't know how to keep backward compatibility as I don't know too much of the internals of Python how the module import mechanism works in detail.
I tried this with the fem-module recently and this is more difficult than I thought. While I got all python modules ported from Mod/Fem to Ext/freecad/fem, I leave out the c++-files because I didn't know of the consequences of moving them into another directory.
In the end I was able to create a fem-analysis with pre and post processing. But opening one of the examples showed that the abstraction layer I tried to use (empty modules which imports everything from the transferred modules) wasn't really working. This is because anything with underscore prefix (private names like _variable) is not imported by using the "from <module> import *". Theoretically, it should be possible to fix this by importing all the things marked as private one by one.
But there is another problem: We really need to recreate the whole structure of the package to provide full backward-compatibility.
In the end I don't think it's not feasable to move a workbench like fem to the new-style packages with keeping full backward-compatibility. It might be possible, but the work needed to do so is enormous and without real benefit. So my conclusion of this is to do it the slow way by adding namespace-packages which are used as abstraction layers in the Ext-directory and this way define the future structure of the python interface.
Regarding the init.py:
If we initialize the new-style workbenches, we import the module at startup. This means the __init__.py is called at App-startup anyway. Further this means that the init.py is obsolete for the initialization and we can do everything in the __init__.py. So in the WorkbenchStarterkit we should not suggest to use init.py and instead use the __init__.py to initialize things like supported import types. In my eyes, this makes more sense for python-developers as it is the same for any other python package. But this does not mean that we should remove the possibility to have a init.py placed in a workbench (as some workbenches might use this in the future too). Maybe deprecate this option at one point, but it's only a question of consistency.
So if we can agree on the "init.py" not needed for namespace-packages I would suggest to move on with the topic which I didn't want to hijack.
No need to wait for FreeCAD to be fully moved towards namespace-packages. I guess it's best to postpone this after a major release (like 1.0) as it most likely introduces backward incompatibilities.
Also no need to fix the ubuntu multiple version not compatible with python's single version per package-and python-version-rule. I guess we can agree on an environment variable that gives us the opportunity to switch between different FreeCAD versions t select the one which is used for the python interface. I will tests this with the freecad.python package and if we find a solid solution, apply it to the master directly.
Anyway, I think it's very important to define some standards regarding the interface (FreeCAD or freecad, python imports, workbecnhes). Not doing so leads to inconsistency and frustration. That's why I think this work is very important. So thanks and please go ahead