Python-Loaders is a small collection of custom module loaders doing various tasks.
pip install -e "git://github.com/FelixLoether/python-loaders#egg=python-loaders"
Prevents the module from being loaded until the lazy loader’s ready() method has been called. The module can still be imported and the attrs defined in attrs can still be accessed before ready() has been called, and references to them will be updated with the real values when the method is called.
This can be useful when your module has some requirements that cannot be satisfied when the module would be first imported. One example of this is defining a class whose parent is given as a parameter to the package’s setup function:
pkg/__init__.py:
import loaders
loader = loaders.Lazy('%s.models' % __name__, ['MyModel'])
import extensions
def init(db):
extensions.db = db
loader.ready()
pkg/extensions.py:
db = None
pkg/models.py:
from .extensions import db
# db is None until the init function has been called, so loading this
# module before that would result in an AttributeError.
class MyModel(db.Model):
name = db.Column(db.Unicode(255))
Parameters: |
|
---|
Loads the module and updates references to it and the attributes defined in attrs. Call this when the module’s requirements have been set up and the module can be loaded.