mercurial/demandload.py
author Thomas Arendsen Hein <thomas@intevation.de>
Wed, 16 Nov 2005 12:56:19 +0100
changeset 1551 e793cbc8be00
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Fixes to "hg heads -r FOO": Make it actually work (undefined variable 'rev'; allow to pass a rev parameter). repo.branchlookup() doesn't need a copy of heads because it doesn't modify it. Use None as default argument to heads() instead of nullid. Doc string PEPification.

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