Acorn Automated Package Decoration on Import¶
Although the most commonly used (and largest) packages have been manually set-up and corrected for acorn, it would be painful for a user to create a new sub-package in the acorn distribution for every package that ever needs to be decorated. Considering that any pure python package will decorate without any problems, it would be nice if any package could just be decorated automatically.
acorn includes a special module finder
AcornMetaImportFinder
that intercepts all calls to
import and can decorate packages “on the fly”. The only necessity is that the
package have its name placed in the [acorn.packages] section of the
Global and Package Configuration in ACORN file. Then the package can just be imported using:
import acorn.package
where package is the name of the package. acorn intercepts the imports by
using the sys.meta_path
hook and inserting the acorn module finder in
the first position of the list.
API Documentation¶
Class for altering the search paths within acorn for new/undecorated packages (i.e., those that weren’t checked explicitly when it was first designed.
-
class
acorn.importer.
AcornDecoratingLoader
(package)[source]¶ Loads packages that need to be decorated for automatic logging by acorn.
Parameters: package (str) – name of the package being loaded.
-
class
acorn.importer.
AcornMetaImportFinder
(prefix='acorn')[source]¶ Overrides the default import behavior of python for packages so that we can intercept and decorate certain packages, but not others.
Parameters: prefix (str) – prefix on import full names before they are considered loadable by acorn. Also available as an attribute.
-
class
acorn.importer.
AcornStandardLoader
(package)[source]¶ Loads packages without decoration, but with the correct flags enabled so that if those packages imported acorn decorated ones, they don’t run all the logging machinery during imports.
-
acorn.importer.
hooks
= []¶ list – of package names that have already been intercepted by our loader/decorator. This allows us to skip them the next time they are imported (by our scripts) so that we don’t get into an infinite loop.