Skip to content

Commit

Permalink
fix!: remove deprecated config.tcl support
Browse files Browse the repository at this point in the history
  • Loading branch information
htfab committed Dec 4, 2024
1 parent a48b1c7 commit f54d304
Showing 1 changed file with 2 additions and 49 deletions.
51 changes: 2 additions & 49 deletions config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import re
import subprocess
import tkinter
from collections.abc import Iterable

import yaml
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit f54d304

Please sign in to comment.