def __init__(self, setup=None, teardown=None): """ :param setup: the callable executed as setup :type setup: callable or None :param teardown: the callable executed as teardown :type teardown: callable or None """ super(Hook, self).__init__() self.setup = default(setup, lambda: None) self.teardown = default(teardown, lambda: None)
def _check_flow(self, flow): """ Check the flow for validity. That is: - all Edges are valid (inputs/outputs exist) - all Sinks are saturated :param flow: flow to check :type flow: sequence of :class:`~penchy.jobs.dependency.Edge` :returns: if flow is valid :rtype: bool """ valid = True sources_of_sinks = defaultdict(list) for edge in flow: if not edge.check(): log.error('Error at connection from "{0}" to "{1}"' .format(edge.source.__class__.__name__, edge.sink.__class__.__name__)) valid = False source_name_mapping = (edge.source.__class__.__name__, default(edge.map_, [(name, name) for name in edge.source.outputs.names])) sources_of_sinks[edge.sink].append(source_name_mapping) for sink, source_mappings in sources_of_sinks.items(): if not sink.inputs.check_sink(source_mappings): log.error('Error at sink "{0}"'.format(sink.__class__.__name__)) valid = False return valid
def __init__(self, jvm, node_setting, name=None): """ :param jvm: the associated jvm :type jvm: :class:`~penchy.jobs.jvms.JVM` :param node_setting: the node setting :type node_setting: :class:`NodeSetting` """ self.name = default(name, "{0} @ {1}".format(jvm, node_setting)) self.jvm = jvm self.node_setting = node_setting self._flow = []
def _build_environment(self): """ Return the environment for a :class:`SystemFilter`. Contains: - ``receive``: to get all data that has been received, takes no arguments returns a dict with :class:`SystemComposition` as keys - ``send``: to send data to the server, takes one datum as argument - ``job``: the filename this job - ``current_composition``: the current :class:`SystemComposition` or ``None`` :returns: environment for a SystemFilter :rtype: dict """ # replace receive and send with dummy functions if not set to avoid # corner cases in pipeline receive = default(self.receive, lambda: {}) send = default(self.send, lambda data: None) return dict(receive=receive, send=send, job=self.filename, current_composition=self._composition)