diff --git a/tools/bin/_profile_paths.py b/tools/bin/_profile_paths.py index 44ece26..65ac928 100644 --- a/tools/bin/_profile_paths.py +++ b/tools/bin/_profile_paths.py @@ -148,14 +148,11 @@ def load_all_baselines(tools_dir: Path | None = None) -> dict: if not codes: raise RuntimeError(f"No master-i18n.*.json files found in {d}.") - # Load all per-lang files per_lang: dict[str, dict] = {code: load_baseline(code, d) for code in codes} - # Use the en baseline (or first available) as the structural template primary_code = "en" if "en" in per_lang else codes[0] primary = per_lang[primary_code] - # Collect all entity names (union across all files) all_entity_names: list[str] = list(primary["entities"].keys()) for code, data in per_lang.items(): for name in data["entities"]: @@ -165,16 +162,13 @@ def load_all_baselines(tools_dir: Path | None = None) -> dict: # Build merged entities merged_entities: dict = {} for entity_name in all_entity_names: - # Gather all ids from primary baseline primary_entity = primary["entities"].get(entity_name, {"field": "", "column": "", "translations": []}) id_set = {e["id"] for e in primary_entity["translations"]} - # Index per-language rows by id lang_rows: dict[str, dict[int, str]] = {} for code, data in per_lang.items(): entity = data["entities"].get(entity_name, {}) lang_rows[code] = {e["id"]: e.get(code, "") for e in entity.get("translations", [])} - # Also collect any ids not in primary for e in entity.get("translations", []): id_set.add(e["id"]) diff --git a/tools/bin/check_changelog_integrity.py b/tools/bin/check_changelog_integrity.py index 3ba00a5..2107164 100755 --- a/tools/bin/check_changelog_integrity.py +++ b/tools/bin/check_changelog_integrity.py @@ -107,14 +107,12 @@ def find_parent_changelog(self, file_path: str) -> Optional[int]: file_path_obj = Path(file_path) dir_path = file_path_obj.parent - # First, check if directory name contains a changelog number # e.g., "03_task_types" -> 3 dir_name = dir_path.name dir_match = re.match(r"^(\d+)_", dir_name) if dir_match: return int(dir_match.group(1)) - # Look for YAML or SQL files in the same directory for ext in ["*.yaml", "*.sql"]: for parent_file in dir_path.glob(ext): if parent_file.name[0].isdigit(): @@ -122,10 +120,8 @@ def find_parent_changelog(self, file_path: str) -> Optional[int]: if num: return num - # Look in parent directory (changelog root) for matching changelog parent_dir = dir_path.parent if parent_dir == self.changelog_dir: - # We're in a subdirectory, look for changelog file in parent for ext in ["*.yaml", "*.sql"]: for parent_file in parent_dir.glob(ext): if parent_file.name[0].isdigit(): @@ -138,7 +134,6 @@ def find_parent_changelog(self, file_path: str) -> Optional[int]: def find_next_changelog(self, changelog_num: int) -> Optional[str]: """Find the next changelog file (N+1)""" next_num = changelog_num + 1 - # Format with leading zero if needed pattern = f"{next_num:02d}_*" output = self.run_git_command([ @@ -146,7 +141,6 @@ def find_next_changelog(self, changelog_num: int) -> Optional[str]: ]) files = [f for f in output.split("\n") if f] - # Return first matching file (should be only one) return files[0] if files else None def get_initial_commit(self, file_path: str) -> Optional[Tuple[str, str]]: @@ -209,16 +203,11 @@ def check_file(self, file_path: str) -> Optional[Violation]: """Check a single file for violations""" file_path_obj = Path(file_path) - # For files in subdirectories, prefer directory-based changelog number - # For files directly in changelog dir, use filename-based number if file_path_obj.parent != self.changelog_dir: - # File is in a subdirectory, check directory name first changelog_num = self.find_parent_changelog(file_path) if changelog_num is None: - # Fallback to filename changelog_num = self.get_changelog_number(file_path) else: - # File is directly in changelog directory, use filename changelog_num = self.get_changelog_number(file_path) if changelog_num is None: changelog_num = self.find_parent_changelog(file_path) @@ -226,29 +215,24 @@ def check_file(self, file_path: str) -> Optional[Violation]: if changelog_num is None: return None - # Check if file has modifications modifications = self.get_modifications(file_path) if not modifications: return None - # Find next changelog next_file = self.find_next_changelog(changelog_num) # If no next changelog, all modifications are valid if not next_file: return None - # Get next changelog's initial commit next_commit_info = self.get_initial_commit(next_file) if not next_commit_info: return None next_commit_hash, next_commit_date = next_commit_info - # Check each modification invalid_mods = [] for mod in modifications: - # If modification is NOT an ancestor of next commit, it's invalid if not self.is_ancestor(mod.commit_hash, next_commit_hash): invalid_mods.append(mod) @@ -274,7 +258,6 @@ def check_all(self) -> Tuple[List[Violation], int]: if violation: violations.append(violation) else: - # Check if file has modifications (valid ones) mods = self.get_modifications(file_path) if mods: valid_count += 1 diff --git a/tools/bin/extract_seed_data.py b/tools/bin/extract_seed_data.py index 3f1d5de..e0fd7d7 100644 --- a/tools/bin/extract_seed_data.py +++ b/tools/bin/extract_seed_data.py @@ -56,13 +56,11 @@ def read_csv(path: Path) -> list[dict[str, str]]: if not path.exists(): raise FileNotFoundError(f"Source CSV not found: {path}") with open(path, encoding="utf-8") as f: - # Handle both quoted and unquoted headers content = f.read() from io import StringIO reader = csv.DictReader(StringIO(content)) rows = [] for row in reader: - # Normalize keys to lower-case for consistent access rows.append({k.strip('"').strip().lower(): v.strip('"').strip() for k, v in row.items()}) return rows @@ -78,7 +76,6 @@ def normalize_row(row: dict[str, str]) -> dict[str, Any]: elif v.upper() in ("NULL", ""): result[k] = None else: - # Try numeric try: result[k] = int(v) except ValueError: diff --git a/tools/bin/generate_all_seed_outputs.py b/tools/bin/generate_all_seed_outputs.py index 6979128..acd1da4 100644 --- a/tools/bin/generate_all_seed_outputs.py +++ b/tools/bin/generate_all_seed_outputs.py @@ -56,7 +56,6 @@ def main() -> None: ) args = parser.parse_args() - # Resolve and validate scenarios requested = [s.strip() for s in args.scenarios.split(",") if s.strip()] unknown = [s for s in requested if s not in all_scenarios] if unknown: diff --git a/tools/bin/generate_translation_files.py b/tools/bin/generate_translation_files.py index 741c13c..5b2994e 100755 --- a/tools/bin/generate_translation_files.py +++ b/tools/bin/generate_translation_files.py @@ -69,7 +69,7 @@ def generate_translation_rows( lang_position = sorted_langs.index(lang_code) # 0-based # Collect all translatable (entity, entry_id) pairs in stable order - all_entries: list[tuple[str, int, str]] = [] # (entity_name, entry_id, column_name) + all_entries: list[tuple[str, int, str]] = [] for entity_name, entity_data in master["entities"].items(): if entity_data.get("seedDataOnly"): continue diff --git a/tools/bin/sort_codelist.py b/tools/bin/sort_codelist.py index dc31399..1af17a7 100755 --- a/tools/bin/sort_codelist.py +++ b/tools/bin/sort_codelist.py @@ -17,20 +17,16 @@ def sort_and_renumber_codelist(input_file: Path, output_file: Path = None) -> No if output_file is None: output_file = input_file - # Read all rows with open(input_file, 'r', encoding='utf-8') as f: reader = csv.DictReader(f) header = reader.fieldnames rows = list(reader) - # Sort by COD_LIST, then COD_DESCRIPTION rows.sort(key=lambda r: (r['COD_LIST'], r['COD_DESCRIPTION'])) - # Renumber COD_ID starting from 1 for idx, row in enumerate(rows, start=1): row['COD_ID'] = str(idx) - # Write sorted and renumbered data with open(output_file, 'w', encoding='utf-8', newline='') as f: writer = csv.DictWriter(f, fieldnames=header, lineterminator='\n') writer.writeheader() diff --git a/tools/bin/switch_default_language.py b/tools/bin/switch_default_language.py index 5b7c55f..8280002 100755 --- a/tools/bin/switch_default_language.py +++ b/tools/bin/switch_default_language.py @@ -100,10 +100,8 @@ def main() -> None: print(f"Dry-run: {args.dry_run}") print() - # Step 1: Update selector update_selector(baseline_code, args.dry_run) - # Step 2: Regenerate production profiles print("\nRegenerating production profiles...") regenerate_production(baseline_code, args.dry_run)