Data Integrator (Python API)
|
Import hook for loading packages with the same name. More...
Classes | |
class | CImporter |
Import hook module finder. More... | |
class | CLoader |
Import hook module loader. More... | |
Import hook for loading packages with the same name.
The Data Integrator project defines a directory hierarchy we also want to use in other projects, especially the architecture and organization of Python source code. By having the same directory structure twice, we encounter the problem that modules are cached through their common package name (eg. P.M, where P is the package, and M the module). This prevents loading modules in other directories with the same package name.
Example:
/long/path1/P/M1
.py/other/path2/P/M2
.pyPYTHONPATH=/long/path1
:/other/path2import
P.M2
will raise an exception, as the import logic finds package P
as directory /long/path1/P
, caches it and retrieves it from the cache to search (nonexisting) module M2
within.
This importer and loader class take care of it. They need to be installed in the system meta path (sys.meta_path
) only once. This is done by the import command import
common.ImportHook
in the init
.py files of Data Integrator, with the PYTHONPATH
variable set in a way such that the directories of the corresponding Data Integrator init
files are found first.
Modifications: YYYY-MM-DD (WHO) what