feat: load neutral workflow config
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from .loader import load_workflow_config
|
||||
from .models import (
|
||||
ClientConfig,
|
||||
FilesystemStoreConfig,
|
||||
@@ -12,6 +13,7 @@ from .models import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"load_workflow_config",
|
||||
"ClientConfig",
|
||||
"FilesystemStoreConfig",
|
||||
"LocalTargetConfig",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from .models import FilesystemStoreConfig, WorkflowConfigFile
|
||||
|
||||
|
||||
def load_workflow_config(path: str | Path) -> WorkflowConfigFile:
|
||||
"""Load neutral workflow config and resolve local filesystem paths.
|
||||
|
||||
Relative filesystem store roots are config-file relative so `wf --config`
|
||||
behaves the same regardless of the caller's current working directory.
|
||||
"""
|
||||
|
||||
config_path = Path(path)
|
||||
data = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
config = WorkflowConfigFile.model_validate(data)
|
||||
store = config.server.store
|
||||
if isinstance(store, FilesystemStoreConfig) and not store.root.is_absolute():
|
||||
config = config.model_copy(
|
||||
update={
|
||||
"server": config.server.model_copy(
|
||||
update={
|
||||
"store": store.model_copy(
|
||||
update={"root": (config_path.parent / store.root).resolve()}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
return config
|
||||
Reference in New Issue
Block a user