Skip to content

Commit

Permalink
pin fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Mar 4, 2024
1 parent f42ac6e commit 723a158
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hypha/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.15.46"
"version": "0.15.47"
}
4 changes: 2 additions & 2 deletions hypha/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ServiceInfo(BaseModel):
class Config:
"""Set the config for pydantic."""

extra='allow'
extra = "allow"

def is_singleton(self):
"""Check if the service is singleton."""
Expand Down Expand Up @@ -137,7 +137,7 @@ class RDF(BaseModel):
class Config:
"""Set the config for pydantic."""

extra='allow'
extra = "allow"


class ApplicationInfo(RDF):
Expand Down
23 changes: 17 additions & 6 deletions hypha/core/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ async def init(self, reset_redis, startup_functions=None):
await self.cleanup_disconnected_clients()
for service in self._public_services:
try:
await self._public_workspace_interface.register_service(service.model_dump())
await self._public_workspace_interface.register_service(
service.model_dump()
)
except Exception: # pylint: disable=broad-except
logger.exception("Failed to register public service: %s", service)
raise
Expand Down Expand Up @@ -187,7 +189,9 @@ async def add_disconnected_client(self, client_info: ClientInfo):
await self._redis.hset(
"clients:disconnected",
f"{client_info.workspace}/{client_info.id}",
json.dumps({"client": client_info.model_dump_json(), "timestamp": time.time()}),
json.dumps(
{"client": client_info.model_dump_json(), "timestamp": time.time()}
),
)

async def remove_disconnected_client(
Expand Down Expand Up @@ -239,14 +243,17 @@ async def get_user_workspace(self, user_id: str):
workspace_info = await self._redis.hget("workspaces", user_id)
if workspace_info is None:
return None
workspace_info = WorkspaceInfo.model_validate(json.loads(workspace_info.decode()))
workspace_info = WorkspaceInfo.model_validate(
json.loads(workspace_info.decode())
)
return workspace_info

async def get_all_users(self):
"""Get all users."""
users = await self._redis.hgetall("users")
return [
UserInfo.model_validate(json.loads(user.decode())) for user in users.values()
UserInfo.model_validate(json.loads(user.decode()))
for user in users.values()
]

async def get_all_workspace(self):
Expand Down Expand Up @@ -278,14 +285,18 @@ async def register_workspace(self, workspace: dict, overwrite=False):
raise KeyError(
f"Client does not exist: {workspace.name}/{client_id}"
)
client_info = ClientInfo.model_validate(json.loads(client_info.decode()))
client_info = ClientInfo.model_validate(
json.loads(client_info.decode())
)
await self._redis.srem(
f"user:{client_info.user_info.id}:clients", client_info.id
)
# assert ret >= 1, f"Client not found in user({client_info.user_info.id})'s clients list: {client_info.id}"
await self._redis.hdel(f"{workspace.name}:clients", client_id)
await self._redis.delete(f"{workspace}:clients")
await self._redis.hset("workspaces", workspace.name, workspace.model_dump_json())
await self._redis.hset(
"workspaces", workspace.name, workspace.model_dump_json()
)
await self.get_workspace_manager(workspace.name, setup=True)

self._event_bus.emit("workspace_registered", workspace.model_dump())
Expand Down
15 changes: 11 additions & 4 deletions hypha/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ async def create_workspace(

if not overwrite and await self._redis.hexists("workspaces", workspace.name):
raise Exception(f"Workspace {workspace.name} already exists.")
await self._redis.hset("workspaces", workspace.name, workspace.model_dump_json())
await self._redis.hset(
"workspaces", workspace.name, workspace.model_dump_json()
)
# Clear the workspace
await self.remove_clients(workspace.name)
workspace_info = await self.get_workspace_info(workspace.name)
Expand Down Expand Up @@ -630,7 +632,9 @@ async def get_workspace_info(self, workspace: str = None) -> WorkspaceInfo:
workspace_info = await self._redis.hget("workspaces", workspace)
if workspace_info is None:
raise KeyError(f"Workspace not found: {workspace}")
workspace_info = WorkspaceInfo.model_validate(json.loads(workspace_info.decode()))
workspace_info = WorkspaceInfo.model_validate(
json.loads(workspace_info.decode())
)
return workspace_info

async def _get_workspace_info_dict(
Expand Down Expand Up @@ -819,7 +823,8 @@ async def _get_all_workspace(self):
"""Get all workspaces."""
workspaces = await self._redis.hgetall("workspaces")
return [
WorkspaceInfo.model_validate(json.loads(v.decode())) for v in workspaces.values()
WorkspaceInfo.model_validate(json.loads(v.decode()))
for v in workspaces.values()
]

async def check_permission(
Expand Down Expand Up @@ -938,7 +943,9 @@ async def _update_workspace(self, config: dict, context=None):
if _id not in workspace.owners:
workspace.owners.append(_id)
workspace.owners = [o.strip() for o in workspace.owners if o.strip()]
await self._redis.hset("workspaces", workspace.name, workspace.model_dump_json())
await self._redis.hset(
"workspaces", workspace.name, workspace.model_dump_json()
)
self._event_bus.emit("workspace_changed", workspace.model_dump())

async def delete_if_empty(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
aioboto3==11.2.0
aiofiles==23.2.1
base58==2.1.1
fastapi==0.104.1
fastapi==0.106.0
imjoy-rpc==0.5.44
jinja2==3.1.2
lxml==4.9.3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

REQUIREMENTS = [
"aiofiles",
"fastapi>=0.70.0",
"fastapi>=0.70.0,<=0.106.0",
"imjoy-rpc>=0.5.44",
"msgpack>=1.0.2",
"numpy",
Expand Down

0 comments on commit 723a158

Please sign in to comment.