Exemple #1
0
def citation(*infos):
    print(make_header("This framework", ""))
    print("[Paper in preparation]\n")
    for kind, modules in get_modules(*infos).items():
        for module in modules:
            print(make_header(kind, module))
            print(get_citation_info(module, kind))
Exemple #2
0
def prettyprint_citation(blocks_text):
    txt = ""
    for block, text in blocks_text.items():
        if not txt.endswith("\n\n"):
            txt += "\n\n"
        txt += make_header(*block.split(":")) + "\n" + text
    return txt.lstrip().rstrip() + "\n"
Exemple #3
0
def install(*infos, **kwargs):
    if not log.root.handlers:
        logger_setup()
    path = kwargs.get("path", ".")
    if not path:
        # See if we can get one (and only one) from infos
        paths = set(
            [p for p in [info.get(_path_install) for info in infos] if p])
        if len(paths) == 1:
            path = paths[0]
        else:
            print("logging?")
            log.error(
                "No 'path' argument given and could not extract one (and only one) "
                "from the infos.")
            raise HandledException
    abspath = os.path.abspath(path)
    log.info("Installing modules at '%s'\n", abspath)
    kwargs_install = {
        "force": kwargs.get("force", False),
        "no_progress_bars": kwargs.get("no_progress_bars")
    }
    for what in (_code, _data):
        kwargs_install[what] = kwargs.get(what, True)
        spath = os.path.join(abspath, what)
        if kwargs_install[what] and not os.path.exists(spath):
            try:
                os.makedirs(spath)
            except OSError:
                log.error(
                    "Could not create the desired installation folder '%s'",
                    spath)
                raise HandledException
    failed_modules = []
    for kind, modules in get_modules(*infos).items():
        for module in modules:
            print(make_header(kind, module))
            module_folder = get_folder(module, kind, sep=".", absolute=False)
            try:
                imported_module = import_module(module_folder,
                                                package=_package)
            except ImportError:
                if kind == _likelihood:
                    info = (next(info for info in infos if module in info.get(
                        _likelihood, {}))[_likelihood][module]) or {}
                    if isinstance(info, string_types) or _external in info:
                        log.warning(
                            "Module '%s' is a custom likelihood. "
                            "Nothing to do.\n", module)
                        flag = False
                    else:
                        log.error("Module '%s' not recognized.\n" % module)
                        failed_modules += ["%s:%s" % (kind, module)]
                continue
            is_installed = getattr(imported_module, "is_installed", None)
            if is_installed is None:
                log.info("Built-in module: nothing to do.\n")
                continue
            if is_installed(path=abspath, **kwargs_install):
                log.info("External module already installed.\n")
                if kwargs_install["force"]:
                    log.info("Forcing re-installation, as requested.")
                else:
                    log.info("Doing nothing.\n")
                    continue
            try:
                success = imported_module.install(path=abspath,
                                                  **kwargs_install)
            except:
                traceback.print_exception(*sys.exc_info(), file=sys.stdout)
                log.error(
                    "An unknown error occurred. Delete the modules folder and try "
                    "again. Notify the developers if this error persists.")
                success = False
            if success:
                log.info("Successfully installed!\n")
            else:
                log.error(
                    "Installation failed! Look at the error messages above. "
                    "Solve them and try again, or, if you are unable to solve, "
                    "install this module manually.")
                failed_modules += ["%s:%s" % (kind, module)]
                continue
            # test installation
            if not is_installed(path=abspath, **kwargs_install):
                log.error(
                    "Installation apparently worked, "
                    "but the subsequent installation test failed! "
                    "Look at the error messages above. "
                    "Solve them and try again, or, if you are unable to solve, "
                    "install this module manually.")
                failed_modules += ["%s:%s" % (kind, module)]
    if failed_modules:
        bullet = "\n - "
        log.error(
            "The installation (or installation test) of some module(s) has failed: "
            "%s\nCheck output of the installer of each module above "
            "for precise error info.\n", bullet + bullet.join(failed_modules))
        raise HandledException
Exemple #4
0
def install(*infos, **kwargs):
    path = kwargs.get("path", ".")
    abspath = os.path.abspath(path)
    kwargs_install = {
        "force": kwargs.get("force", False),
        "no_progress_bars": kwargs.get("no_progress_bars")
    }
    for what in (_code, _data):
        kwargs_install[what] = kwargs.get(what, True)
        spath = os.path.join(abspath, what)
        if kwargs_install[what] and not os.path.exists(spath):
            try:
                os.makedirs(spath)
            except OSError:
                log.error(
                    "Could not create the desired installation folder '%s'",
                    spath)
                raise HandledException
    failed_modules = []
    for kind, modules in get_modules(*infos).items():
        for module in modules:
            print(make_header(kind, module))
            module_folder = get_folder(module, kind, sep=".", absolute=False)
            try:
                imported_module = import_module(module_folder, package=package)
            except ImportError:
                if kind == _likelihood:
                    log.warn(
                        "Module '%s' not recognised. Assuming it's a custom "
                        "likelihood. Nothing to do.\n", module)
                else:
                    log.error("Module '%s' not recognised.\n" % module)
                    failed_modules += ["%s:%s" % (kind, module)]
                continue
            is_installed = getattr(imported_module, "is_installed", None)
            if is_installed is None:
                log.info("Built-in module: nothing to do.\n")
                continue
            if is_installed(path=abspath, **kwargs_install):
                log.info("External module already installed.\n")
                if kwargs_install["force"]:
                    log.info("Forcing re-installation, as requested.")
                else:
                    log.info("Doing nothing.\n")
                    continue
            try:
                success = imported_module.install(path=abspath,
                                                  **kwargs_install)
            except:
                traceback.print_exception(*sys.exc_info(), file=sys.stdout)
                log.error(
                    "An unknown error occurred. Delete the modules folder and try "
                    "again. Notify the developers if this error persists.")
                success = False
            if success:
                log.info("Successfully installed!\n")
            else:
                log.error(
                    "Installation failed! Look at the error messages above. "
                    "Solve them and try again, or, if you are unable to solve, "
                    "install this module manually.")
                failed_modules += ["%s:%s" % (kind, module)]
                continue
            # test installation
            if not is_installed(path=abspath, **kwargs_install):
                log.error(
                    "Installation apparently worked, "
                    "but the subsequent installation test failed! "
                    "Look at the error messages above. "
                    "Solve them and try again, or, if you are unable to solve, "
                    "install this module manually.")
                failed_modules += ["%s:%s" % (kind, module)]
    if failed_modules:
        log.error(
            "The instalation (or installation test) of some module(s) has failed: "
            "%r. Check output above.\n", failed_modules)
        raise HandledException