Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite77b473

Browse files
committed
feat(config): add environment variable parsing for configuration
- Introduced a new function `parse_env` to recursively expand $env:VARIABLE_NAME patterns in strings, dicts, and lists.- Updated `get_config` to utilize `parse_env` for normalizing configuration values.
1 parent3988ff7 commite77b473

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

‎src/core/config.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
importlogging
2+
importos
3+
importre
24
importshutil
35
importsettings
46
fromosimportpath,makedirs
@@ -75,6 +77,23 @@ def get_stylesheet_path() -> str:
7577
returnDEFAULT_STYLES_PATH
7678

7779

80+
defparse_env(obj):
81+
"""
82+
Recursively expand $env:VARIABLE_NAME patterns in strings,
83+
dicts, and lists.
84+
"""
85+
ifisinstance(obj,dict):
86+
return {k:parse_env(v)fork,vinobj.items()}
87+
elifisinstance(obj,list):
88+
return [parse_env(item)foriteminobj]
89+
elifisinstance(obj,str):
90+
pattern=r'\$env:([\w_]+)'
91+
forvarinre.findall(pattern,obj):
92+
val=os.environ.get(var,'')
93+
obj=obj.replace(f'$env:{var}',val)
94+
returnobj
95+
96+
7897
defget_config(show_error_dialog=False)->Union[dict,None]:
7998
config_path=get_config_path()
8099

@@ -83,7 +102,7 @@ def get_config(show_error_dialog=False) -> Union[dict, None]:
83102
config=safe_load(yaml_stream)
84103

85104
ifyaml_validator.validate(config,CONFIG_SCHEMA):
86-
returnyaml_validator.normalized(config)
105+
returnparse_env(yaml_validator.normalized(config))
87106
else:
88107
pretty_errors=dump(yaml_validator.errors)
89108
logging.error(f"The config file '{config_path}' contains validation errors. Please fix:\n{pretty_errors}")
@@ -107,8 +126,6 @@ def get_stylesheet(show_error_dialog=False) -> Union[str, None]:
107126
try:
108127
css_processor=CSSProcessor(styles_path)
109128
css_content=css_processor.process()
110-
#parser = CSSParser(raiseExceptions=True, parseComments=False)
111-
#css_final = parser.parseString(css_content).cssText.decode('utf-8')
112129
returncss_content
113130

114131
exceptSyntaxErrase:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp