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.
This commit is contained in:
Christopher Haster
2025-01-06 13:56:12 -06:00
parent 59b0906fa1
commit 42c81ef7de
2 changed files with 12 additions and 4 deletions

View File

@@ -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)