66from collections .abc import Callable , Coroutine , Sequence
77from functools import partial
88from pathlib import Path
9- from typing import Annotated , Any , Optional , TypeAlias , get_type_hints
9+ from typing import Annotated , Any , Optional , get_type_hints
1010
1111import typer
1212from IPython .terminal .embed import InteractiveShellEmbed
13- from pydantic import BaseModel , create_model
13+ from pydantic import BaseModel , ValidationError , create_model
1414from ruamel .yaml import YAML
1515
1616from fastcs import __version__
2626)
2727from fastcs .logging import logger as _fastcs_logger
2828from fastcs .tracer import Tracer
29- from fastcs .transport .epics .ca .transport import EpicsCATransport
30- from fastcs .transport .epics .pva .transport import EpicsPVATransport
31- from fastcs .transport .graphql .transport import GraphQLTransport
32- from fastcs .transport .rest .transport import RestTransport
33- from fastcs .transport .tango .transport import TangoTransport
3429
3530from .attributes import ONCE , AttrR , AttrW
3631from .controller import BaseController , Controller
4136from .transport import Transport
4237from .util import validate_hinted_attributes
4338
44- # Define a type alias for transport options
45- TransportList : TypeAlias = list [
46- EpicsPVATransport
47- | EpicsCATransport
48- | TangoTransport
49- | RestTransport
50- | GraphQLTransport
51- ]
52-
5339tracer = Tracer (name = __name__ )
5440logger = _fastcs_logger .bind (logger_name = __name__ )
5541
@@ -440,8 +426,19 @@ def run(
440426
441427 yaml = YAML (typ = "safe" )
442428 options_yaml = yaml .load (config )
443- # To do: Handle a k8s "values.yaml" file
444- instance_options = fastcs_options .model_validate (options_yaml )
429+
430+ try :
431+ instance_options = fastcs_options .model_validate (options_yaml )
432+ except ValidationError as e :
433+ if any ("transport" in error ["loc" ] for error in json .loads (e .json ())):
434+ raise LaunchError (
435+ "Failed to validate transports. "
436+ "Are the correct fastcs extras installed? "
437+ f"Available transports:\n { Transport .subclasses } " ,
438+ ) from e
439+
440+ raise LaunchError ("Failed to validate config" ) from e
441+
445442 if hasattr (instance_options , "controller" ):
446443 controller = controller_class (instance_options .controller )
447444 else :
@@ -466,7 +463,7 @@ def _extract_options_model(controller_class: type[Controller]) -> type[BaseModel
466463 if len (args ) == 1 :
467464 fastcs_options = create_model (
468465 f"{ controller_class .__name__ } " ,
469- transport = (TransportList , ...),
466+ transport = (list [ Transport . union ()] , ...),
470467 __config__ = {"extra" : "forbid" },
471468 )
472469 elif len (args ) == 2 :
@@ -483,7 +480,7 @@ def _extract_options_model(controller_class: type[Controller]) -> type[BaseModel
483480 fastcs_options = create_model (
484481 f"{ controller_class .__name__ } " ,
485482 controller = (options_type , ...),
486- transport = (TransportList , ...),
483+ transport = (list [ Transport . union ()] , ...),
487484 __config__ = {"extra" : "forbid" },
488485 )
489486 else :
0 commit comments