From f54d3044a712806e345c0c26a8f5cfbb4b2c184d Mon Sep 17 00:00:00 2001 From: htfab Date: Thu, 5 Dec 2024 00:23:03 +0100 Subject: [PATCH] fix!: remove deprecated config.tcl support resolves #77 --- config_utils.py | 51 ++----------------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/config_utils.py b/config_utils.py index 1f4083b..31c67bf 100644 --- a/config_utils.py +++ b/config_utils.py @@ -3,7 +3,6 @@ import os import re import subprocess -import tkinter from collections.abc import Iterable import yaml @@ -13,35 +12,6 @@ class ConfigFileError(Exception): pass -def read_tcl_config(file: str, design_dir: str | None = None): - logging.warning( - "Support for TCL configuration files is deprecated and will be removed" - ) - if design_dir is None: - design_dir = os.path.dirname(file) - design_dir = os.path.realpath(design_dir) - tcl_code = open(file).read() - interp = tkinter.Tcl() - interp.eval("array unset ::env") - interp.setvar("env(DESIGN_DIR)", design_dir) - config = {} - env_rx = re.compile(r"(?:\:\:)?env\((\w+)\)") - - def py_set(key: str, value: str | None = None): - if match := env_rx.fullmatch(key): - if value is not None: - value = value.replace(design_dir, "dir::") - value = value.replace("dir::/", "dir::") - config[match.group(1)] = value - - py_set_name = interp.register(py_set) - interp.call("rename", py_set_name, "_py_set") - interp.call("rename", "set", "_orig_set") - interp.eval("proc set args { _py_set {*}$args; tailcall _orig_set {*}$args; }") - interp.eval(tcl_code) - return config - - def read_json_config(file: str): config = json.load(open(file)) config.pop("//", None) @@ -84,9 +54,7 @@ def read_config(basename: str, formats: Iterable[str], design_dir: str | None = for fmt in formats: file = f"{basename}.{fmt}" if os.path.exists(file): - if fmt == "tcl": - return read_tcl_config(file, design_dir) - elif fmt == "json": + if fmt == "json": return read_json_config(file) elif fmt == "yaml": return read_yaml_config(file) @@ -99,19 +67,6 @@ def read_config(basename: str, formats: Iterable[str], design_dir: str | None = ) -def write_tcl_config(config: dict, file: str): - logging.warning( - "Support for TCL configuration files is deprecated and will be removed" - ) - with open(file, "w") as f: - for key, value in config.items(): - if type(value) in (list, tuple): - value = " ".join(value) - if type(value) == str: - value = value.replace("dir::", "$::env(DESIGN_DIR)/") - print(f'set ::env({key}) "{value}"', file=f) - - def write_json_config(config: dict, file: str): with open(file, "w") as f: json.dump(config, f, indent=2) @@ -135,9 +90,7 @@ def write_mk_config(config: dict, file: str): def write_config(config: dict, basename: str, formats: Iterable[str]): for fmt in formats: file = f"{basename}.{fmt}" - if fmt == "tcl": - write_tcl_config(config, file) - elif fmt == "json": + if fmt == "json": write_json_config(config, file) elif fmt == "yaml": write_yaml_config(config, file)