tea.utils
Module¶
-
tea.utils.
get_object
(path='', obj=None)[source]¶ Return an object from a dot path.
Path can either be a full path, in which case the get_object function will try to import the modules in the path and follow it to the final object. Or it can be a path relative to the object passed in as the second argument.
Parameters: Returns: Object at the end of the path, or list of non hidden objects if we use the star query.
Example for full paths:
>>> get_object('os.path.join') <function join at 0x1002d9ed8> >>> get_object('tea.process') <module 'tea.process' from 'tea/process/__init__.pyc'>
Example for relative paths when an object is passed in:
>>> import os >>> get_object('path.join', os) <function join at 0x1002d9ed8>
Example for a star query. (Star query can be used only as the last element of the path:
>>> get_object('tea.dsa.*') [] >>> get_object('tea.dsa.singleton.*') [<class 'tea.dsa.singleton.Singleton'>, <class 'tea.dsa.singleton.SingletonMetaclass'> <module 'six' from '...'>] >>> get_object('tea.dsa.*') [<module 'tea.dsa.singleton' from '...'>] # Since we imported it
-
class
tea.utils.
Loader
[source]¶ Module loader class loads recursively a module and all it’s submodules.
Loaded modules will be stored in the
modules
attribute of the loader as a dictionary of {module_path: module} key, value pairs.Errors accounted during the loading process will not stop the loading process. They will be stored in the
errors
attribute of the loader as a dictionary of {module_path: exception} key, value pairs.Usage:
loader = Loader() loader.load('foo') loader.load('baz.bar', 'boo') import baz loader.load(baz)
-
tea.utils.
load_subclasses
(klass, modules=None)[source]¶ Load recursively all all subclasses from a module.
Parameters: - klass (str or list of str) – Class whose subclasses we want to load.
- modules – List of additional modules or module names that should be recursively imported in order to find all the subclasses of the desired class. Default: None
- FIXME: This function is kept only for backward compatibility reasons, it
- should not be used. Deprecation warning should be raised and it should
be replaces by the
Loader
class.