Base

Base classes for DFFML. All classes in DFFML should inherit from these so that they follow a similar API for instantiation and usage.

class dffml.base.BaseConfig[source]

All DFFML Base Objects should take an object (likely a typing.NamedTuple) as as their config.

no_enforce_immutable()

By default, all properties of a config object are immutable. If you would like to mutate immutable properties, you must explicitly call this method using it as a context manager.

Examples

>>> from dffml import config
>>>
>>> @config
... class MyConfig:
...     C: int
>>>
>>> config = MyConfig(C=2)
>>> with config.no_enforce_immutable():
...     config.C = 1
class dffml.base.BaseConfigurable(config: Optional[Type[BaseConfig]])[source]

Class which produces a config for itself by providing Args to a CMD (from dffml.util.cli.base) and then using a CMD after it contains parsed args to instantiate a config (deriving from BaseConfig) which will be used as the only parameter to the __init__ of a BaseDataFlowFacilitatorObject.

classmethod args(args, *above) Dict[str, Arg][source]

Return a dict containing arguments required for this class

classmethod config(config, *above)[source]

Create the BaseConfig required to instantiate this class by parsing the config dict.

classmethod type_for(param: Parameter)[source]

Guess the type based off the default value of the parameter, for when a parameter doesn’t have a type annotation.

class dffml.base.BaseConfigurableMetaClass(name, bases, props, module=None)[source]
classmethod wrap(func)[source]

If a subclass of BaseConfigurable is passed keyword arguments, convert them into the instance of the CONFIG class.

class dffml.base.BaseDataFlowFacilitatorObject(config: Optional[Type[BaseConfig]])[source]

Base class for all Data Flow Facilitator objects conforming to the instantiate -> enter context -> return context via __call__ -> enter returned context’s context pattern. Therefore they must contain a CONTEXT property, set to the BaseDataFlowFacilitatorObjectContext which will be returned from a __call__ to this class.

DFFML is plugin based using Python’s setuptool’s entrypoint API. All classes inheriting from BaseDataFlowFacilitatorObject must have a property named ENTRYPOINT. In the form of dffml.load_point which will be used to load all classes registered to that entry point.

>>> import asyncio
>>> from dffml import *
>>>
>>> # Create the base object. Then enter it's context to preform any initial
>>> # setup. Call obj to get an instance of obj.CONTEXT, which is a subclass
>>> # of BaseDataFlowFacilitatorObjectContext. ctx, the inner context, does
>>> # all the heavy lifting.
>>>
>>> class Context(BaseDataFlowFacilitatorObjectContext):
...     async def method(self):
...         return
>>>
>>> class Object(BaseDataFlowFacilitatorObject):
...     CONTEXT = Context
...     def __call__(self):
...         return Context()
>>>
>>> async def main():
...     async with Object(BaseConfig()) as obj:
...         async with obj() as ctx:
...             await ctx.method()
>>>
>>> asyncio.run(main())
class dffml.base.BaseDataFlowFacilitatorObjectContext[source]

Base class for all Data Flow Facilitator object’s contexts. These are classes which support async context management. Classes ending with …Context are the most inner context’s which are used in DFFML.

See the :class:BaseDataFlowFacilitatorObject for example usage.

exception dffml.base.ConfigAndKWArgsMutuallyExclusive[source]

Raised when both kwargs and config are specified.

exception dffml.base.ImmutableConfigPropertyError[source]

Raised when config property was changed but was not marked as mutable.

class dffml.base.LoggingLogger[source]

Provide the logger property using Python’s builtin logging module.

exception dffml.base.MissingArg[source]

Raised when a BaseConfigurable is missing an argument from the args dict it created with args(). If this exception is raised then the config() method is attempting to retrive an argument which was not set in the args() method.

exception dffml.base.MissingConfig[source]

Raised when a BaseConfigurable is missing an argument from the config dict. Also raised if there was no default value set and the argument is missing.

exception dffml.base.MissingRequiredProperty[source]

Raised when a BaseDataFlowFacilitatorObject is missing some property which should have been defined in the class.

exception dffml.base.NoMutableCallbacksError[source]

Raised when a config property is mutated but there are not mutable callbacks present to handle it’s update.

class dffml.base.ParseExpandAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]
dffml.base.config(cls)[source]

Decorator to create a dataclass

dffml.base.config_ensure_immutable_init(self)[source]

Initialize immutable support config instance local variables.

We can’t call this on __init__ so we call it whenever we are about to use it.

dffml.base.config_make_getter(key)[source]

Create a getter function for use with property() on config objects.

dffml.base.config_make_setter(key, immutable)[source]

Create a setter function for use with property() on config objects.

dffml.base.config_no_enforce_immutable(self)[source]

By default, all properties of a config object are immutable. If you would like to mutate immutable properties, you must explicitly call this method using it as a context manager.

Examples

>>> from dffml import config
>>>
>>> @config
... class MyConfig:
...     C: int
>>>
>>> config = MyConfig(C=2)
>>> with config.no_enforce_immutable():
...     config.C = 1
dffml.base.field(description: str, *args, action=None, required: bool = False, labeled: bool = False, mutable: bool = False, metadata: Optional[dict] = None, **kwargs)[source]

Creates an instance of dataclasses.field(). The first argument, description is the description of the field, and will be set as the "description" key in the metadata dict.

dffml.base.list_action(list_cls)[source]

Action to take a list of values and make them values in the list of type list_class. Which will be a class descendent from AsyncContextManagerList.

dffml.base.make_config(cls_name: str, fields, *args, namespace=None, **kwargs)[source]

Function to create a dataclass