#!/usr/bin/env python3 """Validate ICE-NET repository layout constraints without third-party modules.""" from __future__ import annotations import pathlib import re import sys ROOT = pathlib.Path(__file__).resolve().parents[2] TEXT_EXT = {'.md', '.rs', '.slint', '.toml', '.py', '.yml', '.yaml', '.sh', '.json', '.txt'} def check() -> list[str]: """Return all layout violations, including forbidden tests inside source files.""" errors: list[str] = [] for folder in sorted(p for p in ROOT.rglob('*') if p.is_dir()): if any(part in {'target', '.git', '__pycache__'} for part in folder.parts): continue direct_files = [p for p in folder.iterdir() if p.is_file()] # Cargo.lock and OS/editor metadata are generated or ecosystem files. counted = [p for p in direct_files if p.name not in {'Cargo.lock', '.gitignore', '.DS_Store'}] if len(counted) > 4: errors.append(f'{folder.relative_to(ROOT)}: {len(counted)} source files, max 4') for path in sorted(p for p in ROOT.rglob('*') if p.is_file()): if any(part in {'target', '.git', '__pycache__'} for part in path.parts): continue if path.suffix not in TEXT_EXT and path.name != '.gitignore': continue # Verbatim license texts are not authored files; keep them unmodified. if 'LICENSES' in path.relative_to(ROOT).parts: continue try: body = path.read_text(encoding='utf8') except UnicodeError: errors.append(f'{path.relative_to(ROOT)}: not UTF-8') continue lines = len(body.splitlines()) if lines > 250: errors.append(f'{path.relative_to(ROOT)}: {lines} lines, max 250') if path.suffix == '.rs' and '/src/' in path.as_posix(): if re.search(r'#\s*\[\s*cfg\s*\(\s*test\s*\)\s*\]', body): errors.append(f'{path.relative_to(ROOT)}: inline tests are forbidden') return errors if __name__ == '__main__': errors = check() if errors: print('\n'.join('ERROR: ' + error for error in errors), file=sys.stderr) raise SystemExit(1) print('PASS: text <=250 lines, <=4 owned files/directory (lock excluded), external tests')