diff --git a/wizard-work/spark/python_syntax_validator.py b/wizard-work/spark/python_syntax_validator.py new file mode 100644 index 0000000..4e6704e --- /dev/null +++ b/wizard-work/spark/python_syntax_validator.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""Simple Python syntax validator - verifies Python files parse correctly.""" + +import ast +import sys +from pathlib import Path + +def validate_python_file(filepath: str) -> tuple[bool, str]: + """Validate a Python file's syntax. + + Returns: + (True, "OK") if valid syntax + (False, error_message) if invalid + """ + try: + path = Path(filepath) + source = path.read_text() + ast.parse(source, filename=str(path)) + return True, "OK" + except FileNotFoundError: + return False, f"File not found: {filepath}" + except SyntaxError as e: + return False, f"SyntaxError at line {e.lineno}: {e.msg}" + except Exception as e: + return False, f"Error: {e}" + +def main(): + if len(sys.argv) < 2: + print("Usage: python_syntax_validator.py [file2.py] ...") + sys.exit(1) + + all_valid = True + for filepath in sys.argv[1:]: + valid, msg = validate_python_file(filepath) + if valid: + print(f"VALID: {filepath}") + else: + print(f"INVALID: {filepath} - {msg}") + all_valid = False + + sys.exit(0 if all_valid else 1) + +if __name__ == "__main__": + main() \ No newline at end of file