From 66679e6934f4848d4ef26ecf97b2e34fc4be4adb Mon Sep 17 00:00:00 2001 From: svoboda Date: Thu, 5 Feb 2026 11:56:58 +0100 Subject: [PATCH] Fix crash caused by unreachable SAL server by adding more SAL options --- cherab/jet/__init__.py | 2 +- cherab/jet/equilibrium/equilibrium.py | 3 ++- cherab/jet/sal.py | 24 ++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cherab/jet/__init__.py b/cherab/jet/__init__.py index 5ea73d0..6092933 100644 --- a/cherab/jet/__init__.py +++ b/cherab/jet/__init__.py @@ -15,4 +15,4 @@ # under the Licence. from .equilibrium import * -from .sal import sal +from .sal import JETSALClient, get_jet_sal diff --git a/cherab/jet/equilibrium/equilibrium.py b/cherab/jet/equilibrium/equilibrium.py index f220a9e..9fe4f95 100644 --- a/cherab/jet/equilibrium/equilibrium.py +++ b/cherab/jet/equilibrium/equilibrium.py @@ -24,7 +24,7 @@ from raysect.core import Point2D from cherab.tools.equilibrium import EFITEquilibrium -from cherab.jet.sal import sal +from cherab.jet.sal import JETSALClient from sal.core.exception import NodeNotFound @@ -46,6 +46,7 @@ def __init__(self, pulse, user=None, dda=None, sequence=None): DDA_PATH = '/pulse/{}/ppf/signal/{}/{}:{}' DATA_PATH = '/pulse/{}/ppf/signal/{}/{}/{}:{}' + sal = JETSALClient() # defaults user = user or 'jetppf' diff --git a/cherab/jet/sal.py b/cherab/jet/sal.py index bfb5784..45d53e3 100644 --- a/cherab/jet/sal.py +++ b/cherab/jet/sal.py @@ -3,5 +3,25 @@ from sal.client import SALClient -sal_server = os.environ.get('JET_SAL_SERVER', 'https://sal.jetdata.eu') -sal = SALClient(host=sal_server) +SAL_SERVER = os.environ.get('JET_SAL_SERVER', 'https://sal.jetdata.eu') + + +class JETSALClient(SALClient): + """SALClient with host `sal.jetdata.eu` by default, or env variable `JET_SAL_SERVER`.""" + def __init__(self, host: str = SAL_SERVER, **kwargs): + super().__init__(host=host, **kwargs) + + +def get_jet_sal(host: str = SAL_SERVER, **kwargs) -> SALClient: + """Creates a SALClient instance connected to `host` if provided. + By default uses env variable `JET_SAL_SERVER` if set, `https://sal.jetdata.eu` otherwise. + """ + return SALClient(host=host, **kwargs) + + +def __getattr__(name: str): + if name == "sal": + value = get_jet_sal() + globals()[name] = value # cache on the module + return value + raise AttributeError(f"module {__name__!r} has no attribute {name!r}")