From b76b5d5ee17e9a38f8b62d0f7f9f5a7b150c7342 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Fri, 16 Aug 2024 19:53:04 -0500 Subject: [PATCH] [sourcegen] Simplify TagFileParser --- interfaces/sourcegen/sourcegen/_TagFileParser.py | 14 ++++---------- interfaces/sourcegen/sourcegen/_orchestrate.py | 15 +++++++++------ interfaces/sourcegen/sourcegen/yaml/_Config.py | 7 +++++++ .../sourcegen/yaml/_YamlSourceGenerator.py | 4 ++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/interfaces/sourcegen/sourcegen/_TagFileParser.py b/interfaces/sourcegen/sourcegen/_TagFileParser.py index 22040a9f56..7e9428d742 100644 --- a/interfaces/sourcegen/sourcegen/_TagFileParser.py +++ b/interfaces/sourcegen/sourcegen/_TagFileParser.py @@ -17,7 +17,7 @@ class TagFileParser: """Class handling contents of doxygen tag file.""" - def _parse_doxyfile(self, class_crosswalk: Dict[str, str]): + def _parse_doxyfile(self, class_crosswalk: List[str]): """Retrieve class and function information from Cantera namespace.""" def xml_compounds(kind: str, names: List[str]) -> Dict[str,str]: @@ -43,10 +43,7 @@ def xml_compounds(kind: str, names: List[str]) -> Dict[str,str]: class_names = [_.split(":")[-1] for _ in qualified_names] # Handle exceptions for unknown/undocumented classes - configured = [] - for cls in class_crosswalk.values(): - configured.extend(cls) # one prefix can map to multiple classes - unknown = set(configured) - set(class_names) + unknown = set(class_crosswalk) - set(class_names) if unknown: unknown = "', '".join(unknown) logger.warning( @@ -54,7 +51,7 @@ def xml_compounds(kind: str, names: List[str]) -> Dict[str,str]: f"'{unknown}'") # Parse content of classes that are specified by the configuration file - class_names = set(configured) & set(class_names) + class_names = set(class_crosswalk) & set(class_names) classes = xml_compounds("class", class_names) def xml_members(kind: str, text: str, prefix="") -> Dict[str, str]: @@ -87,10 +84,6 @@ def __init__(self, class_crosswalk: Dict[str, str]) -> None: self._parse_doxyfile(class_crosswalk) - @staticmethod - def from_parsed(parsed_config_file: dict): - return TagFileParser(parsed_config_file["class_crosswalk"]) - def annotated_func(self, parsed: Func) -> Union[AnnotatedFunc, None]: """Match function with doxygen tag information.""" comments = parsed.annotations @@ -143,6 +136,7 @@ def doxygen_func(tag: str, text: str) -> Union[str, None]: xml_tags("anchorfile", xml)[0].replace(".html", ".xml"), xml_tags("anchor", xml)[0]) + def xml_tags(tag: str, text: str, suffix: str="") -> Union[str, None]: if suffix: suffix = f" {suffix.strip()}" diff --git a/interfaces/sourcegen/sourcegen/_orchestrate.py b/interfaces/sourcegen/sourcegen/_orchestrate.py index eb8b533cf9..4e1b558e36 100644 --- a/interfaces/sourcegen/sourcegen/_orchestrate.py +++ b/interfaces/sourcegen/sourcegen/_orchestrate.py @@ -45,14 +45,17 @@ def generate_source(lang: str, out_dir: str=""): reader = ruamel.yaml.YAML(typ="safe") config = reader.load(config_file) - ignore_files: List[str] = config.get("ignore_files", []) + ignore_files: List[str] = config.get("ignore_files", ["all"]) ignore_funcs: Dict[str, List[str]] = config.get("ignore_funcs", {}) - files = (HeaderFileParser(f, ignore_funcs.get(f.name, [])).parse() - for f in _clib_path.glob("*.h") - if f != _clib_defs_path and f.name not in ignore_files) - # removes instances where HeaderFile.parse() returned None - files = list(filter(None, files)) + if "all" in ignore_files: + files = [] + else: + files = (HeaderFileParser(f, ignore_funcs.get(f.name, [])).parse() + for f in _clib_path.glob("*.h") + if f != _clib_defs_path and f.name not in ignore_files) + # removes instances where HeaderFile.parse() returned None + files = list(filter(None, files)) # find and instantiate the language-specific SourceGenerator _, scaffolder_type = inspect.getmembers(module, diff --git a/interfaces/sourcegen/sourcegen/yaml/_Config.py b/interfaces/sourcegen/sourcegen/yaml/_Config.py index 8a48077fdb..cacf301abe 100644 --- a/interfaces/sourcegen/sourcegen/yaml/_Config.py +++ b/interfaces/sourcegen/sourcegen/yaml/_Config.py @@ -15,3 +15,10 @@ class Config: @staticmethod def from_parsed(parsed_config_file: dict): return Config(parsed_config_file["class_crosswalk"]) + + def classes(self): + """Return all classes referenced in configuration file.""" + ret = [] + for cls in self.class_crosswalk.values(): + ret.extend(cls) # one prefix can map to multiple classes + return ret diff --git a/interfaces/sourcegen/sourcegen/yaml/_YamlSourceGenerator.py b/interfaces/sourcegen/sourcegen/yaml/_YamlSourceGenerator.py index 1095fffdce..70e22087ef 100644 --- a/interfaces/sourcegen/sourcegen/yaml/_YamlSourceGenerator.py +++ b/interfaces/sourcegen/sourcegen/yaml/_YamlSourceGenerator.py @@ -27,7 +27,7 @@ def __init__(self, out_dir: str, config: dict): # use the typed config self._config = Config.from_parsed(config) - self._doxygen = TagFileParser.from_parsed(config) + self._doxygen_tags = TagFileParser(self._config.classes()) def generate_source(self, headers_files: List[HeaderFile]): """Generate output""" @@ -36,7 +36,7 @@ def generate_source(self, headers_files: List[HeaderFile]): for header_file in headers_files: name = header_file.path.name annotated_map[name] = [] - for func in list(map(self._doxygen.annotated_func, header_file.funcs)): + for func in list(map(self._doxygen_tags.annotated_func, header_file.funcs)): if func is not None: annotated_map[name].append(func)