Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
Fix extension api
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed May 24, 2021
1 parent 23a4625 commit c75d63d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion imjoy/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.11.12"
"version": "0.11.13"
}
43 changes: 38 additions & 5 deletions imjoy/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import sys
from functools import partial
from typing import Optional
import uuid

import pkg_resources

from imjoy.core import (
UserInfo,
VisibilityEnum,
TokenConfig,
WorkspaceInfo,
all_workspaces,
Expand All @@ -15,7 +18,9 @@
current_workspace,
)
from imjoy.core.auth import check_permission, generate_presigned_token
from imjoy.core.plugin import DynamicPlugin
from imjoy.utils import dotdict
from imjoy.core.connection import BasicConnection

logging.basicConfig(stream=sys.stdout)
logger = logging.getLogger("imjoy-core")
Expand Down Expand Up @@ -56,16 +61,44 @@ def __init__(self, imjoy_api=None):
for entry_point in pkg_resources.iter_entry_points(
"imjoy_core_server_extension"
):
setup_extension = entry_point.load()
setup_extension(self.imjoy_api)
user_info = UserInfo(
id=entry_point.name,
email=None,
parent=None,
roles=[],
scopes=[],
expires_at=None,
)
workspace = WorkspaceInfo(
name=str(uuid.uuid4()) + entry_point.name,
owners=[user_info.id],
visibility=VisibilityEnum.protected,
persistent=False,
)
connection = BasicConnection(lambda x: x)
plugin = DynamicPlugin(
{"workspace": workspace.name, "name": entry_point.name},
self.get_interface(),
connection,
workspace,
)
current_user.set(user_info)
current_workspace.set(workspace)
current_plugin.set(plugin)
try:
setup_extension = entry_point.load()
setup_extension(self.imjoy_api)
except Exception:
logger.exception("Failed to setup extension: %s", entry_point.name)
raise

def register_service(self, service: dict):
"""Register a service."""
plugin = current_plugin.get()
workspace = current_workspace.get()
service.provider = plugin.name
service.providerId = plugin.id
service._rintf = True
service["provider"] = plugin.name
service["providerId"] = plugin.id
service["_rintf"] = True
workspace._services.append(service)

def get_plugin(self, name):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_imjoy_engine_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def socketio_server_fixture():
break
except RequestException:
pass
timeout -= 0.1
time.sleep(0.1)
timeout -= 1
time.sleep(1)
yield

proc.terminate()
Expand Down

0 comments on commit c75d63d

Please # to comment.