Beispiel #1
0
def _resolve_registry_points(cls, base, dct):
    module = cls.__module__
    parents = [x for x in cls.__mro__ if x not in (cls, SpecSet, object)]

    for k, v in dct.items():
        if isinstance(v, RegistryPoint):
            # add v under its name to this class's registry.
            v.__name__ = k
            cls.registry[k] = v

        if is_datasource(v):
            v.__qualname__ = ".".join([cls.__name__, k])
            v.__name__ = k
            v.__module__ = module
            setattr(cls, k, SpecDescriptor(v))
            if k in base.registry:
                # if the datasource has the same name as a RegistryPoint in the
                # base class, the datasource to the RegistryPoint.
                point = base.registry[k]

                # the RegistryPoint gets the implementation datasource as a
                # dependency
                dr.add_dependency(point, v)
                dr.mark_hidden(v)

                # Datasources override previously defined datasources of the
                # same name for contexts they all depend on. Here we tell
                # datasources of the same name not to execute under contexts
                # the new datasource will handle.
                _register_context_handler(parents, v)
Beispiel #2
0
def first_of(deps):
    """ Given a list of dependencies, returns the first of the list
        that exists in the broker. At least one must be present, or this
        component won't fire.
    """
    dr.mark_hidden(deps)

    @datasource(deps)
    def inner(broker):
        for c in deps:
            if c in broker:
                return broker[c]

    return inner
Beispiel #3
0
def _resolve_registry_points(cls, base, dct):
    module = cls.__module__
    parents = [x for x in cls.__mro__ if x not in (cls, SpecSet, object)]

    for k, v in dct.items():
        if isinstance(v, RegistryPoint):
            v.__name__ = k
            cls.registry[k] = v

        if is_datasource(v):
            v.__qualname__ = ".".join([cls.__name__, k])
            v.__name__ = k
            v.__module__ = module
            setattr(cls, k, SpecDescriptor(v))
            if k in base.registry:
                point = base.registry[k]
                dr.add_dependency(point, v)
                dr.mark_hidden(v)
                _register_context_handler(parents, v)
Beispiel #4
0
def first_of(deps):
    """ Given a list of dependencies, returns the first of the list
        that exists in the broker. At least one must be present, or this
        component won't fire.
    """
    dr.mark_hidden(deps)

    @datasource(deps)
    def inner(broker):
        for c in deps:
            if c in broker:
                return broker[c]

    docs = [
        escape(d)
        if isinstance(d, list) and d.func_name != 'inner' else d.__doc__
        for d in deps if d.__doc__
    ]
    docs = [enc(d) for d in docs]
    inner.__doc__ = b",".join([b"Returns the first of the following:"] + docs)
    return inner
Beispiel #5
0
 def __init__(self, deps):
     self.deps = deps
     self.raw = deps[0].raw
     dr.mark_hidden(deps)
     self.__name__ = self.__class__.__name__
     datasource(deps)(self)