Merge pull request #10525 from Web-mc1/main

🤖 Agent: verify failed because bake_bricolage.py imports fontTools before it reads its arguments, and CI has no fontTools. I pushed a change that checks the arguments first, so the new usage test passes without fontTools installed.
This commit is contained in:
Ludovic Marie authored and GitHub committed 2026-11-06 10:30:01 +01:00
commit 0873f24d20
3 files changed
+59

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
"""Dev tools that take paths ask for them, instead of crashing or writing a flag as a directory."""
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
TOOLS = Path(__file__).resolve().parents[1] / "tools"
def run(name: str, *arguments: str) -> tuple[subprocess.CompletedProcess, list[str]]:
"""Runs one tool in an empty folder; returns its result and whatever it left there."""
with tempfile.TemporaryDirectory() as folder:
result = subprocess.run([sys.executable, str(TOOLS / name), *arguments],
cwd=folder, text=True, capture_output=True)
left = sorted(path.name for path in Path(folder).iterdir())
return result, left
class MissingArgumentTests(unittest.TestCase):
def assert_asked_for_arguments(self, name: str, *arguments: str) -> None:
result, left = run(name, *arguments)
self.assertNotIn("Traceback", result.stderr, f"{name} crashed instead of printing usage")
self.assertNotEqual(result.returncode, 0, f"{name} reported success without its arguments")
self.assertIn("Usage", result.stderr + result.stdout, f"{name} printed no usage")
self.assertEqual(left, [], f"{name} wrote files without being told where")
class JsonLoadFixturesTests(MissingArgumentTests):
def test_no_directory_asks_for_one(self):
self.assert_asked_for_arguments("json_load_fixtures.py")
def test_a_flag_is_not_an_output_directory(self):
# It used to create ./--help and fill it with 66 MB of fixtures.
self.assert_asked_for_arguments("json_load_fixtures.py", "--help")
class BakeBricolageTests(MissingArgumentTests):
def test_no_fonts_asks_for_them(self):
self.assert_asked_for_arguments("bake_bricolage.py")
def test_one_font_is_not_enough(self):
self.assert_asked_for_arguments("bake_bricolage.py", "source.ttf")
if __name__ == "__main__":
unittest.main()
+7
View File
@@ -22,6 +22,13 @@ import sys
import unicodedata
from pathlib import Path
# Before the fontTools imports: a machine without fontTools still gets the usage, not a traceback.
if __name__ == "__main__" and (
len(sys.argv) != 3 or any(argument.startswith("-") for argument in sys.argv[1:])
):
sys.exit(__doc__ + "\nUsage: python3 tools/bake_bricolage.py "
"'BricolageGrotesque[opsz,wdth,wght].ttf' 'Geist[wght].ttf'")
from fontTools.pens.boundsPen import BoundsPen
from fontTools.pens.recordingPen import DecomposingRecordingPen
from fontTools.pens.transformPen import TransformPen
+4
View File
@@ -67,6 +67,10 @@ def write(path, target, entry, defaults=False):
print(f"{path.name}: {path.stat().st_size} bytes, {count} states")
# A flag is not a directory: `--help` must print this usage instead of writing 66 MB into `./--help`.
if len(sys.argv) != 2 or sys.argv[1].startswith("-"):
sys.exit(__doc__)
root = Path(sys.argv[1])
root.mkdir(parents=True, exist_ok=True)
write(root / "gameplay-facts.json", 55_700_000, gameplay)