Beispiel #1
0
def run_looper(prj, args, act, log_path, logging_lvl):
    """
    Prepare and run looper action using the provided arguments

    :param looper.project.Project prj: project to execute looper action on
    :param argparse.Namespace args: set of looper arguments
    :param str act: action to run
    :param str log_path: absolute path to the log file location
    :param int logging_lvl: logging level code
    """
    setup_logger("looper", level=logging_lvl, stream=stderr, logfile=log_path, plain_format=True)
    eprint("\nAction: {}\n".format(act))
    # run selected looper action
    with peppy.ProjectContext(prj) as prj:
        if act in ["run", "rerun"]:
            run = looper.looper.Runner(prj)
            try:
                run(args, None, rerun=(act == "rerun"))
                globs.run = True
            except IOError:
                raise Exception("{} pipelines_dir: '{}'".format(prj.__class__.__name__, prj.metadata.pipelines_dir))
        if act == "destroy":
            globs.run = False
            return looper.looper.Destroyer(prj)(args, False)
        if act == "summarize":
            globs.summary_requested = True
            run_custom_summarizers(prj)
            _render_summary_pages(prj)
        if act == "check":
            looper.looper.Checker(prj)(flags=args.flags)

        if act == "clean":
            return looper.looper.Cleaner(prj)(args, False)
Beispiel #2
0
def conf_logs(request):
    """ Configure logging for the testing session. """
    level = request.config.getoption("--logging-level")
    logname = "peppy"
    setup_logger(name=logname, level=level, devmode=True)
    logging.getLogger(logname).info(
        "Configured pep logger at level %s; attaching tests' logger %s",
        str(level), __name__)
    global _LOGGER
    _LOGGER = logging.getLogger("peppy.{}".format(__name__))
Beispiel #3
0
def interactive(
        prj_lines=PROJECT_CONFIG_LINES, 
        iface_lines=PIPELINE_INTERFACE_CONFIG_LINES,
        sample_subannotation_lines=SAMPLE_SUBANNOTATION_LINES,
        annotation_lines=SAMPLE_ANNOTATION_LINES,
        project_kwargs=None, logger_kwargs=None):
    """
    Create Project instance from default or given data.

    This is intended to provide easy access to instances of fundamental pep
    object for interactive test-authorship-motivated work in an iPython
    interpreter or Notebook. Test authorship is simplified if we provide
    easy access to viable instances of these objects.

    :param Iterable[str] prj_lines: project config lines
    :param Iterable[str] iface_lines: pipeline interface config lines
    :param Iterable[str] sample_subannotation_lines: lines for a merge table file
    :param Iterable[str] annotation_lines: lines for a sample annotations file
    :param dict project_kwargs: keyword arguments for Project constructor
    :param dict logger_kwargs: keyword arguments for logging configuration
    :return Project: configured Project
    """

    # Establish logging for interactive session.
    pep_logger_kwargs = {"level": "DEBUG", "name": "peppy"}
    pep_logger_kwargs.update(logger_kwargs or {})
    setup_logger(**pep_logger_kwargs)

    # TODO: don't work with tempfiles once ctors tolerate Iterable.
    dirpath = tempfile.mkdtemp()
    path_conf_file = _write_temp(
        prj_lines,
        dirpath=dirpath, fname=P_CONFIG_FILENAME)
    path_iface_file = _write_temp(
        iface_lines,
        dirpath=dirpath, fname="pipeline_interface.yaml")
    path_sample_subannotation_file = _write_temp(
        sample_subannotation_lines,
        dirpath=dirpath, fname=SUBSAMPLES_FILENAME
    )
    path_sample_annotation_file = _write_temp(
        annotation_lines,
        dirpath=dirpath, fname=ANNOTATIONS_FILENAME
    )

    prj = Project(path_conf_file, **(project_kwargs or {}))
    for path in [path_conf_file, path_iface_file,
                 path_sample_subannotation_file, path_sample_annotation_file]:
        os.unlink(path)
    return prj
Beispiel #4
0
def main():
    # set up the logger
    global _LOGGER
    parser = build_parser()
    args = parser.parse_args()

    # populate config
    # read in the configration file
    cfg = read_server_configuration(args.config)

    # read in files
    _PEP_STORAGE_PATH = cfg["data"]["path"]
    load_data_tree(_PEP_STORAGE_PATH, _PEP_STORES)

    if not args.command:
        parser.print_help()
        print("No subcommand given")
        sys.exit(1)
    logger_args = (dict(name=PKG_NAME, fmt=LOG_FORMAT, level=5)
                   if args.debug else dict(name=PKG_NAME, fmt=LOG_FORMAT))
    _LOGGER = logmuse.setup_logger(**logger_args)

    if args.command == "serve":
        uvicorn.run(app,
                    host="0.0.0.0",
                    port=args.port,
                    debug=args.debug,
                    reload=args.reload)

    else:
        _LOGGER.error(f"unknown command: {args.command}")
        sys.exit(1)
Beispiel #5
0
def main():
    global rgc, _LOGGER
    parser = build_parser()
    args = parser.parse_args()
    if not args.command:
        parser.print_help()
        print("No subcommand given")
        sys.exit(1)
    logger_args = (dict(name=PKG_NAME, fmt=LOG_FORMAT, level=5)
                   if args.debug else dict(name=PKG_NAME, fmt=LOG_FORMAT))
    _LOGGER = logmuse.setup_logger(**logger_args)
    selected_cfg = select_genome_config(args.config)
    assert (
        selected_cfg is not None
    ), "You must provide a config file or set the {} environment variable".format(
        "or ".join(CFG_ENV_VARS))
    # this RefGenConf object will be used in the server, so it's read-only
    rgc = RefGenConf(filepath=selected_cfg, writable=False)
    if args.command == "archive":
        arp = ([parse_registry_path(x) for x in args.asset_registry_paths]
               if args.asset_registry_paths is not None else None)
        archive(rgc, arp, args.force, args.remove, selected_cfg,
                args.genomes_desc)
    elif args.command == "serve":
        # the router imports need to be after the RefGenConf object is declared
        with rgc as r:
            purge_nonservable(r)
        from .routers import private, version1, version2, version3

        app.include_router(version3.router)
        app.include_router(version1.router, prefix="/v1")
        app.include_router(version2.router, prefix="/v2")
        app.include_router(version3.router, prefix="/v3")
        app.include_router(private.router, prefix=f"/{PRIVATE_API}")
        uvicorn.run(app, host="0.0.0.0", port=args.port)
Beispiel #6
0
def run_lucidoc(pkg,
                parse_style,
                outfile=None,
                outfolder=None,
                no_mod_docstr=False,
                include_inherited=False,
                whitelist=None,
                blacklist=None,
                groups=None,
                omit_meta=False,
                **log_kwargs):
    """
    Discover docstrings and create package API documentation in Markdown.

    :param str pkg: name of the package to document
    :param str parse_style: key/name of parsing strategy to use
    :param str outfile: path to documentation output file
    :param str outfolder: path to folder in which to place docs output
    :param bool no_mod_docstr: whether to exclude the module-level docstring,
        if present
    :param bool include_inherited: whether to document inherited members
    :param Iterable[str] whitelist: names of doc targets to include
    :param Iterable[str] blacklist: names of doc targets to exclude
    :param Mapping[str, str | Iterable[str]] | Iterable[(str, str | Iterable[str])] groups:
        pairing of group name with either single target name or collection of target names
    :param bool omit_meta: whether the version metadata for documentation
        target and for this package should be omitted from the documentation
        that's created
    :raise TypeError: if passing an argument to whitelist or blacklist that's
        not a non-string collection, or if passing an argument to groups in
        which a group's names isn't a non-string collection
    :raise LucidocError: if passing both output file and output folder, or if
        passing output file and using groups; or if using more than one of
        whitelist, blacklist, and groups
    :raise pydoc.ErrorDuringImport: if the argument to the package parameter
        (pkg) cannot be imported
    """

    global _LOGGER
    _LOGGER = setup_logger(**log_kwargs)

    if outfile and outfolder:
        raise LucidocError("Cannot specify both output file and output folder")

    groups = _standardize_groups_type(groups)
    retain = _determine_retention_strategy(whitelist, blacklist, groups)

    if groups and outfile:
        raise LucidocError(
            "Cannot use output file with groups; to control output destination, "
            "consider output folder and each group names as filename.")

    try:
        sys.path.append(os.getcwd())
        # Attempt import
        pkg_obj = pydoc.safeimport(pkg)
        if pkg_obj is None:
            raise LucidocError(
                "ERROR -- Documentation target not found: {}".format(pkg))
    except pydoc.ErrorDuringImport:
        _LOGGER.error("Failed to import '{}'".format(pkg))
        raise
    else:
        show_tag = MdTagRenderer()
        parse = get_parser(parse_style)
        doc_res = doc_module(pkg_obj,
                             parse,
                             show_tag,
                             no_mod_docstr=no_mod_docstr,
                             include_inherited=include_inherited,
                             retain=retain,
                             groups=groups,
                             omit_meta=omit_meta)
        if groups:
            outfolder = expandpath(outfolder or os.getcwd())
            _LOGGER.debug("Base output folder: {}".format(outfolder))
            missing, invalid = [], []
            for g, _ in groups:
                try:
                    doc = doc_res[g]
                except KeyError:
                    missing.append(g)
                    continue
                base, ext = os.path.splitext(g)
                if ext:
                    if ext != ".md":
                        invalid.append(g)
                        continue
                    fn = g
                else:
                    fn = base + ".md"
                _write_docs(os.path.join(outfolder, fn), doc)
            if missing:
                _LOGGER.warning("Missing output for {} group(s): {}".format(
                    len(missing), ", ".join(missing)))
            if invalid:
                _LOGGER.warning(
                    "Skipped writing {} group(s) on account of illegal output "
                    "file extension: {}".format(len(invalid),
                                                ", ".join(invalid)))
            _LOGGER.info("Done.")
        elif outfile:
            _write_docs(outfile, doc_res)
            _LOGGER.info("Done.")
        else:
            print(doc_res)