Skip to content

Commit

Permalink
do not call find_builtin_server_type at import time
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Jun 13, 2021
1 parent 8f81ce4 commit e29745e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/idom/client/app/package-lock.json

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

12 changes: 5 additions & 7 deletions src/idom/server/prefab.py
Expand Up @@ -13,8 +13,6 @@
from .utils import find_available_port, find_builtin_server_type


DEFAULT_SERVER_FACTORY = find_builtin_server_type("PerClientStateServer")

logger = logging.getLogger(__name__)

_App = TypeVar("_App")
Expand All @@ -23,7 +21,7 @@

def run(
component: ComponentConstructor,
server_type: ServerFactory[_App, _Config] = DEFAULT_SERVER_FACTORY,
server_type: Optional[ServerFactory[_App, _Config]] = None,
host: str = "127.0.0.1",
port: Optional[int] = None,
server_config: Optional[Any] = None,
Expand Down Expand Up @@ -57,8 +55,8 @@ def run(
The server instance. This isn't really useful unless the server is spawned
as a daemon. Otherwise this function blocks until the server has stopped.
"""
if server_type is None: # pragma: no cover
raise ValueError("No default server available.")
if server_type is None:
server_type = find_builtin_server_type("PerClientStateServer")
if port is None: # pragma: no cover
port = find_available_port(host)

Expand All @@ -73,7 +71,7 @@ def run(


def multiview_server(
server_type: ServerFactory[_App, _Config] = DEFAULT_SERVER_FACTORY,
server_type: Optional[ServerFactory[_App, _Config]] = None,
host: str = "127.0.0.1",
port: Optional[int] = None,
server_config: Optional[_Config] = None,
Expand Down Expand Up @@ -115,7 +113,7 @@ def multiview_server(


def hotswap_server(
server_type: ServerFactory[_App, _Config] = DEFAULT_SERVER_FACTORY,
server_type: Optional[ServerFactory[_App, _Config]] = None,
host: str = "127.0.0.1",
port: Optional[int] = None,
server_config: Optional[_Config] = None,
Expand Down
6 changes: 5 additions & 1 deletion src/idom/server/utils.py
Expand Up @@ -58,7 +58,11 @@ def poll(


def find_builtin_server_type(type_name: str) -> ServerFactory[Any, Any]:
"""Find first installed server implementation"""
"""Find first installed server implementation
Raises:
:class:`RuntimeError` if one cannot be found
"""
installed_builtins: List[str] = []
for name in _SUPPORTED_PACKAGES:
try:
Expand Down
4 changes: 2 additions & 2 deletions src/idom/testing.py
Expand Up @@ -28,7 +28,7 @@
from idom.core.events import EventHandler
from idom.core.hooks import LifeCycleHook, current_hook
from idom.core.utils import hex_id
from idom.server.prefab import DEFAULT_SERVER_FACTORY, hotswap_server
from idom.server.prefab import hotswap_server
from idom.server.proto import Server, ServerFactory
from idom.server.utils import find_available_port

Expand Down Expand Up @@ -73,7 +73,7 @@ class ServerMountPoint(Generic[_Mount, _Server]):

def __init__(
self,
server_type: ServerFactory[_App, _Config] = DEFAULT_SERVER_FACTORY,
server_type: Optional[ServerFactory[_App, _Config]] = None,
host: str = "127.0.0.1",
port: Optional[int] = None,
server_config: Optional[_Config] = None,
Expand Down

0 comments on commit e29745e

Please sign in to comment.