-
Notifications
You must be signed in to change notification settings - Fork 3
Add extensible codec system with Protocol Buffers support and remove IronPython #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7b2b8d9
Initial plan
Copilot 71bceb6
Remove IronPython support and add codec infrastructure
Copilot 8023cdf
Update docstrings and validate codec functionality
Copilot b0b5bd5
Remove old JSON methods from Topic class
Copilot fa73e2e
Update documentation and remove IronPython references
Copilot c648c88
Add codec usage example and fix imports
Copilot 60f32ed
Fix linting errors and remove IronPython CI workflow
Copilot b8fc0dd
Fix remaining lint and style issues
Copilot e9fe014
Refactor codecs to handle message objects directly
Copilot 36a0af7
Address review feedback: move codecs, simplify examples, fix API
Copilot ba9fcab
Remove duplicate MessageCodec and move import to top
Copilot 490749a
Remove JsonMessageCodec from top-level exports
Copilot f5ca830
Fix import in codec_usage.py example
Copilot 07c6a1c
pb stuff
gonzalocasas 2e1ab0a
update dev reqs
gonzalocasas 51dae80
lint
gonzalocasas a7a1685
doc automodule missing
gonzalocasas 187e7eb
doc update
gonzalocasas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
|
|
||
| .. automodule:: compas_eve.codecs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1 @@ | ||
| ******************************************************************************** | ||
| compas_eve | ||
| ******************************************************************************** | ||
|
|
||
| .. automodule:: compas_eve |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """ | ||
| Example demonstrating custom codec usage with COMPAS EVE. | ||
|
|
||
| This example shows how to: | ||
| 1. Use the default JsonMessageCodec | ||
| 2. Create a custom codec | ||
| 3. Use ProtobufMessageCodec (if compas_pb is installed) | ||
| """ | ||
|
|
||
| import json | ||
|
|
||
| import compas_eve as eve | ||
| from compas_eve import MessageCodec | ||
| from compas_eve.codecs import JsonMessageCodec | ||
|
|
||
|
|
||
| # Example 1: Using the default JSON codec (implicit) | ||
| print("=" * 60) | ||
| print("Example 1: Default JSON Codec (implicit)") | ||
| print("=" * 60) | ||
|
|
||
| pub = eve.Publisher("/example/default") | ||
| sub = eve.EchoSubscriber("/example/default") | ||
| sub.subscribe() | ||
|
|
||
| pub.publish(eve.Message(text="Hello with default JSON codec", count=1)) | ||
| print() | ||
|
|
||
|
|
||
| # Example 2: Explicitly using JSON codec | ||
| print("=" * 60) | ||
| print("Example 2: Explicit JSON Codec") | ||
| print("=" * 60) | ||
|
|
||
| json_codec = JsonMessageCodec() | ||
| transport = eve.InMemoryTransport(codec=json_codec) | ||
|
|
||
| pub = eve.Publisher("/example/json", transport=transport) | ||
| sub = eve.EchoSubscriber("/example/json", transport=transport) | ||
| sub.subscribe() | ||
|
|
||
| pub.publish(eve.Message(text="Hello with explicit JSON codec", count=2)) | ||
| print() | ||
|
|
||
|
|
||
| # Example 3: Custom codec | ||
| print("=" * 60) | ||
| print("Example 3: Custom Codec") | ||
| print("=" * 60) | ||
|
|
||
|
|
||
| class UpperCaseCodec(MessageCodec): | ||
| """A simple custom codec that converts all string values to uppercase.""" | ||
|
|
||
| def encode(self, message): | ||
| """Encode message by converting all string values to uppercase.""" | ||
| # Assume message is a Message instance | ||
| data = message.data | ||
|
|
||
| # Convert string values to uppercase | ||
| encoded_data = {} | ||
| for key, value in data.items(): | ||
| if isinstance(value, str): | ||
| encoded_data[key] = value.upper() | ||
| else: | ||
| encoded_data[key] = value | ||
| return json.dumps(encoded_data) | ||
|
|
||
| def decode(self, encoded_data, message_type): | ||
| """Decode data (strings remain uppercase).""" | ||
| data = json.loads(encoded_data) | ||
| return message_type.parse(data) | ||
|
|
||
|
|
||
| custom_codec = UpperCaseCodec() | ||
| custom_transport = eve.InMemoryTransport(codec=custom_codec) | ||
|
|
||
| pub = eve.Publisher("/example/custom", transport=custom_transport) | ||
|
|
||
| # Create a custom subscriber that prints the message | ||
| class PrintSubscriber(eve.Subscriber): | ||
| def message_received(self, message): | ||
| print(f"Received: {message}") | ||
|
|
||
| sub = PrintSubscriber("/example/custom", transport=custom_transport) | ||
| sub.subscribe() | ||
|
|
||
| pub.publish(eve.Message(text="hello world", count=3)) | ||
| print() | ||
|
|
||
|
|
||
| # Example 4: Protocol Buffers codec (if available) | ||
| print("=" * 60) | ||
| print("Example 4: Protocol Buffers Codec (if available)") | ||
| print("=" * 60) | ||
|
|
||
| try: | ||
| from compas_eve.codecs import ProtobufMessageCodec | ||
|
|
||
| pb_codec = ProtobufMessageCodec() | ||
| pb_transport = eve.InMemoryTransport(codec=pb_codec) | ||
|
|
||
| pub = eve.Publisher("/example/protobuf", transport=pb_transport) | ||
| sub = eve.EchoSubscriber("/example/protobuf", transport=pb_transport) | ||
| sub.subscribe() | ||
|
|
||
| pub.publish(eve.Message(text="Hello with Protocol Buffers", count=4)) | ||
| print("β Protocol Buffers codec is working!") | ||
|
|
||
| except ImportError as e: | ||
| print(f"Protocol Buffers codec not available: {e}") | ||
| print("Install with: pip install compas_pb") | ||
|
|
||
| print() | ||
| print("=" * 60) | ||
| print("All examples completed!") | ||
| print("=" * 60) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,54 @@ | ||
| [build-system] | ||
| requires = ["setuptools>=66.0"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| # ============================================================================ | ||
| # project info | ||
| # ============================================================================ | ||
|
|
||
| [project] | ||
| name = "compas_eve" | ||
| description = "COMPAS Event Extensions: adds event-based communication infrastructure to the COMPAS framework." | ||
| keywords = ["events", "event-driven", "compas", "architecture", "distributed systems"] | ||
| authors = [ | ||
| { name = "Gonzalo Casas", email = "[email protected]" }, | ||
| { name = "Chen Kasirer", email = "[email protected]" }, | ||
| ] | ||
| license = { file = "LICENSE" } | ||
| readme = "README.md" | ||
| requires-python = ">=3.9" | ||
| dynamic = ['dependencies', 'optional-dependencies', 'version'] | ||
| classifiers = [ | ||
| "Development Status :: 4 - Beta", | ||
| "Topic :: Scientific/Engineering", | ||
| "Operating System :: Unix", | ||
| "Operating System :: POSIX", | ||
| "Operating System :: Microsoft :: Windows", | ||
| "Programming Language :: Python", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Programming Language :: Python :: 3.14", | ||
| ] | ||
|
|
||
| [project.entry-points.'compas_pb.plugins'] | ||
| serializers = 'compas_eve.codecs.conversions' | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/compas-dev/compas_eve" | ||
| Documentation = "https://compas.dev/compas_eve" | ||
| Repository = "https://github.com/compas-dev/compas_eve" | ||
| Changelog = "https://github.com/compas-dev/compas_eve/blob/main/CHANGELOG.md" | ||
| Issues = "https://github.com/compas-dev/compas_eve/issues" | ||
| Forum = "https://forum.compas-framework.org/" | ||
|
|
||
|
|
||
| # ============================================================================ | ||
| # setuptools config | ||
| # ============================================================================ | ||
|
|
||
| [tool.black] | ||
| line-length = 120 | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,12 @@ | ||
| attrs >=17.4 | ||
| autopep8 | ||
| black | ||
| bump2version >=1.0.1 | ||
| check-manifest >=0.36 | ||
| compas_invocations | ||
| doc8 | ||
| flake8 | ||
| black >=22.12.0 | ||
| build | ||
| bump-my-version | ||
| compas_invocations2 | ||
| compas_pb >= 0.4.4 | ||
| invoke >=0.14 | ||
| isort | ||
| pydocstyle | ||
| pytest >=3.2 | ||
| pytest-mock | ||
| ruff | ||
| sphinx_compas2_theme | ||
| twine | ||
| wheel | ||
| -e . | ||
| wheel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot don't import the
JsonMessageCodecto this level, leave it where it belongs, and just import it from.codecswhere used, otherwise it's a bit asymmetric/oddThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed JsonMessageCodec from top-level exports in commit [pending]. It now stays in the codecs submodule and should be imported as
from compas_eve.codecs import JsonMessageCodec. The import in core.py is now lazy to avoid unnecessary top-level dependencies.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed JsonMessageCodec from top-level exports in commit 490749a. It now stays in the codecs submodule and should be imported as
from compas_eve.codecs import JsonMessageCodec. The import in core.py is now lazy to avoid unnecessary top-level dependencies.