Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tools/bin/_profile_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand All @@ -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"])

Expand Down
17 changes: 0 additions & 17 deletions tools/bin/check_changelog_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,21 @@ 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():
num = self.get_changelog_number(str(parent_file))
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():
Expand All @@ -138,15 +134,13 @@ 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([
"ls-files", f"{self.changelog_dir}/{pattern}"
])

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]]:
Expand Down Expand Up @@ -209,46 +203,36 @@ 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)

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)

Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tools/bin/extract_seed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion tools/bin/generate_all_seed_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/bin/generate_translation_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions tools/bin/sort_codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions tools/bin/switch_default_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading