mercurial/demandload.py
author mpm@selenic.com
Wed, 08 Jun 2005 17:08:55 -0800
changeset 290 07c6cb9fd1c5
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
replace hg branch with hg init [source] -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 replace hg branch with hg init [source] This does the hardlink trick if both repos are on the same filesystem, otherwise it does a pull. manifest hash: 780a3a0aca6e4a535909c6221ee94394701ec1c9 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCp5anywK+sNU5EO8RArdDAJ9Tiia0YZmZ6xiTYdKhZJ2UZY8V5wCfeoPy DamQ2Zyz3yTjNqu4ge0CuRQ= =EXv5 -----END PGP SIGNATURE-----

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