From 2b966f97a3842c4eecda57bff5f60e17ac42b310 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 13 Oct 2024 12:17:15 -0600 Subject: [PATCH] Add config.print_progress_categories & validate object categories --- tools/project.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/project.py b/tools/project.py index 1d9c79b..34b98ae 100644 --- a/tools/project.py +++ b/tools/project.py @@ -17,7 +17,7 @@ import os import platform import sys from pathlib import Path -from typing import IO, Any, Dict, Iterable, List, Optional, Set, Tuple, cast +from typing import IO, Any, Dict, Iterable, List, Optional, Set, Tuple, Union, cast from . import ninja_syntax from .ninja_syntax import serialize_path @@ -81,6 +81,18 @@ class Object: set_default("shift_jis", config.shift_jis) set_default("src_dir", config.src_dir) + # Validate progress categories + def check_category(category: str): + if not any(category == c.id for c in config.progress_categories): + sys.exit(f"Progress category '{category}' missing from config.progress_categories") + + progress_category = obj.options["progress_category"] + if isinstance(progress_category, list): + for category in progress_category: + check_category(category) + elif progress_category is not None: + check_category(progress_category) + # Resolve paths build_dir = config.out_path() obj.src_path = Path(obj.options["src_dir"]) / obj.options["source"] @@ -167,6 +179,9 @@ class ProjectConfig: False # Include individual modules, disable for large numbers of modules ) self.progress_categories: List[ProgressCategory] = [] # Additional categories + self.print_progress_categories: Union[bool, List[str]] = ( + True # Print additional progress categories in the CLI progress output + ) # Progress fancy printing self.progress_use_fancy: bool = False @@ -1687,7 +1702,11 @@ def calculate_progress(config: ProjectConfig) -> None: print_category("All", report_data["measures"]) for category in report_data["categories"]: - print_category(category["name"], category["measures"]) + if config.print_progress_categories is True or ( + isinstance(config.print_progress_categories, list) + and category["id"] in config.print_progress_categories + ): + print_category(category["name"], category["measures"]) if config.progress_use_fancy: measures = report_data["measures"]