fix!: remove deprecated config.tcl support

resolves #77
This commit is contained in:
htfab
2024-12-05 08:46:44 +02:00
committed by Uri Shaked
parent a48b1c7446
commit 6372419d1e
+2 -50
View File
@@ -1,9 +1,7 @@
import json import json
import logging import logging
import os import os
import re
import subprocess import subprocess
import tkinter
from collections.abc import Iterable from collections.abc import Iterable
import yaml import yaml
@@ -13,35 +11,6 @@ class ConfigFileError(Exception):
pass 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): def read_json_config(file: str):
config = json.load(open(file)) config = json.load(open(file))
config.pop("//", None) config.pop("//", None)
@@ -84,9 +53,7 @@ def read_config(basename: str, formats: Iterable[str], design_dir: str | None =
for fmt in formats: for fmt in formats:
file = f"{basename}.{fmt}" file = f"{basename}.{fmt}"
if os.path.exists(file): if os.path.exists(file):
if fmt == "tcl": if fmt == "json":
return read_tcl_config(file, design_dir)
elif fmt == "json":
return read_json_config(file) return read_json_config(file)
elif fmt == "yaml": elif fmt == "yaml":
return read_yaml_config(file) return read_yaml_config(file)
@@ -99,19 +66,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): def write_json_config(config: dict, file: str):
with open(file, "w") as f: with open(file, "w") as f:
json.dump(config, f, indent=2) json.dump(config, f, indent=2)
@@ -135,9 +89,7 @@ def write_mk_config(config: dict, file: str):
def write_config(config: dict, basename: str, formats: Iterable[str]): def write_config(config: dict, basename: str, formats: Iterable[str]):
for fmt in formats: for fmt in formats:
file = f"{basename}.{fmt}" file = f"{basename}.{fmt}"
if fmt == "tcl": if fmt == "json":
write_tcl_config(config, file)
elif fmt == "json":
write_json_config(config, file) write_json_config(config, file)
elif fmt == "yaml": elif fmt == "yaml":
write_yaml_config(config, file) write_yaml_config(config, file)