def module_path(name, path):
    global _path_cache
    candidates = []
    packages = {}
    modules = {}
    if name.endswith('.js'):
        parts = [name]
    else:
        parts = name.split('.')
    if not name in _path_cache:
        _path_cache[name] = {}
    for p in path:
        if p in _path_cache[name]:
            if _path_cache[name][p] is None:
                continue
            return _path_cache[name][p]
        tail = []
        for pn in parts:
            tail.append(pn)
            mn = '.'.join(tail)
            cp = os.path.join(*([p] + tail))
            if mn in _path_cache:
                cache = _path_cache[mn]
            else:
                cache = {}
                _path_cache[mn] = cache
            if p in cache:
                if cache[p] is None:
                    break
            elif os.path.isdir(cp) and os.path.exists(
                os.path.join(cp, '__init__.py')):
                cache[p] = os.path.join(cp, '__init__.py')
            elif os.path.exists(cp + '.py'):
                cache[p] = cp + '.py'
            elif pn.endswith('.js') and os.path.exists(cp):
                cache[p] = cp
            else:
                cache[p] = None
        if p in _path_cache[name] and not _path_cache[name][p] is None:
            return _path_cache[name][p]
        _path_cache[name][p] = None
    
    return None
    raise RuntimeError, "Module %r not found" % name
dataset/ETHPy150Open anandology/pyjamas/pyjs/src/pyjs/linker.py/module_path/original