How to use the dffml.df.base.op function in dffml

To help you get started, we’ve selected a few dffml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github intel / dffml / tests / test_df.py View on Github external
@op(inputs={"numbers": numbers}, outputs={"sum": result}, conditions=[is_add])
async def add(numbers: List[int]):
    return {"sum": sum(numbers)}
github intel / dffml / dffml / skel / operations / REPLACE_IMPORT_PACKAGE_NAME / operations.py View on Github external
@op(
    inputs={"line": calc_string},
    outputs={"add": is_add, "mult": is_mult, "numbers": numbers},
)
async def calc_parse_line(line: str):
    """
    Parse a line which holds the English form of a math calculation to be done
    """
    return {
        "add": "add" in line,
        "mult": "mult" in line,
        "numbers": [int(item) for item in line.split() if item.isdigit()],
    }
github intel / dffml / feature / git / dffml_feature_git / feature / operations.py View on Github external
@op(
    inputs={"repo": git_repository},
    outputs={"branch": git_branch},
    conditions=[no_git_branch_given],
)
async def git_repo_default_branch(repo: Dict[str, str]):
    branches = (
        await check_output("git", "branch", "-r", cwd=repo["directory"])
    ).split("\n")
    main = [branch for branch in branches if "->" in branch][0].split()[-1]
    main = main.split("/")[-1]
    return {"branch": main}
github intel / dffml / dffml / skel / operations / REPLACE_IMPORT_PACKAGE_NAME / operations.py View on Github external
@op(
    inputs={"numbers": numbers},
    outputs={"product": result},
    conditions=[is_mult],
)
async def calc_mult(numbers: List[int]):
    """
    Multiply a list of numbers together
    """
    product = 1
    for number in numbers:
        product *= number
    return {"product": product}
github intel / dffml / dffml / operation / output.py View on Github external
@op(
    inputs={"spec": Definition(name="remap_spec", primitive="map")},
    outputs={"response": Definition(name="remap_output", primitive="map")},
    stage=Stage.OUTPUT,
    config_cls=RemapConfig,
)
async def remap(
    self: OperationImplementationContext, spec: Dict[str, List[str]]
):
    # Create a new orchestrator context. Specify that it should use the existing
    # input set context, this way the output operations we'll be running have
    # access to the data from this data flow rather than a new sub flow.
    async with self.octx.parent(
        self.config.dataflow, ictx=self.octx.ictx
    ) as octx:
        _ctx, result = [result async for result in octx.run(ctx=self.ctx)][0]
    # Remap the output operations to their feature (copied logic
github intel / dffml / feature / git / dffml_feature_git / feature / operations.py View on Github external
@op(inputs={"URL": URL}, outputs={"valid": valid_git_repository_URL})
async def check_if_valid_git_repository_URL(URL: str):
    exit_code = await exec_with_logging("git", "ls-remote", URL)
    return {"valid": bool(exit_code == 0)}
github intel / dffml / examples / shouldi / shouldi / pypi.py View on Github external
@op(
    inputs={"package": package},
    outputs={"response_json": package_json},
    # imp_enter allows us to create instances of objects which are async context
    # managers and assign them to self.parent which is an object of type
    # OperationImplementation which will be alive for the lifetime of the
    # Orchestrator which runs all these operations.
    imp_enter={
        "session": (lambda self: aiohttp.ClientSession(trust_env=True))
    },
)
async def pypi_package_json(self, package: str) -> Dict[str, Any]:
    """
    Download the information on the package in JSON format.
    """
    url = f"https://pypi.org/pypi/{package}/json"
    async with self.parent.session.get(url) as resp: