-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathdefault.py
54 lines (39 loc) · 1.58 KB
/
default.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import annotations
import asyncio
from typing import Any
from idom.types import RootComponentConstructor
from .types import BackendImplementation
from .utils import all_implementations
def configure(
app: Any, component: RootComponentConstructor, options: None = None
) -> None:
"""Configure the given app instance to display the given component"""
if options is not None: # pragma: no cover
raise ValueError("Default implementation cannot be configured with options")
return _default_implementation().configure(app, component)
def create_development_app() -> Any:
"""Create an application instance for development purposes"""
return _default_implementation().create_development_app()
async def serve_development_app(
app: Any,
host: str,
port: int,
started: asyncio.Event | None = None,
) -> None:
"""Run an application using a development server"""
return await _default_implementation().serve_development_app(
app, host, port, started
)
_DEFAULT_IMPLEMENTATION: BackendImplementation[Any] | None = None
def _default_implementation() -> BackendImplementation[Any]:
"""Get the first available server implementation"""
global _DEFAULT_IMPLEMENTATION
if _DEFAULT_IMPLEMENTATION is not None:
return _DEFAULT_IMPLEMENTATION
try:
implementation = next(all_implementations())
except StopIteration: # pragma: no cover
raise RuntimeError("No built-in server implementation installed.")
else:
_DEFAULT_IMPLEMENTATION = implementation
return implementation