Util Entrypoint

Loader subclasses know how to load classes under their entry point which conform to their subclasses.

class dffml.util.entrypoint.Entrypoint[source]

Uses the pkg_resources.iter_entry_points on the ENTRYPOINT of the class

classmethod load(loading=None)[source]

Loads all installed loading and returns them as a list. Sources to be loaded should be registered to ENTRYPOINT via setuptools.

classmethod load_dict(to_load: Dict[str, str])[source]

Loads each class tagged with the key it should be accessed by without instantiating it.

classmethod load_multiple(to_load: List[str])[source]

Loads each class requested without instantiating it.

exception dffml.util.entrypoint.EntrypointNotFound[source]
exception dffml.util.entrypoint.MissingLabel[source]
dffml.util.entrypoint.base_entry_point(entrypoint, *args)[source]

Any class which subclasses from Entrypoint needs this decorator applied to it. The decorator sets the ENTRYPOINT and ENTRY_POINT_NAME properties on the class.

This allows the load() classmethod to be called to load subclasses of the class being decorated. This is how the subclasses get loaded via the entry point system by calling BaseClass.load().

ENTRY_POINT_NAME corresponds to the command line argument and config file reference to the class. It comes from all arguments after the entrypoint argument (first argument) is a list which would turn into an command line argument if it were joined with hyphens.

Examples

>>> from dffml import base_entry_point, Entrypoint
>>>
>>> @base_entry_point('dffml.entrypoint', 'entrypoint')
... class BaseEntrypointSubclassClass(Entrypoint): pass
entry_points={
    # dffml.entrypoint = ENTRYPOINT
    'dffml.entrypoint': [
        'mylabel = module.path.to:EntrypointSubclassClass',
    ]
}
dffml.util.entrypoint.entrypoint(label)[source]

If a class if going to be registered with setuptools as an entrypoint it must have the label it will be registered under associated with it via this decorator.

This decorator sets the ENTRY_POINT_ORIG_LABEL and ENTRY_POINT_LABEL class proprieties to the same value, label.

Examples

>>> from dffml import entrypoint, Entrypoint
>>>
>>> @entrypoint('mylabel')
... class EntrypointSubclassClass(Entrypoint): pass

In setup.py, EntrypointSubclassClass needs to have this decorator applied to it with label set to mylabel.

entry_points={
    'dffml.entrypoint': [
        'mylabel = module.path.to:EntrypointSubclassClass',
    ]
}
dffml.util.entrypoint.load(*args: str, relative: Optional[Union[str, Path]] = None) Iterator[Any][source]

Load objects given the entrypoint formatted path to the object. Roughly how the python stdlib docs say entrypoint loading works.