From 42c81ef7de8b5c286f2db51ff6e029044701deda Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 6 Jan 2025 13:56:12 -0600 Subject: [PATCH] scripts: Switched to tomllib/tomli for toml parsing Found a bug in our toml parser that's difficult to work around: defines.GC_FLAGS = """ => { LFS_GC_MKCONSISTENT "GC_FLAGS": "blablabla", | LFS_GC_LOOKAHEAD } // where did defines go? """ This appears to be this bug: https://github.com/uiri/toml/issues/286 But since it was opened 4 years ago, I think it's safe to say this toml library is now defunct... --- Apparently tomllib/tomli is the new hotness, which started as tomli before being adopt in Python 3.11 as tomllib. Fortunately tomli is still maintained so we don't have to worry about Python versions too much. Adopting tomli was relatively straightforward, the only hiccup being that it doesn't support text files? Curious, but fortunately Python exposes the underlying binary file handle in f.buffer. --- scripts/bench.py | 8 ++++++-- scripts/test.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/bench.py b/scripts/bench.py index 99b74f1f..15c0e2b7 100755 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -29,7 +29,11 @@ import subprocess as sp import sys import threading as th import time -import toml + +try: + import tomllib as toml +except ModuleNotFoundError: + import tomli as toml RUNNER_PATH = ['./runners/bench_runner'] @@ -182,7 +186,7 @@ class BenchSuite: # load toml file and parse bench cases with open(self.path) as f: # load benches - config = toml.load(f) + config = toml.load(f.buffer) # find line numbers f.seek(0) diff --git a/scripts/test.py b/scripts/test.py index 3307584e..411d6b65 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -30,7 +30,11 @@ import subprocess as sp import sys import threading as th import time -import toml + +try: + import tomllib as toml +except ModuleNotFoundError: + import tomli as toml RUNNER_PATH = ['./runners/test_runner'] @@ -188,7 +192,7 @@ class TestSuite: # load toml file and parse test cases with open(self.path) as f: # load tests - config = toml.load(f) + config = toml.load(f.buffer) # find line numbers f.seek(0)