mercurial/demandload.py
author mpm@selenic.com
Fri, 10 Jun 2005 13:48:08 -0800
changeset 309 61414da06fe5
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
add easy profiling support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 add easy profiling support Now you can do hg -p [command] and it will run it under the hotshot profiler manifest hash: fcad346798243ad2434bc5458ed8d3456707c599 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCqgqYywK+sNU5EO8RAp9BAJsFI7iUWYEMvXWYaVt4VmrlOF3enwCdEFRJ l/EZmMLecbfQcbbh5oo0yHs= =voa0 -----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