From 662ae900b119dea4361cc445ceff8477b2207ef9 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sat, 22 Jun 2024 10:28:17 +0200 Subject: [PATCH 1/5] Get local workspace from connection --- javascript/package-lock.json | 2 +- javascript/package.json | 2 +- javascript/src/hypha/rpc.js | 7 +++++++ python/imjoy_rpc/VERSION | 2 +- python/imjoy_rpc/hypha/rpc.py | 6 ++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/javascript/package-lock.json b/javascript/package-lock.json index fde62d9e..9e313873 100644 --- a/javascript/package-lock.json +++ b/javascript/package-lock.json @@ -1,6 +1,6 @@ { "name": "imjoy-rpc", - "version": "0.5.48post1", + "version": "0.5.49", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/javascript/package.json b/javascript/package.json index fce0b53f..fa2b30f2 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -1,6 +1,6 @@ { "name": "imjoy-rpc", - "version": "0.5.48post1", + "version": "0.5.49", "description": "Remote procedure calls for ImJoy.", "module": "index.js", "types": "index.d.ts", diff --git a/javascript/src/hypha/rpc.js b/javascript/src/hypha/rpc.js index 44006a9d..7e154b33 100644 --- a/javascript/src/hypha/rpc.js +++ b/javascript/src/hypha/rpc.js @@ -222,6 +222,13 @@ export class RPC extends MessageEmitter { await this.get_manager_service(30.0); assert(this._manager_service); this._connection_info = await this._manager_service.get_connection_info(); + if ( + !this._local_workspace && + this._connection_info && + this._connection_info.workspace + ) { + this._local_workspace = this._connection_info.workspace; + } if ( this._connection_info.reconnection_token && this._connection.set_reconnection_token diff --git a/python/imjoy_rpc/VERSION b/python/imjoy_rpc/VERSION index 1fb61986..d3e34105 100644 --- a/python/imjoy_rpc/VERSION +++ b/python/imjoy_rpc/VERSION @@ -1,3 +1,3 @@ { - "version": "0.5.48.post2" + "version": "0.5.49" } diff --git a/python/imjoy_rpc/hypha/rpc.py b/python/imjoy_rpc/hypha/rpc.py index 76f2635d..5edb39ae 100644 --- a/python/imjoy_rpc/hypha/rpc.py +++ b/python/imjoy_rpc/hypha/rpc.py @@ -220,6 +220,12 @@ async def _get_connection_info(self): self._connection_info = ( await self._manager_service.get_connection_info() ) + if ( + not self._local_workspace + and self._connection_info + and self._connection_info.get("workspace") + ): + self._local_workspace = self._connection_info["workspace"] if "reconnection_token" in self._connection_info and hasattr( self._connection, "set_reconnection_token" ): From b8bb456a319d2e1bafeb94fd65b159272848f08c Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sat, 22 Jun 2024 17:33:00 +0200 Subject: [PATCH 2/5] Disable sse client test --- javascript/tests/{sse_client_test.js => test_sse_client.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename javascript/tests/{sse_client_test.js => test_sse_client.js} (100%) diff --git a/javascript/tests/sse_client_test.js b/javascript/tests/test_sse_client.js similarity index 100% rename from javascript/tests/sse_client_test.js rename to javascript/tests/test_sse_client.js From ecb5cab840d9eb960cf43aecd346e8070fed2ead Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sat, 22 Jun 2024 17:54:30 +0200 Subject: [PATCH 3/5] Support _rintf to keep interface object --- javascript/package-lock.json | 2 +- javascript/package.json | 2 +- javascript/src/hypha/rpc.js | 12 +++++++++++- python/imjoy_rpc/VERSION | 2 +- python/imjoy_rpc/hypha/rpc.py | 9 ++++++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/javascript/package-lock.json b/javascript/package-lock.json index 9e313873..96c53a50 100644 --- a/javascript/package-lock.json +++ b/javascript/package-lock.json @@ -1,6 +1,6 @@ { "name": "imjoy-rpc", - "version": "0.5.49", + "version": "0.5.50", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/javascript/package.json b/javascript/package.json index fa2b30f2..a48957e5 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -1,6 +1,6 @@ { "name": "imjoy-rpc", - "version": "0.5.49", + "version": "0.5.50", "description": "Remote procedure calls for ImJoy.", "module": "index.js", "types": "index.d.ts", diff --git a/javascript/src/hypha/rpc.js b/javascript/src/hypha/rpc.js index 7e154b33..e77f904a 100644 --- a/javascript/src/hypha/rpc.js +++ b/javascript/src/hypha/rpc.js @@ -834,11 +834,21 @@ export class RPC extends MessageEmitter { [`Method call time out: ${method_name}`], method_name ); + // By default, hypha will clear the session after the method is called + // However, if the args contains _rintf === true, we will not clear the session + let clear_after_called = true; + for (let arg of args) { + if (typeof arg === "object" && arg._rintf === true) { + debugger; + clear_after_called = false; + break; + } + } extra_data["promise"] = await self._encode_promise( resolve, reject, local_session_id, - true, + clear_after_called, timer, local_workspace ); diff --git a/python/imjoy_rpc/VERSION b/python/imjoy_rpc/VERSION index d3e34105..91c6f08c 100644 --- a/python/imjoy_rpc/VERSION +++ b/python/imjoy_rpc/VERSION @@ -1,3 +1,3 @@ { - "version": "0.5.49" + "version": "0.5.50" } diff --git a/python/imjoy_rpc/hypha/rpc.py b/python/imjoy_rpc/hypha/rpc.py index 5edb39ae..276c5df1 100644 --- a/python/imjoy_rpc/hypha/rpc.py +++ b/python/imjoy_rpc/hypha/rpc.py @@ -785,11 +785,18 @@ def pfunc(resolve, reject): f"Method call time out: {method_name}", label=method_name, ) + # By default, hypha will clear the session after the method is called + # However, if the args contains _rintf === true, we will not clear the session + clear_after_called = True + for arg in args: + if (isinstance(arg, dict) and arg.get("_rintf")) or (hasattr(arg, "_rintf") and arg._rintf == True): + clear_after_called = False + break extra_data["promise"] = self._encode_promise( resolve=resolve, reject=reject, session_id=local_session_id, - clear_after_called=True, + clear_after_called=clear_after_called, timer=timer, local_workspace=local_workspace, ) From 0dc5f4cf8a2ea788b495290c1b9a391d29ff4353 Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sat, 22 Jun 2024 18:00:03 +0200 Subject: [PATCH 4/5] Update readme --- imjoy-rpc-v2.md | 1 + 1 file changed, 1 insertion(+) diff --git a/imjoy-rpc-v2.md b/imjoy-rpc-v2.md index bd6b3247..b3ede4ed 100644 --- a/imjoy-rpc-v2.md +++ b/imjoy-rpc-v2.md @@ -47,6 +47,7 @@ The data representation is a JSON object (but can contain binary data, e.g. `Arr Notes: - `_encode(...)` in the imjoy-rpc representation means the type will be recursively encoded (decoded). + - When sending functions to be used remotely in a remote function call (e.g. passing an object with member functions when calling a remote function), the functions will only be available during the call and will be removed after the call. If you want to keep the function available for later calls, you can either mark the function as a "interface" function by setting any of the containing objects' `_rintf` to true, or you can register the function as a service, then call the service instead. - For n-D numpy array, there is no established n-D array library in javascript, the current behavior is, if there is `tf`(Tensorflow.js) detected, then it will be decoded into `tf.Tensor`. If `nj`(numjs) is detected, then it will be decoded into `nj.array`. - Typed array will be represented as numpy array if available, otherwise it will be converted to raw bytes. Type Conversion From 67eb2ba69b17cd1047cc1f8b7dfd64b6c376302f Mon Sep 17 00:00:00 2001 From: Wei Ouyang Date: Sat, 22 Jun 2024 18:07:37 +0200 Subject: [PATCH 5/5] Add publish action --- .github/workflows/publish.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..92cda203 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Publish to PyPI + +on: + workflow_dispatch: + inputs: + + +jobs: + publish: + runs-on: ubuntu-latest + defaults: + run: + working-directory: python + steps: + - name: Check out code + uses: actions/checkout@v2 + + # Add steps for any necessary setup, like installing dependencies + - name: Build + run: | + python -m pip install --upgrade pip + python -m pip install -U twine + python -m pip install -U wheel + python3 -m pip install build==1.0.3 # pin build + rm -rf ./build + rm -rf ./dist/* + python setup.py sdist bdist_wheel + + - name: Publish package on PyPI + uses: pypa/gh-action-pypi-publish@v1.6.4 + with: + user: __token__ + password: "${{ secrets.PYPI_TOKEN }}" + packages_dir: ./dist/ \ No newline at end of file