diff --git a/src/fluxus/_producer.py b/src/fluxus/_producer.py index 6c12bba..ab8d81b 100644 --- a/src/fluxus/_producer.py +++ b/src/fluxus/_producer.py @@ -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. @@ -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]""" diff --git a/src/fluxus/core/producer/_producer_base.py b/src/fluxus/core/producer/_producer_base.py index ed64f73..710a89e 100644 --- a/src/fluxus/core/producer/_producer_base.py +++ b/src/fluxus/core/producer/_producer_base.py @@ -49,7 +49,7 @@ 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. @@ -57,7 +57,7 @@ def iter(self) -> Iterator[T_Product_ret]: """ @abstractmethod - def aiter(self) -> AsyncIterator[T_Product_ret]: + def aproduce(self) -> AsyncIterator[T_Product_ret]: """ Generate new products asynchronously. @@ -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] @@ -135,7 +135,7 @@ 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. @@ -143,7 +143,7 @@ async def aiter(self) -> AsyncIterator[T_Product_ret]: :return: the new products """ - for product in self.iter(): + for product in self.produce(): yield product def __rshift__( @@ -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. @@ -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. @@ -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() ) diff --git a/src/fluxus/core/transformer/_chained_.py b/src/fluxus/core/transformer/_chained_.py index 302cd74..0cabba9 100644 --- a/src/fluxus/core/transformer/_chained_.py +++ b/src/fluxus/core/transformer/_chained_.py @@ -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) @@ -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) @@ -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 diff --git a/src/fluxus/functional/conduit/_producer.py b/src/fluxus/functional/conduit/_producer.py index 3ceca67..9954493 100644 --- a/src/fluxus/functional/conduit/_producer.py +++ b/src/fluxus/functional/conduit/_producer.py @@ -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() diff --git a/src/fluxus/lineage/_label.py b/src/fluxus/lineage/_label.py index fe148a2..f4faf29 100644 --- a/src/fluxus/lineage/_label.py +++ b/src/fluxus/lineage/_label.py @@ -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) diff --git a/src/fluxus/py.typed b/src/fluxus/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/fluxus/simple/_simple.py b/src/fluxus/simple/_simple.py index 8c90f8e..b690e96 100644 --- a/src/fluxus/simple/_simple.py +++ b/src/fluxus/simple/_simple.py @@ -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) @@ -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) diff --git a/src/fluxus/viz/_flow.py b/src/fluxus/viz/_flow.py index 79f02f2..74817dd 100644 --- a/src/fluxus/viz/_flow.py +++ b/src/fluxus/viz/_flow.py @@ -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, diff --git a/src/fluxus/viz/_graph.py b/src/fluxus/viz/_graph.py index 06a8c85..6e4ecab 100644 --- a/src/fluxus/viz/_graph.py +++ b/src/fluxus/viz/_graph.py @@ -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, @@ -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) @@ -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) @@ -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. """ diff --git a/test/fluxus_test/test_flow.py b/test/fluxus_test/test_flow.py index e4b7018..69d4823 100644 --- a/test/fluxus_test/test_flow.py +++ b/test/fluxus_test/test_flow.py @@ -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)) diff --git a/test/fluxus_test/test_lineage.py b/test/fluxus_test/test_lineage.py index 6deba19..7b5e49e 100644 --- a/test/fluxus_test/test_lineage.py +++ b/test/fluxus_test/test_lineage.py @@ -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()