mercurial/demandload.py
author Fabian Otto <sigsegv@alchiba.ni.cs.tu-berlin.de>
Mon, 20 Feb 2006 15:58:04 -0600
changeset 1759 5afd459db177
parent 262 3db700146536
child 1826 f3abe0bdccdd
permissions -rw-r--r--
Sunpro compiler patch The compiling runs through without warning, but runnig the newly builded hg emmits a message: | ImportError: ld.so.1: python: fatal: relocation error: | file /opt/local/lib/python2.3/site-packages/mercurial/bdiff.so: | symbol cmp: referenced symbol not found Removing the inline infront of cmp corrects this error message.

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