@@ -90,15 +90,14 @@ def check(self, value: Any) -> None: # pylint: disable=unused-argument
9090 ValueError: If the value is not valid.
9191 """
9292 # This method can be overridden in subclasses for specific validation
93- pass
9493
9594 def get (self ) -> Any :
9695 """Return the current value of the option.
9796
9897 Returns:
9998 The current value of the option.
10099 """
101- self ._container ._ensure_loaded_from_env ()
100+ self ._container .ensure_loaded_from_env ()
102101 return self ._value
103102
104103 def set (self , value : Any , sync_env : bool = True ) -> None :
@@ -111,7 +110,7 @@ def set(self, value: Any, sync_env: bool = True) -> None:
111110 self .check (value ) # Validate the new value
112111 self ._value = value
113112 if sync_env :
114- self ._container ._sync_env ()
113+ self ._container .sync_env ()
115114
116115 def context (self , temp_value : Any ) -> Generator [None , None , None ]:
117116 """Temporarily override the option within a context.
@@ -218,13 +217,14 @@ def check(self, value: Any) -> None:
218217 "Each item must be a tuple of (format, description) as strings"
219218 )
220219
221- def set (self , value : Any ) -> None :
222- """Set the value of the image I/O formats option.
220+ def set (self , value : Any , sync_env : bool = True ) -> None :
221+ """Set the value of the option.
223222
224223 Args:
225224 value: The new value to assign.
225+ sync_env: Whether to synchronize the environment variable.
226226 """
227- super ().set (value )
227+ super ().set (value , sync_env )
228228 from sigima_ .io .image import formats # pylint: disable=import-outside-toplevel
229229
230230 # Generate image I/O format classes based on the new value
@@ -285,9 +285,9 @@ def __init__(self) -> None:
285285
286286.. note::
287287
288- The `sigima` library supports any image format that can be read by the
289- `imageio` library, provided that the associated plugin(s) are installed
290- (see `imageio documentation <https://imageio.readthedocs.io/en/stable/formats/index.html>`_)
288+ The `sigima` library supports any image format that can be read by the `imageio`
289+ library, provided that the associated plugin(s) are installed (see `imageio
290+ documentation <https://imageio.readthedocs.io/en/stable/formats/index.html>`_)
291291 and that the output NumPy array data type and shape are supported by `sigima`.
292292
293293 To add a new file format, you may use the `imageio_formats` option to specify
@@ -330,19 +330,20 @@ def generate_rst_doc(self) -> str:
330330 doc += f" - { opt .description } \n "
331331 return doc
332332
333- def _ensure_loaded_from_env (self ) -> None :
333+ def ensure_loaded_from_env (self ) -> None :
334334 """Lazy-load from JSON env var on first access."""
335335 if self ._loaded_from_env :
336336 return
337337 if self .ENV_VAR in os .environ :
338338 try :
339339 values = json .loads (os .environ [self .ENV_VAR ])
340340 self .from_dict (values )
341- except Exception as e :
342- print (f"[sigima] Warning: failed to load options from env: { e } " )
341+ except Exception as exc : # pylint: disable=broad-except
342+ # If loading fails, we just log a warning and continue with defaults
343+ print (f"[sigima] Warning: failed to load options from env: { exc } " )
343344 self ._loaded_from_env = True
344345
345- def _sync_env (self ) -> None :
346+ def sync_env (self ) -> None :
346347 """Update env var with current option values."""
347348 os .environ [self .ENV_VAR ] = json .dumps (self .to_dict ())
348349
@@ -369,7 +370,7 @@ def from_dict(self, values: dict[str, Any]) -> None:
369370 opt = getattr (self , name )
370371 if isinstance (opt , OptionField ):
371372 opt .set (value , sync_env = False )
372- self ._sync_env ()
373+ self .sync_env ()
373374
374375
375376#: Global instance of the options container
0 commit comments