From be87caa99b6bd0907dc3fe154e6e8e33d77ad997 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 12:42:41 -0500 Subject: [PATCH 1/6] Move legacy pubsub stuff from `msg.py` to trionics mod --- tractor/{msg.py => trionics/_pubsub.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tractor/{msg.py => trionics/_pubsub.py} (100%) diff --git a/tractor/msg.py b/tractor/trionics/_pubsub.py similarity index 100% rename from tractor/msg.py rename to tractor/trionics/_pubsub.py From d29a915d48b179bfef08004df46cd092930cdd8b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 12:43:06 -0500 Subject: [PATCH 2/6] Update mod doc string --- tractor/trionics/_pubsub.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tractor/trionics/_pubsub.py b/tractor/trionics/_pubsub.py index caa03ec..e69231c 100644 --- a/tractor/trionics/_pubsub.py +++ b/tractor/trionics/_pubsub.py @@ -15,7 +15,9 @@ # along with this program. If not, see . """ -Messaging pattern APIs and helpers. +Single target entrypoint, remote-task, dynamic (no push if no consumer) +pubsub API using async an generator which muli-plexes to consumers by +key. NOTE: this module is likely deprecated by the new bi-directional streaming support provided by ``tractor.Context.open_stream()`` and friends. From ffe88de53bb7f07e78efb498ca3da752a546ddb5 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 13:43:48 -0500 Subject: [PATCH 3/6] 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()) From 7e004c0688499286c0616fc3f3f9d77f343c72f1 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 14:22:15 -0500 Subject: [PATCH 4/6] Add back blank `msg.py` --- tractor/msg.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tractor/msg.py diff --git a/tractor/msg.py b/tractor/msg.py new file mode 100644 index 0000000..16f4e5c --- /dev/null +++ b/tractor/msg.py @@ -0,0 +1,20 @@ +# 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 . + +''' +Coming soon! + +''' From 070e6ba459b04ea28eb05fcf4ce07f98ab386238 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 14:30:39 -0500 Subject: [PATCH 5/6] Add `.experimental` subpkg to setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index b17bb57..77b43f1 100755 --- a/setup.py +++ b/setup.py @@ -35,6 +35,7 @@ setup( platforms=['linux', 'windows'], packages=[ 'tractor', + 'tractor.experimental', 'tractor.trionics', 'tractor.testing', ], From debbf64d5849e5602fe6845bf0db703ddedaff0a Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 29 Jan 2022 17:58:58 -0500 Subject: [PATCH 6/6] Add nooz --- nooz/298.misc.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 nooz/298.misc.rst diff --git a/nooz/298.misc.rst b/nooz/298.misc.rst new file mode 100644 index 0000000..77a2acc --- /dev/null +++ b/nooz/298.misc.rst @@ -0,0 +1,2 @@ +Add a new `tractor.experimental` subpackage for staging new high level +APIs and subystems that we might eventually make built-ins.