Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/setup' into dev/1.0rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Moon committed Jun 17, 2024
2 parents b0acf9c + 6036e8b commit a7c95ef
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/fluxus/_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AsyncProducer(Producer[T_Product_ret], Generic[T_Product_ret], metaclass=A
"""

@final
def iter(self) -> Iterator[T_Product_ret]:
def produce(self) -> Iterator[T_Product_ret]:
"""
Generate new products, optionally using an existing producer as input.
Expand All @@ -91,8 +91,8 @@ def iter(self) -> Iterator[T_Product_ret]:
:raises RuntimeError: if called from within an event loop
"""

return arun(iter_async_to_sync(self.aiter()))
return arun(iter_async_to_sync(self.aproduce()))

@abstractmethod
def aiter(self) -> AsyncIterator[T_Product_ret]:
def aproduce(self) -> AsyncIterator[T_Product_ret]:
"""[see superclass]"""
18 changes: 9 additions & 9 deletions src/fluxus/core/producer/_producer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class BaseProducer(Source[T_Product_ret], Generic[T_Product_ret], metaclass=ABCM
"""

@abstractmethod
def iter(self) -> Iterator[T_Product_ret]:
def produce(self) -> Iterator[T_Product_ret]:
"""
Generate new products.
:return: the new products
"""

@abstractmethod
def aiter(self) -> AsyncIterator[T_Product_ret]:
def aproduce(self) -> AsyncIterator[T_Product_ret]:
"""
Generate new products asynchronously.
Expand All @@ -74,11 +74,11 @@ def aiter_concurrent_conduits(self) -> AsyncIterator[SerialProducer[T_Product_re

@final
def __iter__(self) -> Iterator[T_Product_ret]:
return self.iter()
return self.produce()

@final
def __aiter__(self) -> AsyncIterator[T_Product_ret]:
return self.aiter()
return self.aproduce()

def __and__(
self, other: BaseProducer[T_Product_ret]
Expand Down Expand Up @@ -135,15 +135,15 @@ async def aiter_concurrent_conduits(
"""[see superclass]"""
yield self

async def aiter(self) -> AsyncIterator[T_Product_ret]:
async def aproduce(self) -> AsyncIterator[T_Product_ret]:
"""
Generate new products asynchronously.
By default, defers to the synchronous variant, :meth:`.iter`.
:return: the new products
"""
for product in self.iter():
for product in self.produce():
yield product

def __rshift__(
Expand All @@ -169,7 +169,7 @@ class ConcurrentProducer(
A collection of one or more producers.
"""

def iter(self) -> Iterator[T_Product_ret]:
def produce(self) -> Iterator[T_Product_ret]:
"""
Generate new products from all producers in this group.
Expand All @@ -178,7 +178,7 @@ def iter(self) -> Iterator[T_Product_ret]:
for producer in self.iter_concurrent_conduits():
yield from producer

def aiter(self) -> AsyncIterator[T_Product_ret]:
def aproduce(self) -> AsyncIterator[T_Product_ret]:
"""
Generate new products from all producers in this group asynchronously.
Expand All @@ -189,5 +189,5 @@ def aiter(self) -> AsyncIterator[T_Product_ret]:

# noinspection PyTypeChecker
return async_flatten(
producer.aiter() async for producer in self.aiter_concurrent_conduits()
producer.aproduce() async for producer in self.aiter_concurrent_conduits()
)
14 changes: 7 additions & 7 deletions src/fluxus/core/transformer/_chained_.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def _processor(
"""[see superclass]"""
return self.transformer

def iter(self) -> Iterator[T_TransformedProduct_ret]:
def produce(self) -> Iterator[T_TransformedProduct_ret]:
"""[see superclass]"""
return self.transformer.iter(self._producer)

def aiter(self) -> AsyncIterator[T_TransformedProduct_ret]:
def aproduce(self) -> AsyncIterator[T_TransformedProduct_ret]:
"""[see superclass]"""
return self.transformer.aiter(self._producer)

Expand Down Expand Up @@ -538,10 +538,10 @@ class _BufferedProducer(
source: SerialProducer[T_Output_ret]
_products: list[T_Output_ret] | None = None

def iter(self) -> Iterator[T_Output_ret]:
def produce(self) -> Iterator[T_Output_ret]:
"""[see superclass]"""
if self._products is None:
self._products = list(self.source.iter())
self._products = list(self.source.produce())
return iter(self._products)


Expand Down Expand Up @@ -585,15 +585,15 @@ def create(
"""
return (
_AsyncBufferedProducer(source=source, products=products, k=k)
for k, products in enumerate(_async_iter_parallel(source.aiter(), n))
for k, products in enumerate(_async_iter_parallel(source.aproduce(), n))
)

def iter(self) -> Iterator[T_Output_ret]:
def produce(self) -> Iterator[T_Output_ret]:
raise NotImplementedError(
"Not implemented; use `aiter` to iterate asynchronously."
)

def aiter(self) -> AsyncIterator[T_Output_ret]:
def aproduce(self) -> AsyncIterator[T_Output_ret]:
return self.products


Expand Down
2 changes: 1 addition & 1 deletion src/fluxus/functional/conduit/_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(
super().__init__(name=name)
self.producer = producer

async def aiter(self) -> AsyncIterator[DictProduct]:
async def aproduce(self) -> AsyncIterator[DictProduct]:
"""[see superclass]"""
products = self.producer()

Expand Down
8 changes: 4 additions & 4 deletions src/fluxus/lineage/_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ def product_type(self) -> type[T_Product_ret]:
# _Delegator class
return self._delegate.product_type

def iter(self) -> Iterator[T_Product_ret]:
def produce(self) -> Iterator[T_Product_ret]:
"""[see superclass]"""
for product in self._delegate.iter():
for product in self._delegate.produce():
yield product.label(**self._labels)

async def aiter(self) -> AsyncIterator[T_Product_ret]:
async def aproduce(self) -> AsyncIterator[T_Product_ret]:
"""[see superclass]"""
async for product in self._delegate.aiter():
async for product in self._delegate.aproduce():
yield product.label(**self._labels)


Expand Down
Empty file added src/fluxus/py.typed
Empty file.
4 changes: 2 additions & 2 deletions src/fluxus/simple/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, products: Iterable[T_Product_ret]) -> None:
f"{product_type}: " + ", ".join(map(repr, mismatched_products))
)

def iter(self) -> Iterator[T_Product_ret]:
def produce(self) -> Iterator[T_Product_ret]:
"""[see superclass]"""
return iter(self.products)

Expand All @@ -95,6 +95,6 @@ def __init__(self, products: AsyncIterable[T_Product_ret]) -> None:
"""
self.products = products

def aiter(self) -> AsyncIterator[T_Product_ret]:
def aproduce(self) -> AsyncIterator[T_Product_ret]:
"""[see superclass]"""
return aiter(self.products)
1 change: 1 addition & 0 deletions src/fluxus/viz/_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def render_flow(self, flow: Conduit[Any]) -> None: # pragma: no cover
FlowGraph.from_conduit(flow).to_dot(
font="Monaco, Consolas, monospace",
fontcolor=color_scheme.contrast_color(color_scheme.accent_1),
fontcolor_terminal=color_scheme.contrast_color(color_scheme.background),
fontsize=10,
foreground=color_scheme.foreground,
background=color_scheme.background,
Expand Down
7 changes: 6 additions & 1 deletion src/fluxus/viz/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def to_dot(
font: str | None = None,
fontsize: float | None = None,
fontcolor: RgbColor | RgbaColor | None = None,
fontcolor_terminal: RgbColor | RgbaColor | None = None,
background: RgbColor | RgbaColor | None = None,
foreground: RgbColor | RgbaColor | None = None,
fill: RgbColor | RgbaColor | None = None,
Expand All @@ -108,6 +109,8 @@ def to_dot(
:param font: the font of the graph (optional)
:param fontsize: the font size (optional)
:param fontcolor: the text color of the graph (defaults to the foreground color)
:param fontcolor_terminal: the text color of the terminal nodes (defaults to the
font color of regular nodes)
:param background: the background color of the graph (optional)
:param foreground: the foreground color of the graph (optional)
:param fill: the fill color of the nodes (optional)
Expand Down Expand Up @@ -190,6 +193,8 @@ def _node_id(_node: Conduit[Any]) -> str:
if isinstance(node, (BaseProducer, Consumer)):
# Producers and consumers don't get filled, just rounded
node_attrs["style"] = "rounded"
if fontcolor_terminal:
node_attrs["fontcolor"] = fontcolor_terminal.hex

digraph.add_node(_node_id(node), **node_attrs)

Expand Down Expand Up @@ -345,7 +350,7 @@ def shape(self) -> str:
"""[see superclass]"""
return "circle"

def iter(self) -> Iterator[Never]: # pragma: no cover
def produce(self) -> Iterator[Never]: # pragma: no cover
"""
Yield nothing.
"""
Expand Down
2 changes: 1 addition & 1 deletion test/fluxus_test/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, start: int, stop: int) -> None:
self.start = start
self.stop = stop

def iter(self) -> Iterator[int]:
def produce(self) -> Iterator[int]:
return iter(range(self.start, self.stop))


Expand Down
2 changes: 1 addition & 1 deletion test/fluxus_test/test_lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OriginProducer(LabelingProducer[Origin]):
A producer of ``Origin`` products.
"""

def iter(self) -> Iterator[Origin]:
def produce(self) -> Iterator[Origin]:
yield Origin()


Expand Down

0 comments on commit a7c95ef

Please sign in to comment.