mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
feat: parse env var strings to expected config value types (#3107)
* fix: add try_parse_bool for env var strings to enable config overrides of boolean values * fix: fallback to given value if not parseable * feat: extend eval to all valid types * fix: remove return type * fix: prevent strange type conversions by providing expected type * feat: add tests
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import os
|
||||
from ast import literal_eval
|
||||
|
||||
|
||||
def makedirs_with_log(path):
|
||||
try:
|
||||
@@ -24,3 +26,16 @@ def get_files_from_folder(folder_path, extensions=None, name_filter=None):
|
||||
filenames.append(path)
|
||||
|
||||
return filenames
|
||||
|
||||
|
||||
def try_eval_env_var(value: str, expected_type=None):
|
||||
try:
|
||||
value_eval = value
|
||||
if expected_type is bool:
|
||||
value_eval = value.title()
|
||||
value_eval = literal_eval(value_eval)
|
||||
if expected_type is not None and not isinstance(value_eval, expected_type):
|
||||
return value
|
||||
return value_eval
|
||||
except:
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user