diff --git a/interfaces/sourcegen/sourcegen/_HeaderFileParser.py b/interfaces/sourcegen/sourcegen/_HeaderFileParser.py index 8bd0e6d329..bc2986e7e9 100644 --- a/interfaces/sourcegen/sourcegen/_HeaderFileParser.py +++ b/interfaces/sourcegen/sourcegen/_HeaderFileParser.py @@ -11,6 +11,7 @@ from ._dataclasses import HeaderFile, Func, Recipe from ._helpers import read_config +from .clib import CLibSourceGenerator _LOGGER = logging.getLogger() @@ -18,7 +19,7 @@ _CLIB_PATH = Path(__file__).parents[3] / "include" / "cantera" / "clib" _CLIB_IGNORE = ["clib_defs.h", "ctmatlab.h"] -_DATA_PATH = Path(__file__).parent / "_data" +_PWD = Path(__file__).parent class HeaderFileParser: """ @@ -38,8 +39,16 @@ def headers_from_yaml( ) -> list[HeaderFile]: """Parse header file YAML configuration.""" files = sorted( - ff for ff in _DATA_PATH.glob("*.yaml") if ff.name not in ignore_files) - return [cls(ff, ignore_funcs.get(ff.name, []))._parse_yaml() for ff in files] + ff for ff in (_PWD / "_data").glob("*.yaml") if ff.name not in ignore_files) + files = [cls(ff, ignore_funcs.get(ff.name, []))._parse_yaml() for ff in files] + + # preprocess header information (uses CLibSourceGenerator) + config = read_config(_PWD / "clib" / "config.yaml") + templates = read_config(_PWD / "clib" / "templates.yaml") + for key in ["ignore_files", "ignore_funcs"]: + config.pop(key) + CLibSourceGenerator(None, config, templates).resolve_tags(files) + return files def _parse_yaml(self) -> HeaderFile: msg = f" parsing {self._path.name!r}" diff --git a/interfaces/sourcegen/sourcegen/_orchestrate.py b/interfaces/sourcegen/sourcegen/_orchestrate.py index d0677fcb33..4f182681ee 100644 --- a/interfaces/sourcegen/sourcegen/_orchestrate.py +++ b/interfaces/sourcegen/sourcegen/_orchestrate.py @@ -9,7 +9,6 @@ from ._HeaderFileParser import HeaderFileParser from ._SourceGenerator import SourceGenerator -from .clib import CLibSourceGenerator from ._helpers import read_config @@ -45,22 +44,12 @@ def generate_source(lang: str, out_dir: str, verbose: bool = False) -> None: msg = f"Starting sourcegen for {lang!r} API" _LOGGER.info(msg) - if lang == "clib": - # prepare for generation of CLib headers in main processing step - files = HeaderFileParser.headers_from_yaml(ignore_files, ignore_funcs) - elif lang == "csharp": + if lang == "csharp": # csharp parses existing (traditional) CLib header files files = HeaderFileParser.headers_from_h(ignore_files, ignore_funcs) else: - # generate CLib headers from YAML specifications as a preprocessing step + # generate CLib headers from YAML specifications files = HeaderFileParser.headers_from_yaml(ignore_files, ignore_funcs) - clib_root = Path(__file__).parent / "clib" - clib_config = read_config(clib_root / "config.yaml") - clib_templates = read_config(clib_root / "templates.yaml") - for key in ["ignore_files", "ignore_funcs"]: - clib_config.pop(key) - clib_scaffolder = CLibSourceGenerator(None, clib_config, clib_templates) - clib_scaffolder.resolve_tags(files) # find and instantiate the language-specific SourceGenerator msg = f"Generating {lang!r} source files..." diff --git a/interfaces/sourcegen/sourcegen/yaml/config.yaml b/interfaces/sourcegen/sourcegen/yaml/config.yaml index 73adc9bbf5..aa76f4a81d 100644 --- a/interfaces/sourcegen/sourcegen/yaml/config.yaml +++ b/interfaces/sourcegen/sourcegen/yaml/config.yaml @@ -4,7 +4,8 @@ # at https://cantera.org/license.txt for license and copyright information. # Ignore these files entirely: -ignore_files: [] +ignore_files: +- ctfunc_auto.yaml # for testing purposes # Ignore these specific functions: ignore_funcs: {}