style: 代码格式化
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
全局上下文管理模块
|
||||
以及基准路径
|
||||
"""
|
||||
|
||||
from contextvars import ContextVar
|
||||
import pathlib
|
||||
from heurams.services.config import ConfigFile
|
||||
@@ -11,17 +12,22 @@ from heurams.services.config import ConfigFile
|
||||
# 数据文件路径规定: 以运行目录为准
|
||||
|
||||
rootdir = pathlib.Path(__file__).parent
|
||||
print(f'rootdir: {rootdir}')
|
||||
print(f"rootdir: {rootdir}")
|
||||
workdir = pathlib.Path.cwd()
|
||||
print(f'workdir: {workdir}')
|
||||
config_var: ContextVar[ConfigFile] = ContextVar('config_var', default=ConfigFile(rootdir / "default" / "config" / "config.toml"))
|
||||
print(f"workdir: {workdir}")
|
||||
config_var: ContextVar[ConfigFile] = ContextVar(
|
||||
"config_var", default=ConfigFile(rootdir / "default" / "config" / "config.toml")
|
||||
)
|
||||
try:
|
||||
config_var: ContextVar[ConfigFile] = ContextVar('config_var', default=ConfigFile(workdir / "config" / "config.toml")) # 配置文件
|
||||
print('已加载自定义用户配置')
|
||||
config_var: ContextVar[ConfigFile] = ContextVar(
|
||||
"config_var", default=ConfigFile(workdir / "config" / "config.toml")
|
||||
) # 配置文件
|
||||
print("已加载自定义用户配置")
|
||||
except:
|
||||
print('未能加载自定义用户配置')
|
||||
print("未能加载自定义用户配置")
|
||||
|
||||
# runtime_var: ContextVar = ContextVar('runtime_var', default=dict()) # 运行时共享数据
|
||||
|
||||
#runtime_var: ContextVar = ContextVar('runtime_var', default=dict()) # 运行时共享数据
|
||||
|
||||
class ConfigContext:
|
||||
"""
|
||||
@@ -33,14 +39,14 @@ class ConfigContext:
|
||||
... get_daystamp() # 使用 test_config
|
||||
>>> get_daystamp() # 恢复原配置
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, config_provider: ConfigFile):
|
||||
self.config_provider = config_provider
|
||||
self._token = None
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
self._token = config_var.set(self.config_provider)
|
||||
return self
|
||||
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
config_var.reset(self._token) # type: ignore
|
||||
config_var.reset(self._token) # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user