From 890dec979ea77340cb65b06eaef594d505a842f2 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Fri, 25 Oct 2024 15:58:29 -0400 Subject: [PATCH] [fontc] Add --experimental-single-source flag This instructs gftools to only build the single named source file. --- Lib/gftools/builder/__init__.py | 8 +++++++- Lib/gftools/builder/fontc.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Lib/gftools/builder/__init__.py b/Lib/gftools/builder/__init__.py index 931e97b2..9eca2408 100644 --- a/Lib/gftools/builder/__init__.py +++ b/Lib/gftools/builder/__init__.py @@ -7,7 +7,7 @@ from os import chdir from pathlib import Path from tempfile import NamedTemporaryFile, gettempdir -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Tuple, Union from gftools.builder.fontc import FontcArgs import networkx as nx @@ -401,6 +401,12 @@ def main(args=None): type=Path, ) + parser.add_argument( + "--experimental-single-source", + help="only compile the single named source file", + type=str, + ) + parser.add_argument("config", help="Path to config file or source file", nargs="+") args = parser.parse_args(args) fontc_args = FontcArgs(args) diff --git a/Lib/gftools/builder/fontc.py b/Lib/gftools/builder/fontc.py index 9a717126..0db9c340 100644 --- a/Lib/gftools/builder/fontc.py +++ b/Lib/gftools/builder/fontc.py @@ -14,6 +14,7 @@ class FontcArgs: simple_output_path: Union[Path, None] fontc_bin_path: Union[Path, None] + single_source: Union[str, None] # init with 'None' returns a default obj where everything is None def __init__(self, args: Union[Namespace, None]) -> None: @@ -21,6 +22,7 @@ def __init__(self, args: Union[Namespace, None]) -> None: return None self.simple_output_path = abspath(args.experimental_simple_output) self.fontc_bin_path = abspath(args.experimental_fontc) + self.single_source = args.experimental_single_source if self.fontc_bin_path: if not self.fontc_bin_path.is_file(): raise ValueError(f"fontc does not exist at {self.fontc_bin_path}") @@ -51,6 +53,14 @@ def modify_config(self, config: dict): config["outputDir"] = str(output_dir) config["ttDir"] = str(output_dir) config["otDir"] = str(output_dir) + if self.single_source: + filtered_sources = [s for s in config["sources"] if self.single_source in s] + n_sources = len(filtered_sources) + if n_sources != 1: + raise ValueError( + f"--exerimental-single-source {self.single_source} must match exactly one of {config['sources']} (matched {n_sources}) " + ) + config["sources"] = filtered_sources def abspath(path: Union[Path, None]) -> Union[Path, None]: