From ffe88de53bb7f07e78efb498ca3da752a546ddb5 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 13:43:48 -0500 Subject: [PATCH] Better idea: start a `tractor.experimental` subpkg --- tests/test_pubsub.py | 9 +++--- tractor/experimental/__init__.py | 29 +++++++++++++++++++ tractor/{trionics => experimental}/_pubsub.py | 13 ++++++--- 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 tractor/experimental/__init__.py rename tractor/{trionics => experimental}/_pubsub.py (98%) diff --git a/tests/test_pubsub.py b/tests/test_pubsub.py index 6243a4e..390ca29 100644 --- a/tests/test_pubsub.py +++ b/tests/test_pubsub.py @@ -5,19 +5,20 @@ import pytest import trio import tractor from tractor.testing import tractor_test +from tractor.experimental import msgpub def test_type_checks(): with pytest.raises(TypeError) as err: - @tractor.msg.pub + @msgpub async def no_get_topics(yo): yield assert "must define a `get_topics`" in str(err.value) with pytest.raises(TypeError) as err: - @tractor.msg.pub + @msgpub def not_async_gen(yo): pass @@ -32,7 +33,7 @@ def is_even(i): _get_topics = None -@tractor.msg.pub +@msgpub async def pubber(get_topics, seed=10): # ensure topic subscriptions are as expected @@ -103,7 +104,7 @@ async def subs( await stream.aclose() -@tractor.msg.pub(tasks=['one', 'two']) +@msgpub(tasks=['one', 'two']) async def multilock_pubber(get_topics): yield {'doggy': 10} diff --git a/tractor/experimental/__init__.py b/tractor/experimental/__init__.py new file mode 100644 index 0000000..4fad3be --- /dev/null +++ b/tractor/experimental/__init__.py @@ -0,0 +1,29 @@ +# tractor: structured concurrent "actors". +# Copyright 2018-eternity Tyler Goodlet. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +''' +Experimental APIs and subsystems not yet validated to be included as +built-ins. + +This is a staging area for ``tractor.builtin``. + +''' +from ._pubsub import pub as msgpub + + +__all__ = [ + 'msgpub', +] diff --git a/tractor/trionics/_pubsub.py b/tractor/experimental/_pubsub.py similarity index 98% rename from tractor/trionics/_pubsub.py rename to tractor/experimental/_pubsub.py index e69231c..7a8ec37 100644 --- a/tractor/trionics/_pubsub.py +++ b/tractor/experimental/_pubsub.py @@ -23,6 +23,7 @@ NOTE: this module is likely deprecated by the new bi-directional streaming support provided by ``tractor.Context.open_stream()`` and friends. """ +from __future__ import annotations import inspect import typing from typing import Dict, Any, Set, Callable, List, Tuple @@ -32,8 +33,9 @@ from async_generator import aclosing import trio import wrapt -from .log import get_logger -from ._streaming import Context +from ..log import get_logger +from .._streaming import Context + __all__ = ['pub'] @@ -45,8 +47,11 @@ async def fan_out_to_ctxs( topics2ctxs: Dict[str, list], packetizer: typing.Callable = None, ) -> None: - """Request and fan out quotes to each subscribed actor channel. - """ + ''' + Request and fan out quotes to each subscribed actor channel. + + ''' + def get_topics(): return tuple(topics2ctxs.keys())