Beispiel #1
0
def absmodpath(module): #{{{
    if isinstance(module, basestring):
        return _amp_str(module)
    elif isfilemodule(module):
        p = op.abspath(module.__file__)
        if ispackage(module):
            p = op.dirname(p)
        return absmodpath(p)
    elif ismodule(module):
        return module.__name__
    raise TypeError("Cannot determine module path of %s object" %module.__class__.__name__)
Beispiel #2
0
def rootpackage(module): #{{{
    if isfilemodule(module):
        p = absmodpath(module.__file__)
        if not p:
            return None
        root = p.split('.')[0]
        return __import__(root)
    elif ismodule(module):
        return module
    names = (module.__class__.__name__, str(module))
    raise TypeError("Cannot determine root package of %s object '%s'" %names)
Beispiel #3
0
def parent(module): #{{{
    if isfilemodule(module):
        p = absmodpath(module)
        path = p.split('.')
        plen = len(path)
        mpath = None
        if not plen or plen == 1:
            return module
        else: 
            mpath = '.'.join(path[:-1])
        return modpathmod(mpath)
    elif ismodule(module):
        return module
    raise TypeError("Cannot import parent module of %s object" %module.__class__.__name__)