faust.utils.venusian¶
Venusian (see venusian).
We define our own interface so we don’t have to specify the callback argument.
- class faust.utils.venusian.Scanner(**kw)[source]¶
- scan(package, categories=None, onerror=None, ignore=None)[source]¶
Scan a Python package and any of its subpackages. All top-level objects will be considered; those marked with venusian callback attributes related to
categorywill be processed.The
packageargument should be a reference to a Python package or module object.The
categoriesargument should be sequence of Venusian callback categories (each category usually a string) or the special valueNonewhich means all Venusian callback categories. The default isNone.The
onerrorargument should either beNoneor a callback function which behaves the same way as theonerrorcallback function described in http://docs.python.org/library/pkgutil.html#pkgutil.walk_packages . By default, during a scan, Venusian will propagate all errors that happen during its code importing process, includingImportError. If you use a customonerrorcallback, you can change this behavior.Here’s an example
onerrorcallback that ignoresImportError:import sys def onerror(name): if not issubclass(sys.exc_info()[0], ImportError): raise # reraise the last exception
The
namepassed toonerroris the module or package dotted name that could not be imported due to an exception.New in version 1.0: the
onerrorcallbackThe
ignoreargument allows you to ignore certain modules, packages, or global objects during a scan. It should be a sequence containing strings and/or callables that will be used to match against the full dotted name of each object encountered during a scan. The sequence can contain any of these three types of objects:A string representing a full dotted name. To name an object by dotted name, use a string representing the full dotted name. For example, if you want to ignore the
my.packagepackage and any of its subobjects or subpackages during the scan, passignore=['my.package'].A string representing a relative dotted name. To name an object relative to the
packagepassed to this method, use a string beginning with a dot. For example, if thepackageyou’ve passed is imported asmy.package, and you passignore=['.mymodule'], themy.package.mymodulemymodule and any of its subobjects or subpackages will be omitted during scan processing.A callable that accepts a full dotted name string of an object as its single positional argument and returns
TrueorFalse. For example, if you want to skip all packages, modules, and global objects with a full dotted path that ends with the word “tests”, you can useignore=[re.compile('tests$').search]. If the callable returnsTrue(or anything else truthy), the object is ignored, if it returnsFalse(or anything else falsy) the object is not ignored. Note that unlike string matches, ignores that use a callable don’t cause submodules and subobjects of a module or package represented by a dotted name to also be ignored, they match individual objects found during a scan, including packages, modules, and global objects.
You can mix and match the three types of strings in the list. For example, if the package being scanned is
my,ignore=['my.package', '.someothermodule', re.compile('tests$').search]would causemy.package(and all its submodules and subobjects) to be ignored,my.someothermoduleto be ignored, and any modules, packages, or global objects found during the scan that have a full dotted name that ends with the wordteststo be ignored.Note that packages and modules matched by any ignore in the list will not be imported, and their top-level code will not be run as a result.
A string or callable alone can also be passed as
ignorewithout a surrounding list.New in version 1.0a3: the
ignoreargument