apfel.impt.transform
This module provides a low-level hook mechanism to transform the source code of a package or module during its import. It must be imported before any other packages and modules that you want to hook.
Normally you would use adapters defined in the impt package, instead of directly using the low level register_transform_hook function.
API#
Classes
| Name | Description |
|---|---|
TransformPathFinder | A subclass of :python importlib.machinery.PathFinder |
TransformSourceFileLoader | A subclass of :python importlib.machinery.SourceFileLoader |
Functions
| Name | Description |
|---|---|
register_transform_hook | Register a hook function to replace the source code of a module or package. |
TransformPathFinderclass#
class TransformPathFinder(_frozen_importlib_external.PathFinder)Bases: _frozen_importlib_external.PathFinder
A subclass of importlib.machinery.PathFinder
that injects TransformSourceFileLoader to the import process.
TransformSourceFileLoaderclass#
class TransformSourceFileLoader(fullname: str, path: str, *, hook: Sequence[Callable[[str], str]])Bases: _frozen_importlib_external.SourceFileLoader
A subclass of importlib.machinery.SourceFileLoader
that applies all registered hooks to the source code of a module or package during import.
