Skip to content

Commit

Permalink
[sourcegen] Simplify orchestrate
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 27, 2025
1 parent 7e7d7c2 commit ef63709
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
15 changes: 12 additions & 3 deletions interfaces/sourcegen/sourcegen/_HeaderFileParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

from ._dataclasses import HeaderFile, Func, Recipe
from ._helpers import read_config
from .clib import CLibSourceGenerator


_LOGGER = logging.getLogger()

_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:
"""
Expand All @@ -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}"
Expand Down
15 changes: 2 additions & 13 deletions interfaces/sourcegen/sourcegen/_orchestrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from ._HeaderFileParser import HeaderFileParser
from ._SourceGenerator import SourceGenerator
from .clib import CLibSourceGenerator
from ._helpers import read_config


Expand Down Expand Up @@ -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..."
Expand Down
3 changes: 2 additions & 1 deletion interfaces/sourcegen/sourcegen/yaml/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

0 comments on commit ef63709

Please sign in to comment.