[modutils, registry] use standards python loaders instead of reinventing how to find python modules
In regards of this merge request open-source/logilab-common!76 (merged)
Especially the commit about rewriting modpath_from_file
It turns out that we kinda have completely reinvented the loading mechanism of modules from python without using the standard library. This is very likely due to this code being especially old and those mechanism not existing at that time.
In the meantime, we end up having very old not very strong code a bit everywhere that is able to load a python file from the path using a lot of magic stuff, this is especially the case in:
- yams.reader.SchemaLoader.load see open-source/yams!78
- logilab.common.registry.RegistryStore.init_registrations https://forge.extranet.logilab.fr/open-source/logilab-common/-/blob/2c2caa1fc1e1d17032695af40d4c64ea663bbe0b/logilab/common/registry.py#L986-999
All those code works on either a list of file or directory and ends up using logilab.common.modutils.modpath_from_file and exec (sic) or a custom exec function while doing a context_of_file_to_exec['__name__'] = modpath_from_file(path_to_file)
. This is basically reinventing the import mechanism of python.
This is especially not great since all this code is hard to write, hard to maintain, buggy right now (DEPRECATED: doens't play well with symlinks and sys.meta_path
from modpath_from_file) and in the end totally unjustified.
We should switch all this old code to using importlib or wathever and using modern maintained python instead of reinventing a broken buggy wheel.