Skip to content

Commit

Permalink
some documentation. add register process decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Jan 3, 2024
1 parent f32ec41 commit b07f26b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion process_bigraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pprint
from process_bigraph.protocols import local_lookup
from process_bigraph.registry import protocol_registry, process_registry
from process_bigraph.registry import protocol_registry, process_registry,register_process
from process_bigraph.emitter import ConsoleEmitter, RAMEmitter, DatabaseEmitter
from process_bigraph.composite import Process, Step, Composite
from process_bigraph.type_system import types
Expand Down
16 changes: 16 additions & 0 deletions process_bigraph/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@
#: Maps process names to :term:`protocol methods`
protocol_registry = Registry()

# decorator to register processes
def register_process(name):
"""Register a process with the process registry.
:param name: The name of the process.
:Example:
@register_process('my_process')
class MyProcess(Process):
...
"""
def decorator(func):
process_registry.register(name, func)
return func

return decorator
15 changes: 13 additions & 2 deletions process_bigraph/type_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def divide_process(value, bindings=None, types=None):


def serialize_process(value, bindings=None, types=None):
"""Serialize a process to a JSON-safe representation."""
# TODO -- need to get back the protocol: address and the config
process = value.copy()
del process['instance']
Expand All @@ -49,6 +50,16 @@ def serialize_process(value, bindings=None, types=None):


def deserialize_process(serialized, bindings=None, types=None):
"""Deserialize a process from a serialized state.
This function is used by the type system to deserialize a process.
:param serialized: A JSON-safe representation of the process.
:param bindings: The bindings to use for deserialization.
:param types: The type system to use for deserialization.
:returns: The deserialized state with an instantiated process.
"""
deserialized = serialized.copy()
protocol, address = serialized['address'].split(':', 1)

Expand Down Expand Up @@ -161,11 +172,11 @@ def __init__(self):


def infer_schema(self, schema, state, top_state=None, path=None):
'''
"""
Given a schema fragment and an existing state with _type keys,
return the full schema required to describe that state,
and whatever state was hydrated (processes/steps) during this process
'''
"""

schema = schema or {}
# TODO: deal with this
Expand Down

0 comments on commit b07f26b

Please sign in to comment.