How to use the dffml.df.base.OperationImplementation.load 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
async def test_load_name_given(self):
        self.assertEqual(add.imp, OperationImplementation.load("add"))
        self.assertEqual(mult.imp, OperationImplementation.load("mult"))
github intel / dffml / tests / test_df.py View on Github external
async def test_load(self):
        loaded = OperationImplementation.load()
        self.assertIn(add.imp, loaded)
        self.assertIn(mult.imp, loaded)
        self.assertNotIn(parse_line.op, loaded)
github intel / dffml / tests / test_df.py View on Github external
async def test_load_name_given(self):
        self.assertEqual(add.imp, OperationImplementation.load("add"))
        self.assertEqual(mult.imp, OperationImplementation.load("mult"))
github intel / dffml / tests / test_df.py View on Github external
async def test_load_failure(self):
        with self.assertRaises(FailedToLoadOperationImplementation):
            OperationImplementation.load("parse_line")
github intel / dffml / dffml / df / memory.py View on Github external
async def instantiable(
        self, operation: Operation, *, opimp: OperationImplementation = None
    ) -> bool:
        """
        Looks for class registered with ____ entrypoint using pkg_resources.
        """
        # This is pure Python, so if we're given an operation implementation we
        # will be able to instantiate it
        if opimp is not None:
            return True
        try:
            opimp = OperationImplementation.load(operation.name)
        except FailedToLoadOperationImplementation as error:
            self.logger.debug(
                "OperationImplementation %r is not instantiable: %s",
                operation.name,
                error,
            )
            return False
        return True
github intel / dffml / dffml / df / memory.py View on Github external
async def instantiate(
        self,
        operation: Operation,
        config: BaseConfig,
        *,
        opimp: OperationImplementation = None,
    ) -> bool:
        """
        Instantiate class registered with ____ entrypoint using pkg_resources.
        Return true if instantiation was successful.
        """
        if opimp is None:
            if await self.instantiable(operation):
                opimp = OperationImplementation.load(operation.name)
            else:
                raise OperationImplementationNotInstantiable(operation.name)
        self.operations[
            operation.instance_name
        ] = await self._stack.enter_async_context(opimp(config))
github intel / dffml / dffml / df / memory.py View on Github external
def args(cls, args, *above) -> Dict[str, Arg]:
        # Enable the user to specify operation implementations to be loaded via
        # the entrypoint system (by ParseOperationImplementationAction)
        # TODO opimps should be operations
        cls.config_set(
            args,
            above,
            "opimps",
            Arg(type=OperationImplementation.load, nargs="+", default=[]),
        )
        # Add orig label to above since we are done loading
        above = cls.add_orig_label(*above)
        # Load all the opimps and add the arguments they might require
        # TODO(p4) Should we do this? If someone messes up their entrypoints in
        # one package it will mess up loading anytime this is called.
        """
        for loaded in OperationImplementation.load():
            loaded.args(args, *above)
        """
        return args