Ejemplo n.º 1
0
def get_module(recipe):
    """
    Get module of a recipe
    Args:
        recipe (str): name of recipe
    :return: module
    """
    path = sources.get(recipe)
    return imp.load_module(f"recipes.{path.stem}",
                           *imp.find_module(recipe, [path.parent]))
Ejemplo n.º 2
0
Archivo: query.py Proyecto: armenzg/adr
def load_query_context(name, add_contexts=[]):
    """
    Get query context from yaml file.
    Args:
        name (str): name of query
        add_contexts (list): additional contexts if needed
    Returns:
        query_contexts (list): mixed array of strings (name of common contexts)
         and dictionaries (full definition of specific contexts)
    """
    with open(sources.get(name, query=True)) as fh:
        query = yaml.load(fh, Loader=yaml.SafeLoader)
        # Extract query and context
        specific_contexts = query.pop("context") if "context" in query else {}
        contexts = context.extract_context_names(query)
        contexts.update(add_contexts)
        query_contexts = context.get_context_definitions(contexts, specific_contexts)

        return query_contexts
Ejemplo n.º 3
0
Archivo: query.py Proyecto: armenzg/adr
def load_query(name):
    """Loads the specified query from the disk.

    No checks are necessary as adr.cli:query_handler filters
    requests for queries that do not exist.

    Args:
        name (str): name of the query to be run.

    Results:
        dict query: dictionary representation of yaml query
        (exclude the context).
    """
    with open(sources.get(name, query=True)) as fh:
        query = yaml.load(fh, Loader=yaml.SafeLoader)
        # Remove the context
        if "context" in query:
            query.pop("context")
        return query