stream/Pipeline: Allow Pipeline to be created dynamically.
Ex: self.submodules.pipeline = Pipeline() self.pipeline.add(m0) self.pipeline.add(m1) self.pipeline.add(m3)
This commit is contained in:
parent
c6ccb626e8
commit
2a27ca18ea
|
@ -940,14 +940,20 @@ class Pack(Module):
|
|||
|
||||
class Pipeline(Module):
|
||||
def __init__(self, *modules):
|
||||
n = len(modules)
|
||||
m = modules[0]
|
||||
self.modules = list(modules)
|
||||
|
||||
def add(self, module):
|
||||
self.modules.append(module)
|
||||
|
||||
def do_finalize(self):
|
||||
n = len(self.modules)
|
||||
m = self.modules[0]
|
||||
# Expose sink of first module if available.
|
||||
if hasattr(m, "sink"):
|
||||
self.sink = m.sink
|
||||
# Iterate on Modules/Endpoints.
|
||||
for i in range(1, n):
|
||||
m_n = modules[i]
|
||||
m_n = self.modules[i]
|
||||
# If m is an Endpoint, use it as Source, else use Module.source.
|
||||
source = m if isinstance(m, Endpoint) else m.source
|
||||
# If m_n is an Endpoint, use it as Sink, else use Module.sink.
|
||||
|
|
Loading…
Reference in New Issue