Skip to content

Commit

Permalink
chore: updates per review
Browse files Browse the repository at this point in the history
- Renaming ui_utils.py to core_ui.py
- Minor style fixes and unused imports removal
  • Loading branch information
mmikita95 committed Mar 6, 2024
1 parent 762b144 commit 35c3347
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/streamsync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json
import math
from streamsync.ss_types import Readable, InstancePath, StreamsyncEvent, StreamsyncEventResult, StreamsyncFileItem
from streamsync.ui_utils import ComponentTree, SessionComponentTree
from streamsync.core_ui import ComponentTree, SessionComponentTree


class Config:
Expand Down
8 changes: 4 additions & 4 deletions src/streamsync/ui_utils.py → src/streamsync/core_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from pydantic import BaseModel, Field

current_parent_container: ContextVar[Union['Component', None]] = \
ContextVar('current_parent_container')
current_parent_container: ContextVar[Union["Component", None]] = \
ContextVar("current_parent_container")
# This variable is thread safe and context safe


Expand All @@ -30,7 +30,7 @@ def to_dict(self) -> Dict:
"""
return self.model_dump(exclude_none=True)

def __enter__(self) -> 'Component':
def __enter__(self) -> "Component":
self._token = current_parent_container.set(self)
return self

Expand Down Expand Up @@ -70,7 +70,7 @@ def get_descendents(self, parent_id: str) -> List[Component]:
def attach(self, component: Component, override=False) -> None:
self.counter += 1
if (component.id in self.components) and (override is False):
raise RuntimeWarning(f'Component with ID {component.id} already exists')
raise RuntimeWarning(f"Component with ID {component.id} already exists")
self.components[component.id] = component

def ingest(self, serialised_components: Dict[str, Any]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/streamsync/ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from streamsync.ui_manager import StreamsyncUI
from streamsync.ui_utils import Component
from streamsync.core_ui import Component


class StreamsyncUIManager(StreamsyncUI):
Expand Down
18 changes: 9 additions & 9 deletions src/streamsync/ui_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Union

from streamsync.core import StreamsyncSession, session_manager
from streamsync.ui_utils import (Component, SessionComponentTree, UIError,
current_parent_container)
from streamsync.core_ui import (Component, SessionComponentTree, UIError,
current_parent_container)


class StreamsyncUI:
Expand All @@ -16,11 +16,11 @@ class StreamsyncUI:
def __init__(self, session_id: str):
self.session: Union[StreamsyncSession, None] = session_manager.get_session(session_id)
if self.session is None:
raise RuntimeError('Invalid session passed to the UI manager')
raise RuntimeError("Invalid session passed to the UI manager")
# Initialize the component tree with the session
self.component_tree: SessionComponentTree = \
self.session.session_component_tree
self.root_component = self.component_tree.get_component('root')
self.root_component = self.component_tree.get_component("root")
if not self.root_component:
raise RuntimeError(f"Failed to acquire root component in session {session_id}")

Expand All @@ -43,17 +43,17 @@ def find(self, component_id: str) \
# Example context manager for finding components
component = self.component_tree.get_component(component_id)
if component is None:
raise RuntimeError(f'Component {component_id} not found')
raise RuntimeError(f"Component {component_id} not found")
return component

def _create_component(self, component_type: str, **kwargs) -> Component:
parent_container = current_parent_container.get(None)
if 'parentId' in kwargs:
parent_id = kwargs.pop('parentId')
if "parentId" in kwargs:
parent_id = kwargs.pop("parentId")
else:
parent_id = 'root' if not parent_container else parent_container.id
parent_id = "root" if not parent_container else parent_container.id
component = Component(
type=component_type, parentId=parent_id, flag='cmc', **kwargs
type=component_type, parentId=parent_id, flag="cmc", **kwargs
)
self.component_tree.attach(component, attach_to_bottom=True)
return component
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict

import numpy as np
from streamsync.core import (BytesWrapper, ComponentTree, Evaluator, EventDeserialiser,
from streamsync.core import (BytesWrapper, Evaluator, EventDeserialiser,
FileWrapper, SessionManager, StateProxy, StateSerialiser, StateSerialiserException, StreamsyncState)
import streamsync as ss
from streamsync.ss_types import StreamsyncEvent
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from streamsync.ui_utils import ComponentTree, UIError
from streamsync.core_ui import ComponentTree, UIError
from streamsync.ui import StreamsyncUIManager
import streamsync as ss

Expand Down

0 comments on commit 35c3347

Please sign in to comment.