@@ -311,28 +311,6 @@ def get_store_spec(self, store: str) -> Dict[str, Any]:
311311
312312 return spec
313313
314- def save (self , filename : Optional [Union [str , Path ]] = None , verbose : bool = False ) -> None :
315- """
316- Save settings to a JSON file.
317-
318- Args:
319- filename: Path to save the configuration. Defaults to datajoint.json in cwd.
320- verbose: If True, log the save operation.
321- """
322- if filename is None :
323- filename = Path .cwd () / CONFIG_FILENAME
324-
325- data = self ._to_flat_dict ()
326- # Remove secrets from saved config
327- secrets_keys = ["database.password" , "external.aws_secret_access_key" ]
328- for key in secrets_keys :
329- data .pop (key , None )
330-
331- with open (filename , "w" ) as f :
332- json .dump (data , f , indent = 4 , default = str )
333- if verbose :
334- logger .info (f"Saved settings to { filename } " )
335-
336314 def load (self , filename : Union [str , Path ]) -> None :
337315 """
338316 Load settings from a JSON file.
@@ -352,31 +330,6 @@ def load(self, filename: Union[str, Path]) -> None:
352330 self ._update_from_flat_dict (data )
353331 self ._config_path = filepath
354332
355- def _to_flat_dict (self ) -> Dict [str , Any ]:
356- """Convert settings to flat dict with dot notation keys."""
357- result : Dict [str , Any ] = {}
358-
359- def flatten (obj : Any , prefix : str = "" ) -> None :
360- if isinstance (obj , BaseSettings ):
361- for name in obj .model_fields :
362- if name .startswith ("_" ):
363- continue
364- value = getattr (obj , name )
365- key = f"{ prefix } .{ name } " if prefix else name
366- if isinstance (value , BaseSettings ):
367- flatten (value , key )
368- elif isinstance (value , SecretStr ):
369- result [key ] = value .get_secret_value () if value else None
370- elif isinstance (value , Path ):
371- result [key ] = str (value )
372- else :
373- result [key ] = value
374- elif isinstance (obj , dict ):
375- result [prefix ] = obj
376-
377- flatten (self )
378- return result
379-
380333 def _update_from_flat_dict (self , data : Dict [str , Any ]) -> None :
381334 """Update settings from a flat dict with dot notation keys."""
382335 for key , value in data .items ():
0 commit comments