@@ -58,10 +58,14 @@ class SimvueConfiguration(pydantic.BaseModel):
5858 server : ServerSpecifications = pydantic .Field (
5959 ..., description = "Specifications for Simvue server"
6060 )
61+ profiles : dict [str , ServerSpecifications ] = pydantic .Field (
62+ default_factory = dict [str , ServerSpecifications ]
63+ )
6164 run : DefaultRunSpecifications = DefaultRunSpecifications ()
6265 offline : OfflineSpecifications = OfflineSpecifications ()
6366 metrics : MetricsSpecifications = MetricsSpecifications ()
6467 eco : EcoConfig = EcoConfig ()
68+ current_profile : str | None = None
6569
6670 @classmethod
6771 def _load_pyproject_configs (cls ) -> dict | None :
@@ -161,6 +165,7 @@ def fetch(
161165 mode : typing .Literal ["offline" , "online" , "disabled" ],
162166 server_url : str | None = None ,
163167 server_token : str | None = None ,
168+ profile : str | None = None ,
164169 ) -> "SimvueConfiguration" :
165170 """Retrieve the Simvue configuration from this project
166171
@@ -178,6 +183,8 @@ def fetch(
178183 * online - send metrics and data to a server.
179184 * offline - run in offline mode.
180185 * disabled - run in disabled mode.
186+ profile : str | None, optional
187+ specify server profile to user for URL and token.
181188
182189 Return
183190 ------
@@ -187,16 +194,26 @@ def fetch(
187194 """
188195 _config_dict : dict [str , dict [str , str ]] = cls ._load_pyproject_configs () or {}
189196
197+ profile = os .environ .get ("SIMVUE_SERVER_PROFILE" , profile )
198+
190199 try :
191200 # NOTE: Legacy INI support has been removed
192201 _config_dict |= toml .load (cls .config_file ())
193202
194203 except FileNotFoundError :
195204 if not server_token or not server_url :
196- _config_dict = {"server" : {}}
205+ _config_dict | = {"server" : {}}
197206 logger .debug ("No config file found, checking environment variables" )
198207
199- _config_dict ["server" ] = _config_dict .get ("server" , {})
208+ if not profile :
209+ _config_dict ["server" ] = _config_dict .get ("server" , {})
210+ elif not _config_dict .get ("profiles" , {}).get (profile ):
211+ raise RuntimeError (
212+ f"Cannot load server configuration for '{ profile } ', "
213+ "profile not found in configurations."
214+ )
215+ else :
216+ _config_dict ["server" ] = _config_dict ["profiles" ][profile ]
200217
201218 _config_dict ["offline" ] = _config_dict .get ("offline" , {})
202219
@@ -237,7 +254,7 @@ def fetch(
237254 _config_dict ["server" ]["url" ] = _server_url
238255 _config_dict ["run" ]["mode" ] = _run_mode
239256
240- return SimvueConfiguration (** _config_dict )
257+ return SimvueConfiguration (current_profile = profile , ** _config_dict )
241258
242259 @classmethod
243260 @functools .lru_cache
0 commit comments