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

Commit

Permalink
Support core server extension (#162)
Browse files Browse the repository at this point in the history
* support core server extension

* remove print
  • Loading branch information
oeway authored May 23, 2021
1 parent 0e09b78 commit 2acb0e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 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.11"
"version": "0.11.12"
}
52 changes: 33 additions & 19 deletions imjoy/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from functools import partial
from typing import Optional

import pkg_resources

from imjoy.core import (
TokenConfig,
WorkspaceInfo,
Expand All @@ -13,6 +15,7 @@
current_workspace,
)
from imjoy.core.auth import check_permission, generate_presigned_token
from imjoy.utils import dotdict

logging.basicConfig(stream=sys.stdout)
logger = logging.getLogger("imjoy-core")
Expand All @@ -26,7 +29,35 @@ class CoreInterface:

def __init__(self, imjoy_api=None):
"""Set up instance."""
self.imjoy_api = imjoy_api
imjoy_api = imjoy_api or {}
self.imjoy_api = dotdict(
{
"_rintf": True,
"log": self.log,
"error": self.error,
"registerService": self.register_service,
"register_service": self.register_service,
"getServices": self.get_services,
"get_services": self.get_services,
"utils": {},
"getPlugin": self.get_plugin,
"get_plugin": self.get_plugin,
"generateToken": self.generate_token,
"generate_token": self.generate_token,
"create_workspace": self.create_workspace,
"createWorkspace": self.create_workspace,
"get_workspace": self.get_workspace,
"getWorkspace": self.get_workspace,
}
)
self.imjoy_api.update(imjoy_api)

# run server extensions
for entry_point in pkg_resources.iter_entry_points(
"imjoy_core_server_extension"
):
setup_extension = entry_point.load()
setup_extension(self.imjoy_api)

def register_service(self, service: dict):
"""Register a service."""
Expand Down Expand Up @@ -162,21 +193,4 @@ def wrap_func(func, *args, **kwargs):

def get_interface(self):
"""Return the interface."""
return {
"_rintf": True,
"log": self.log,
"error": self.error,
"registerService": self.register_service,
"register_service": self.register_service,
"getServices": self.get_services,
"get_services": self.get_services,
"utils": {},
"getPlugin": self.get_plugin,
"get_plugin": self.get_plugin,
"generateToken": self.generate_token,
"generate_token": self.generate_token,
"create_workspace": self.create_workspace,
"createWorkspace": self.create_workspace,
"get_workspace": self.get_workspace,
"getWorkspace": self.get_workspace,
}
return self.imjoy_api.copy()

0 comments on commit 2acb0e1

Please sign in to comment.