Skip to content
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

Get local workspace from connection #559

Merged
merged 6 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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/
1 change: 1 addition & 0 deletions imjoy-rpc-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imjoy-rpc",
"version": "0.5.48post1",
"version": "0.5.50",
"description": "Remote procedure calls for ImJoy.",
"module": "index.js",
"types": "index.d.ts",
Expand Down
19 changes: 18 additions & 1 deletion javascript/src/hypha/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -827,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
);
Expand Down
2 changes: 1 addition & 1 deletion python/imjoy_rpc/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.5.48.post2"
"version": "0.5.50"
}
15 changes: 14 additions & 1 deletion python/imjoy_rpc/hypha/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
):
Expand Down Expand Up @@ -779,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,
)
Expand Down
Loading