Esempio n. 1
0
File: modutil.py Progetto: saa/disco
def locate_modules(modules, recurse=True, include_sys=False):
    """
    Finds module files corresponding to the module names specified in the list *modules*.

    :param modules: The modules to search for other required modules.

    :param recurse: If ``True``, recursively search for local modules
                    that are used in *modules*.

    A module is local if it can be found in your ``PYTHONPATH``. For modules that
    can be found under system-wide default paths (e.g. ``/usr/lib/python``), just
    the module name is returned without the corresponding path, so system-wide
    modules are not distributed to nodes unnecessarily.

    This function is used by :func:`find_modules` to locate modules used by
    the specified functions.
    """
    LOCALDIRS = user_paths()
    found = {}

    for module in modules:
        file, path, x = imp.find_module(module)
        from disco.fileutils import get_valid_path
        path = get_valid_path(path)

        if dirname(path) in LOCALDIRS and os.path.isfile(path):
            found[module] = path
            if recurse:
                found.update(recurse_module(module, path))
        elif include_sys:
            found[module] = None
    return found.items()
Esempio n. 2
0
File: modutil.py Progetto: saa/disco
def recurse_module(module, path):
    finder = modulefinder.ModuleFinder(path=list(user_paths()))
    finder.run_script(path)
    from disco.fileutils import get_valid_path
    return dict((name, get_valid_path(module.__file__))
                for name, module in finder.modules.items()
                if name != '__main__' and module.__file__)
Esempio n. 3
0
def locate_modules(modules, recurse=True, include_sys=False):
    """
    Finds module files corresponding to the module names specified in the list *modules*.

    :param modules: The modules to search for other required modules.

    :param recurse: If ``True``, recursively search for local modules
                    that are used in *modules*.

    A module is local if it can be found in your ``PYTHONPATH``. For modules that
    can be found under system-wide default paths (e.g. ``/usr/lib/python``), just
    the module name is returned without the corresponding path, so system-wide
    modules are not distributed to nodes unnecessarily.

    This function is used by :func:`find_modules` to locate modules used by
    the specified functions.
    """
    LOCALDIRS = user_paths()
    found = {}

    for module in modules:
        file, path, x = imp.find_module(module)
        from disco.fileutils import get_valid_path
        path = get_valid_path(path)

        if dirname(path) in LOCALDIRS and os.path.isfile(path):
            found[module] = path
            if recurse:
                found.update(recurse_module(module, path))
        elif include_sys:
            found[module] = None
    return found.items()
Esempio n. 4
0
def guess_home():
    from disco.error import DiscoError
    from disco.fileutils import get_valid_path
    disco_lib  = os.path.dirname(get_valid_path(__file__))
    disco_home = os.path.dirname(os.path.dirname(disco_lib))
    if os.path.exists(os.path.join(disco_home, '.disco-home')):
        return disco_home
    raise DiscoError("DISCO_HOME is not specified, where should Disco live?")
Esempio n. 5
0
def guess_home():
    from disco.error import DiscoError
    from disco.fileutils import get_valid_path
    disco_lib = os.path.dirname(get_valid_path(__file__))
    disco_home = os.path.dirname(os.path.dirname(disco_lib))
    if os.path.exists(os.path.join(disco_home, '.disco-home')):
        return disco_home
    raise DiscoError("DISCO_HOME is not specified, where should Disco live?")
Esempio n. 6
0
def recurse_module(module, path):
    finder = modulefinder.ModuleFinder(path=list(user_paths()))
    finder.run_script(path)
    from disco.fileutils import get_valid_path
    return dict((name, get_valid_path(module.__file__)) for name, module in finder.modules.items()
                if name != '__main__' and module.__file__)