fix template fill consistency for TOML

This commit is contained in:
2025-12-19 18:15:59 -08:00
parent a12b952343
commit 8039fb3d0b
5 changed files with 486 additions and 19 deletions

View File

@@ -365,7 +365,7 @@ class ConfigManager:
theme_dict = {}
for file_part in relaxed_theme_matches:
toml_dict = TOMLTemplate(file_part.path).fill(palette_dict)
toml_dict = TOMLTemplate(file_part.path).fill_dict(palette_dict)
theme_dict = util.deep_update(theme_dict, toml_dict)
template_dict = {
@@ -423,7 +423,8 @@ class ConfigManager:
theme_dict = {}
palette_dict = TOMLTemplate.stack_toml(palette_paths)
for file_part in relaxed_theme_matches:
toml_dict = TOMLTemplate(file_part.path).fill(palette_dict)
toml_template = TOMLTemplate(file_part.path)
toml_dict = toml_template.fill_dict(palette_dict)
theme_dict = util.deep_update(theme_dict, toml_dict)
theme_map[fp.path.stem] = {"theme": theme_dict}
@@ -965,6 +966,9 @@ class ConfigManager:
return
# otherwise bottle up and run as specified user w/ permissions
# this looks sorta silly but I frankly think it's the easiest way to
# compactly set up a symlink procedure under an elevated subprocess (we
# *have* to wrap this up; can't do it in the current process)
compact_symlink_py = (
"import os,sys,pathlib;"
"p=pathlib.Path(sys.argv[1]).parent;"

View File

@@ -50,10 +50,10 @@ class DictReader:
def copy(self) -> "DictReader":
return self.from_dict(copy.deepcopy(self._config))
def get_subconfig(self, key: str) -> "DictReader":
def get_subconfig(self, key: str) -> None: # "DictReader":
pass
def get(self, key: str, default: str | None = None) -> str:
def get(self, key: str, default: str | None = None) -> str | None:
keys = key.split(".")
subconfig = self._config
@@ -65,7 +65,7 @@ class DictReader:
return subconfig.get(keys[-1], default)
def set(self, key: str, value: str) -> bool:
def set(self, key: str, value: str | None) -> bool:
keys = key.split(".")
subconfig = self._config

View File

@@ -4,6 +4,7 @@ Support for basic config templates
import re
import tomllib
from typing import Any
from pathlib import Path
from symconf import util
@@ -89,10 +90,10 @@ class TOMLTemplate(FileTemplate):
exe_pattern=exe_pattern,
)
def fill(
def fill_dict(
self,
template_dict: dict,
) -> str:
) -> dict[str, Any]:
filled_template = super().fill(template_dict)
toml_dict = tomllib.loads(filled_template)