2626import glob
2727import os
2828import shutil
29+ import warnings
2930from sys import platform
3031
3132import yaml
@@ -61,7 +62,6 @@ def __init__(self):
6162 "/tmp/cubitpy_{}" .format (getpass .getuser ()), # nosec
6263 "pid_{}" .format (os .getpid ()),
6364 )
64-
6565 self .temp_log = os .path .join (self .temp_dir , "cubitpy.log" )
6666
6767 # Check if temp path exits, if not create it.
@@ -89,9 +89,11 @@ def __init__(self):
8989 def get_cubit_root_path (** kwargs ):
9090 """Get Path to cubit root directory."""
9191 if cupy .is_remote ():
92- print (
93- "[WARNING] Cubitpy is running in remote mode. "
94- "The CUBIT_ROOT environment variable is ignored."
92+ warnings .warn (
93+ "Cubit is running in remote mode because CUBIT_REMOTE_CONFIG_FILE is set. "
94+ "The remote Cubit installation will be used, and the local CUBIT_ROOT "
95+ "setting is ignored." ,
96+ UserWarning ,
9597 )
9698 return get_path ("CUBIT_ROOT" , os .path .isdir , ** kwargs )
9799
@@ -102,14 +104,14 @@ def get_cubit_remote_config_filepath():
102104
103105 @classmethod
104106 def get_cubit_remote_config (cls ):
105- """Get remote Cubit config from YAML file ."""
107+ """Load (user, host, remote_cubit_root) from YAML config ."""
106108 TEMPLATE = (
107109 "\n Expected YAML format:\n "
108110 "----------------------------------------\n "
109111 "remote:\n "
110112 ' user: "<username>"\n '
111113 ' host: "<hostname_or_ip>"\n '
112- " remote_cubit_root: <remote_cubit_root_path_in_remote_path_syntax >\n "
114+ " remote_cubit_root: <remote_path >\n "
113115 "----------------------------------------\n "
114116 )
115117
@@ -118,25 +120,23 @@ def fail(msg):
118120 raise RuntimeError (msg + TEMPLATE )
119121
120122 path = cls .get_cubit_remote_config_filepath ()
121- if path is None :
122- fail ("CUBIT_REMOTE_CONFIG_FILE: file not found." )
123+ if not path :
124+ fail ("Config file not found." )
123125
124126 try :
125- with open (path ) as f :
127+ with open (path , "r" ) as f :
126128 data = yaml .safe_load (f )
127129 except Exception as e :
128- fail (f"Failed to read YAML file: { e } " )
129-
130- if not isinstance (data , dict ) or "remote" not in data :
131- fail ("Missing 'remote' section in YAML config." )
130+ fail (f"Failed to read YAML at '{ path } ': { e } " )
132131
133- required = ["user" , "host" , "remote_cubit_root" ]
134- missing = [k for k in required if k not in data ["remote" ]]
135- if missing :
136- fail (f"Missing keys: { ', ' .join (missing )} " )
132+ remote = data .get ("remote" ) if isinstance (data , dict ) else None
133+ if not remote :
134+ fail ("Missing 'remote' section." )
137135
138- cfg = data ["remote" ]
139- return cfg ["user" ], cfg ["host" ], cfg ["remote_cubit_root" ]
136+ try :
137+ return remote ["user" ], remote ["host" ], remote ["remote_cubit_root" ]
138+ except KeyError as k :
139+ fail (f"Missing key: { k .args [0 ]} " )
140140
141141 @classmethod
142142 def get_cubit_exe_path (cls , ** kwargs ):
0 commit comments