sapling/mercurial/demandload.py
mpm@selenic.com 1b992606bb implement demand loading hack
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

implement demand loading hack

This attempts to speed up start-up times without pushing imports down
into local scopes.

manifest hash: f9c18897e67f7872b44f5c89bdde00edfc3628ce
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFCo0kHywK+sNU5EO8RAg5HAKCxRKAz3FXDyv4wScq1ZbwTgfPa2gCfW9K+
dg5nC3Uvp4FilP8waF6liAY=
=dolF
-----END PGP SIGNATURE-----
2005-06-05 10:48:39 -08:00

16 lines
384 B
Python

def demandload(scope, modules):
class d:
def __getattr__(self, name):
mod = self.__dict__["mod"]
scope = self.__dict__["scope"]
scope[mod] = __import__(mod, scope, scope, [])
return getattr(scope[mod], name)
for m in modules.split():
dl = d()
dl.mod = m
dl.scope = scope
scope[m] = dl