-
Notifications
You must be signed in to change notification settings - Fork 0
Support Logging, improve interface #3
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0ad4994
Fix integration test
mesudip cf54656
Refactor rpc logging protocol
mesudip ad48345
Refacotr rpcloggin/context, improve context handling
mesudip 69fe514
Support await,timeout on RpcCallHandle
mesudip 3c80742
Make calls context aware, update Readme
mesudip e37bb79
Address pr comments,fix tests
mesudip 3bab9f9
Prepare release scripts
mesudip 437aead
Fix issues in rpc system tests
mesudip 58b9a46
Fix ssh pipe tests
mesudip 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ venv | |
| .pytest_cache | ||
| __pycache__/ | ||
| .vscode | ||
| examples | ||
| examples | ||
| /dist | ||
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,52 @@ | ||
| name: Publish to PyPI | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
|
|
||
| jobs: | ||
| build-and-publish: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.x' | ||
|
|
||
| - name: Install build dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build twine | ||
|
|
||
| - name: Extract version from tag | ||
| run: | | ||
| # Strip 'refs/tags/v' from the ref | ||
| VERSION=${GITHUB_REF#refs/tags/v} | ||
| echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
| echo "Releasing version: $VERSION" | ||
|
|
||
| - name: Update version in pyproject.toml | ||
| run: | | ||
| # Update version = "x.x.x" in pyproject.toml | ||
| # We use a temp file to ensure compatibility with different sed versions if run locally, | ||
| # effectively overwriting the original. | ||
| sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml | ||
|
|
||
| # Verify replacement | ||
| grep "version =" pyproject.toml | ||
|
|
||
| - name: Build package | ||
| run: python -m build | ||
|
|
||
| - name: Publish to PyPI | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
| run: twine upload dist/* |
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 |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ __pycache__/ | |
| .pytest_cache/ | ||
| cbor_rpc.egg-info/ | ||
| .coverage | ||
| /dist | ||
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,74 @@ | ||
| # CBOR-RPC Project Documentation for LLMs | ||
|
|
||
| ## Architecture Overview | ||
| The stack consists of: Transport (Pipe) -> Serialization (Transformer) -> Protocol (RPC). | ||
|
|
||
| **IMPORTANT**: All public components MUST be imported directly from `cbor_rpc`. DO NOT import from submodules (e.g., use `from cbor_rpc import TcpPipe`, NOT `from cbor_rpc.tcp.tcp import TcpPipe`). | ||
|
|
||
| ## 1. Pipes (Transport) | ||
| All pipes implement `Pipe` (async base) or `EventPipe` (event-based). | ||
| Common methods: `write(chunk)`, `read(timeout)`, `terminate()`. | ||
|
|
||
| - **TcpPipe**: `await TcpPipe.create_connection(host, port)` (Client) or `await TcpPipe.create_server(host, port)` (Server). | ||
| - **StdioPipe**: `await StdioPipe.open()` (Use stdin/stdout to communicate) or `await StdioPipe.start_process(*args)` (Subprocess). | ||
| - **SshPipe**: Works over `asyncssh` channels. | ||
| - **EventPipe**: High-level wrapper emitting "data", "close", "error" events. | ||
|
|
||
| ## 2. Transformers (Serialization) | ||
| Used to convert raw bytes from pipes into Python objects. | ||
| - **Implementations**: `CborStreamTransformer` (default), `JsonStreamTransformer`. | ||
| - **Usage**: `transformed_pipe = transformer.apply_transformer(raw_pipe)`. | ||
| - **Note**: Always use `*StreamTransformer` for TCP/Stdio to handle packet fragmentation. | ||
|
|
||
| ## 3. RPC Layer | ||
| Provides high-level method calling over pipes. | ||
|
|
||
| - **`call_method(name, *args)`**: Async call. Wait for return value. Throws on timeout or remote error. | ||
| - **`fire_method(name, *args)`**: Async "fire and forget". No return value, no waiting. | ||
| - **`wait_next_event(topic)`**: Wait for a specific pulse/event from the other side. | ||
| - **`set_timeout(ms)`**: Set default timeout for all calls (default 30000ms). | ||
|
|
||
| ### Client Construction | ||
| - **`RpcV1.read_only_client(pipe)`**: Use when you only need to call methods on the remote side. | ||
| ```python | ||
| from cbor_rpc import TcpPipe, CborStreamTransformer, RpcV1 | ||
|
|
||
| pipe = await TcpPipe.create_connection("localhost", 8080) | ||
| t_pipe = CborStreamTransformer().apply_transformer(pipe) | ||
| rpc = RpcV1.read_only_client(t_pipe) | ||
| result = await rpc.call_method("method_name", arg1, arg2) | ||
| ``` | ||
|
|
||
| ### Server Usage | ||
| To run a server, subclass `RpcV1Server` for logic and `TcpServer` (or other) for transport. Override `accept` to apply the transformer and register the connection. | ||
|
|
||
| ```python | ||
| from cbor_rpc import RpcV1Server, TcpServer, CborStreamTransformer | ||
|
|
||
| # 1. Implementation | ||
| class MyRpcApp(RpcV1Server): | ||
| async def handle_method_call(self, conn_id, context, method, args): | ||
| if method == "ping": return "pong" | ||
|
|
||
| # 2. Setup transport | ||
| class MyServer(TcpServer): | ||
| def set_app(self, app): self.app = app | ||
|
|
||
| async def accept(self, pipe): | ||
| # Apply transformer to the raw connection pipe | ||
| rpc_pipe = CborStreamTransformer().apply_transformer(pipe) | ||
| # Register with the RPC app | ||
| await self.app.add_connection(f"{pipe.get_peer_info()}", rpc_pipe) | ||
| return True | ||
|
|
||
| # 3. Execution | ||
| app = MyRpcApp() | ||
| server = await MyServer.create(port=8080) | ||
| server.set_app(app) | ||
| ``` | ||
|
|
||
| ## Tips | ||
| - **Timeouts**: Default 30s. Set via `rpc.set_timeout(ms)`. | ||
| - **Context**: `RpcCallContext` in handlers provides metadata/logging. | ||
| - **Logging**: Controlled via `cbor_rpc.RpcLogger`. | ||
| m | ||
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.
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.
There seems to be a stray 'm' character at the end of the file. Please remove it.