- class codegenloader.base.CodeGenLoader(path)¶
Abstract base class for code generation import hooks.
The entry point for applications is to define a subclass and use the register class method to set __path__. This will make the module where __path__ was assigned a pseudo-package from which the generated code can be imported.
The interface between this class and the python interpreter is defined in PEP 302: http://www.python.org/dev/peps/pep-0302/
Constructs a CodeGenLoader.
Implements the hook protocol from PEP 302: it is called with a “path”, and returns a loader if we can handle that path (i.e. if the path is actually a unique token we created in register), or raises an ImportError if not.
- classmethod register(*args, **kwargs)¶
Registers an import hook.
Arguments are passed (eventually) to initialize.
- initialize(modname, basedir)¶
Real initialization function, independent of PEP302 requirements.
modname is the module name relative to which the generated code will be imported. basedir is the directory in which the source files for generation can be found. If it is not an absolute path, it is interpreted as relative to the file containing modname
Returns a loader object for the module fullname, if it exists.
Implements the “finder” portion of the PEP 302 interface.
Returns the module named fullname.
Implements the “loader” portion of the PEP 302 interface.
Converts a fully-qualified module name to a relative one.
Return a tuple (is_pkg, contents) if code is stored for this module.
If the code is not found, raises KeyError.
- store_contents(relpath, contents)¶
Store the contents of a file at relpath.
To be called from subclasses after code has been generated.
Should return True if we can generate a module named relname.