posted 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
posted-0.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
posted-0.0.2/PKG-INFO ADDED
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.1
2
+ Name: posted
3
+ Version: 0.0.2
4
+ Summary: Interfacing with message-broker functionality
5
+ Home-page: https://github.com/i2mint/posted
6
+ Author: OtoSense
7
+ License: mit
8
+ Platform: any
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+
12
+
13
+ # posted
14
+ Interfacing with message-broker functionality
15
+
16
+
17
+ To install: ```pip install posted```
18
+
19
+
20
+ # Examples
21
+
22
+ ## ReactiveScope
23
+
24
+ A scope that reacts to writes by computing associated functions, themselves writing in the scope, creating a chain reaction that propagates information through the scope.
25
+
26
+ Parameters
27
+ ----------
28
+ func_nodes : Iterable[ReactiveFuncNode]
29
+ The functions that will be called when the scope is written to.
30
+ scope_factory : Callable[[], MutableMapping]
31
+ A factory that returns a new scope. The scope will be cleared by calling this
32
+ factory at each call to `.clear()`.
33
+
34
+ Examples
35
+ --------
36
+
37
+ First, we need some func nodes to define the reaction relationships.
38
+ We'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.
39
+
40
+
41
+ >>> from meshed import FuncNode, DAG
42
+ >>>
43
+ >>> def f(a, b):
44
+ ... return a + b
45
+ >>> def g(a_plus_b, d):
46
+ ... return a_plus_b * d
47
+ >>> f_node = FuncNode(func=f, out='a_plus_b')
48
+ >>> g_node = FuncNode(func=g, bind={'d': 'b'})
49
+ >>> d = DAG((f_node, g_node))
50
+ >>>
51
+ >>> print(d.dot_digraph_ascii())
52
+ <BLANKLINE>
53
+ a
54
+ <BLANKLINE>
55
+ │
56
+ │
57
+ ▼
58
+ ┌────────┐
59
+ b ──▶ │ f │
60
+ └────────┘
61
+ │ │
62
+ │ │
63
+ │ ▼
64
+ │
65
+ │ a_plus_b
66
+ │
67
+ │ │
68
+ │ │
69
+ │ ▼
70
+ │ ┌────────┐
71
+ └─────▶ │ g_ │
72
+ └────────┘
73
+ │
74
+ │
75
+ ▼
76
+ <BLANKLINE>
77
+ g
78
+ <BLANKLINE>
79
+
80
+ Now we make a scope with these func nodes.
81
+
82
+ >>> s = ReactiveScope(d)
83
+
84
+ The scope starts empty (by default).
85
+
86
+ >>> s
87
+ <ReactiveScope with .scope: {}>
88
+
89
+ So if we try to access any key, we'll get a KeyError.
90
+
91
+ >>> s['g'] # doctest: +IGNORE_EXCEPTION_DETAIL
92
+ Traceback (most recent call last):
93
+ ...
94
+ KeyError: 'g'
95
+
96
+ That's because we didn't put write anything in the scope yet.
97
+
98
+ But, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you
99
+ write values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.
100
+
101
+ >>> s['b'] = 3
102
+ >>> s['a_plus_b'] = 5
103
+ >>> s
104
+ <ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>
105
+
106
+ So now we can access ``g``.
107
+
108
+ >>> s['g']
109
+ 15
110
+
111
+ Note though, that we first showed that ``g`` appeared in the scope before we
112
+ explicitly asked for it. This was to show that ``g`` was computed as a
113
+ side-effect of writing to the scope, not because we asked for it, triggering the
114
+ computation
115
+
116
+ Let's clear the scope and show that by specifying ``a`` and ``b``, we get all the
117
+ other values of the network.
118
+
119
+ >>> s.clear()
120
+ >>> s
121
+ <ReactiveScope with .scope: {}>
122
+ >>> s['a'] = 3
123
+ >>> s['b'] = 4
124
+ >>> s
125
+ <ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>
126
+ >>> s['g'] # (3 + 4) * 4 == 7 * 4 == 28
127
+ 28
posted-0.0.2/README.md ADDED
@@ -0,0 +1,116 @@
1
+
2
+ # posted
3
+ Interfacing with message-broker functionality
4
+
5
+
6
+ To install: ```pip install posted```
7
+
8
+
9
+ # Examples
10
+
11
+ ## ReactiveScope
12
+
13
+ A scope that reacts to writes by computing associated functions, themselves writing in the scope, creating a chain reaction that propagates information through the scope.
14
+
15
+ Parameters
16
+ ----------
17
+ func_nodes : Iterable[ReactiveFuncNode]
18
+ The functions that will be called when the scope is written to.
19
+ scope_factory : Callable[[], MutableMapping]
20
+ A factory that returns a new scope. The scope will be cleared by calling this
21
+ factory at each call to `.clear()`.
22
+
23
+ Examples
24
+ --------
25
+
26
+ First, we need some func nodes to define the reaction relationships.
27
+ We'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.
28
+
29
+
30
+ >>> from meshed import FuncNode, DAG
31
+ >>>
32
+ >>> def f(a, b):
33
+ ... return a + b
34
+ >>> def g(a_plus_b, d):
35
+ ... return a_plus_b * d
36
+ >>> f_node = FuncNode(func=f, out='a_plus_b')
37
+ >>> g_node = FuncNode(func=g, bind={'d': 'b'})
38
+ >>> d = DAG((f_node, g_node))
39
+ >>>
40
+ >>> print(d.dot_digraph_ascii())
41
+ <BLANKLINE>
42
+ a
43
+ <BLANKLINE>
44
+ │
45
+ │
46
+ ▼
47
+ ┌────────┐
48
+ b ──▶ │ f │
49
+ └────────┘
50
+ │ │
51
+ │ │
52
+ │ ▼
53
+ │
54
+ │ a_plus_b
55
+ │
56
+ │ │
57
+ │ │
58
+ │ ▼
59
+ │ ┌────────┐
60
+ └─────▶ │ g_ │
61
+ └────────┘
62
+ │
63
+ │
64
+ ▼
65
+ <BLANKLINE>
66
+ g
67
+ <BLANKLINE>
68
+
69
+ Now we make a scope with these func nodes.
70
+
71
+ >>> s = ReactiveScope(d)
72
+
73
+ The scope starts empty (by default).
74
+
75
+ >>> s
76
+ <ReactiveScope with .scope: {}>
77
+
78
+ So if we try to access any key, we'll get a KeyError.
79
+
80
+ >>> s['g'] # doctest: +IGNORE_EXCEPTION_DETAIL
81
+ Traceback (most recent call last):
82
+ ...
83
+ KeyError: 'g'
84
+
85
+ That's because we didn't put write anything in the scope yet.
86
+
87
+ But, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you
88
+ write values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.
89
+
90
+ >>> s['b'] = 3
91
+ >>> s['a_plus_b'] = 5
92
+ >>> s
93
+ <ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>
94
+
95
+ So now we can access ``g``.
96
+
97
+ >>> s['g']
98
+ 15
99
+
100
+ Note though, that we first showed that ``g`` appeared in the scope before we
101
+ explicitly asked for it. This was to show that ``g`` was computed as a
102
+ side-effect of writing to the scope, not because we asked for it, triggering the
103
+ computation
104
+
105
+ Let's clear the scope and show that by specifying ``a`` and ``b``, we get all the
106
+ other values of the network.
107
+
108
+ >>> s.clear()
109
+ >>> s
110
+ <ReactiveScope with .scope: {}>
111
+ >>> s['a'] = 3
112
+ >>> s['b'] = 4
113
+ >>> s
114
+ <ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>
115
+ >>> s['g'] # (3 + 4) * 4 == 7 * 4 == 28
116
+ 28
File without changes
@@ -0,0 +1 @@
1
+ """To put WIP code"""
@@ -0,0 +1,201 @@
1
+ """Reactive DAG -- An example of how to specify message passing links
2
+ between functions
3
+
4
+ Ideas towards a reactive-programming interpretation of meshes.
5
+
6
+ A scope (MutableMapping --think dict-like) that reacts to writes by computing
7
+ associated functions, themselves writing in the scope, creating a chain reaction that
8
+ propagates information through the scope.
9
+ """
10
+
11
+ from functools import cached_property
12
+
13
+ from meshed import DAG, FuncNode
14
+
15
+ # TODO: Should ReactiveFuncNode exist? Could put the logic in a function and used in
16
+ # ReactiveScope instead.
17
+
18
+
19
+ class ReactiveFuncNode(FuncNode):
20
+ """A ``FuncNode`` that computes on a scope only if the scope has what it takes"""
21
+
22
+ @cached_property
23
+ def _dependencies(self):
24
+ """The keys the scope needs to have so that the FuncNode is callable"""
25
+ return set(self.bind.values())
26
+
27
+ def call_on_scope(self, scope, write_output_into_scope=True):
28
+ if self._dependencies.issubset(scope):
29
+ return super().call_on_scope(scope, write_output_into_scope)
30
+
31
+
32
+ from typing import MutableMapping
33
+
34
+
35
+ # TODO: Don't seem to need the relations to be acyclic. Try it out, and make it work.
36
+ # TODO: If we allow multiple writes/deletes, to a key or even to different keys,
37
+ # we open ourselves to a lot more complexity. We need to be able to detect when
38
+ # existing values are not valid anymore, given the relations exhibited by the func
39
+ # nodes. This is a lot of work, and I'm not sure it's worth it. Might be better to
40
+ # keep the scope as a simple mapping, and protect it from having actions taken on it
41
+ # that might bring it into an invalid state.
42
+ class ReactiveScope(MutableMapping):
43
+ """
44
+ A scope that reacts to writes by computing associated functions, themselves writing
45
+ in the scope, creating a chain reaction that propagates information through the
46
+ scope.
47
+
48
+ Parameters
49
+ ----------
50
+ func_nodes : Iterable[ReactiveFuncNode]
51
+ The functions that will be called when the scope is written to.
52
+ scope_factory : Callable[[], MutableMapping]
53
+ A factory that returns a new scope. The scope will be cleared by calling this
54
+ factory at each call to `.clear()`.
55
+
56
+ Examples
57
+ --------
58
+
59
+ First, we need some func nodes to define the reaction relationships.
60
+ We'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.
61
+
62
+ >>> from meshed import FuncNode, DAG
63
+ >>>
64
+ >>> def f(a, b):
65
+ ... return a + b
66
+ >>> def g(a_plus_b, d):
67
+ ... return a_plus_b * d
68
+ >>> f_node = FuncNode(func=f, out='a_plus_b')
69
+ >>> g_node = FuncNode(func=g, bind={'d': 'b'})
70
+ >>> d = DAG((f_node, g_node))
71
+ >>>
72
+ >>> print(d.dot_digraph_ascii())
73
+ <BLANKLINE>
74
+ a
75
+ <BLANKLINE>
76
+ │
77
+ │
78
+ ▼
79
+ ┌────────┐
80
+ b ──▶ │ f │
81
+ └────────┘
82
+ │ │
83
+ │ │
84
+ │ ▼
85
+ │
86
+ │ a_plus_b
87
+ │
88
+ │ │
89
+ │ │
90
+ │ ▼
91
+ │ ┌────────┐
92
+ └─────▶ │ g_ │
93
+ └────────┘
94
+ │
95
+ │
96
+ ▼
97
+ <BLANKLINE>
98
+ g
99
+ <BLANKLINE>
100
+
101
+ Now we make a scope with these func nodes.
102
+
103
+ >>> s = ReactiveScope(d)
104
+
105
+ The scope starts empty (by default).
106
+
107
+ >>> s
108
+ <ReactiveScope with .scope: {}>
109
+
110
+ So if we try to access any key, we'll get a KeyError.
111
+
112
+ >>> s['g'] # doctest: +IGNORE_EXCEPTION_DETAIL
113
+ Traceback (most recent call last):
114
+ ...
115
+ KeyError: 'g'
116
+
117
+ That's because we didn't put write anything in the scope yet.
118
+
119
+ But, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you
120
+ write values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.
121
+
122
+ >>> s['b'] = 3
123
+ >>> s['a_plus_b'] = 5
124
+ >>> s
125
+ <ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>
126
+
127
+ So now we can access ``g``.
128
+
129
+ >>> s['g']
130
+ 15
131
+
132
+ Note though, that we first showed that ``g`` appeared in the scope before we
133
+ explicitly asked for it. This was to show that ``g`` was computed as a
134
+ side-effect of writing to the scope, not because we asked for it, triggering the
135
+ computation
136
+
137
+ Let's clear the scope and show that by specifying ``a`` and ``b``, we get all the
138
+ other values of the network.
139
+
140
+ >>> s.clear()
141
+ >>> s
142
+ <ReactiveScope with .scope: {}>
143
+ >>> s['a'] = 3
144
+ >>> s['b'] = 4
145
+ >>> s
146
+ <ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>
147
+ >>> s['g'] # (3 + 4) * 4 == 7 * 4 == 28
148
+ 28
149
+ """
150
+
151
+ def __init__(self, func_nodes=(), scope_factory=dict):
152
+ # Note: scope_factory could be made to return a pre-filled dict too
153
+ if isinstance(func_nodes, DAG):
154
+ dag = func_nodes
155
+ func_nodes = dag.func_nodes
156
+ func_nodes = [ReactiveFuncNode.from_dict(fn.to_dict()) for fn in func_nodes]
157
+ self.dag = DAG(func_nodes)
158
+ self.func_nodes_for_var_node = {
159
+ k: v for k, v in self.dag.graph.items() if k in self.dag.var_nodes
160
+ }
161
+ self.scope_factory = scope_factory
162
+ self.clear()
163
+
164
+ def clear(self):
165
+ """Note: This actually doesn't clear the mapping, but rather, resets it to it's original state,
166
+ as defined by the `.scope_factory`"""
167
+ self.scope = self.scope_factory()
168
+
169
+ def __getitem__(self, k):
170
+ # TODO: try/catch and give the user a bit more info (e.g. what dependencies are missing?)
171
+ return self.scope[k]
172
+
173
+ def __setitem__(self, k, v):
174
+ # write the value under the key
175
+ self.scope[k] = v
176
+ # TODO: Need to make sure the func_node are in topological order
177
+ # TODO: The .get(k, ()): prefill with missing keys at init time instead?
178
+ for func_node in self.func_nodes_for_var_node.get(k, ()):
179
+ # "try" calling the func_node on the scope (if scope doesn't have enough
180
+ #
181
+ func_node.call_on_scope(self.scope)
182
+
183
+ def __len__(self):
184
+ return len(self.scope)
185
+
186
+ def __contains__(self, k):
187
+ return k in self.scope
188
+
189
+ def __iter__(self):
190
+ return iter(self.scope)
191
+
192
+ def __delitem__(self, k):
193
+ # TODO: Could use the same mechanism as setitem to propagate the deletion through the network
194
+ raise NotImplementedError(
195
+ "deletion of keys are not implemented, since cache invalidation hasn't. "
196
+ 'You can clear the whole scope with the `.clear()` method. '
197
+ "(Note: This actually doesn't clear the mapping, but rather, resets it to it's original state.)"
198
+ )
199
+
200
+ def __repr__(self):
201
+ return f'<{type(self).__qualname__} with .scope: {repr(self.scope)}>'
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.1
2
+ Name: posted
3
+ Version: 0.0.2
4
+ Summary: Interfacing with message-broker functionality
5
+ Home-page: https://github.com/i2mint/posted
6
+ Author: OtoSense
7
+ License: mit
8
+ Platform: any
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+
12
+
13
+ # posted
14
+ Interfacing with message-broker functionality
15
+
16
+
17
+ To install: ```pip install posted```
18
+
19
+
20
+ # Examples
21
+
22
+ ## ReactiveScope
23
+
24
+ A scope that reacts to writes by computing associated functions, themselves writing in the scope, creating a chain reaction that propagates information through the scope.
25
+
26
+ Parameters
27
+ ----------
28
+ func_nodes : Iterable[ReactiveFuncNode]
29
+ The functions that will be called when the scope is written to.
30
+ scope_factory : Callable[[], MutableMapping]
31
+ A factory that returns a new scope. The scope will be cleared by calling this
32
+ factory at each call to `.clear()`.
33
+
34
+ Examples
35
+ --------
36
+
37
+ First, we need some func nodes to define the reaction relationships.
38
+ We'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.
39
+
40
+
41
+ >>> from meshed import FuncNode, DAG
42
+ >>>
43
+ >>> def f(a, b):
44
+ ... return a + b
45
+ >>> def g(a_plus_b, d):
46
+ ... return a_plus_b * d
47
+ >>> f_node = FuncNode(func=f, out='a_plus_b')
48
+ >>> g_node = FuncNode(func=g, bind={'d': 'b'})
49
+ >>> d = DAG((f_node, g_node))
50
+ >>>
51
+ >>> print(d.dot_digraph_ascii())
52
+ <BLANKLINE>
53
+ a
54
+ <BLANKLINE>
55
+ │
56
+ │
57
+ ▼
58
+ ┌────────┐
59
+ b ──▶ │ f │
60
+ └────────┘
61
+ │ │
62
+ │ │
63
+ │ ▼
64
+ │
65
+ │ a_plus_b
66
+ │
67
+ │ │
68
+ │ │
69
+ │ ▼
70
+ │ ┌────────┐
71
+ └─────▶ │ g_ │
72
+ └────────┘
73
+ │
74
+ │
75
+ ▼
76
+ <BLANKLINE>
77
+ g
78
+ <BLANKLINE>
79
+
80
+ Now we make a scope with these func nodes.
81
+
82
+ >>> s = ReactiveScope(d)
83
+
84
+ The scope starts empty (by default).
85
+
86
+ >>> s
87
+ <ReactiveScope with .scope: {}>
88
+
89
+ So if we try to access any key, we'll get a KeyError.
90
+
91
+ >>> s['g'] # doctest: +IGNORE_EXCEPTION_DETAIL
92
+ Traceback (most recent call last):
93
+ ...
94
+ KeyError: 'g'
95
+
96
+ That's because we didn't put write anything in the scope yet.
97
+
98
+ But, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you
99
+ write values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.
100
+
101
+ >>> s['b'] = 3
102
+ >>> s['a_plus_b'] = 5
103
+ >>> s
104
+ <ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>
105
+
106
+ So now we can access ``g``.
107
+
108
+ >>> s['g']
109
+ 15
110
+
111
+ Note though, that we first showed that ``g`` appeared in the scope before we
112
+ explicitly asked for it. This was to show that ``g`` was computed as a
113
+ side-effect of writing to the scope, not because we asked for it, triggering the
114
+ computation
115
+
116
+ Let's clear the scope and show that by specifying ``a`` and ``b``, we get all the
117
+ other values of the network.
118
+
119
+ >>> s.clear()
120
+ >>> s
121
+ <ReactiveScope with .scope: {}>
122
+ >>> s['a'] = 3
123
+ >>> s['b'] = 4
124
+ >>> s
125
+ <ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>
126
+ >>> s['g'] # (3 + 4) * 4 == 7 * 4 == 28
127
+ 28
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ posted/__init__.py
6
+ posted.egg-info/PKG-INFO
7
+ posted.egg-info/SOURCES.txt
8
+ posted.egg-info/dependency_links.txt
9
+ posted.egg-info/not-zip-safe
10
+ posted.egg-info/top_level.txt
11
+ posted/scrap/__init__.py
12
+ posted/scrap/reactive_dag.py
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ posted
posted-0.0.2/setup.cfg ADDED
@@ -0,0 +1,25 @@
1
+ [metadata]
2
+ name = posted
3
+ version = 0.0.2
4
+ url = https://github.com/i2mint/posted
5
+ platforms = any
6
+ description_file = README.md
7
+ root_url = https://github.com/i2mint/
8
+ license = mit
9
+ author = OtoSense
10
+ description = Interfacing with message-broker functionality
11
+ long_description = file:README.md
12
+ long_description_content_type = text/markdown
13
+ keywords =
14
+ display_name = posted
15
+
16
+ [options]
17
+ packages = find:
18
+ include_package_data = True
19
+ zip_safe = False
20
+ install_requires =
21
+
22
+ [egg_info]
23
+ tag_build =
24
+ tag_date = 0
25
+
posted-0.0.2/setup.py ADDED
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup() # Note: Everything should be in the local setup.cfg