|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Lint runner script for pytrickle project. |
| 4 | +Runs all configured linting tools with proper 4-space indentation and POSIX line endings. |
| 5 | +""" |
| 6 | + |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | + |
| 12 | +def run_command(cmd: list[str], description: str) -> bool: |
| 13 | + """Run a command and return True if successful.""" |
| 14 | + print(f"\n🔍 Running {description}...") |
| 15 | + try: |
| 16 | + result = subprocess.run(cmd, check=True, capture_output=True, text=True) |
| 17 | + print(f"✅ {description} passed") |
| 18 | + if result.stdout: |
| 19 | + print(result.stdout) |
| 20 | + return True |
| 21 | + except subprocess.CalledProcessError as e: |
| 22 | + print(f"❌ {description} failed") |
| 23 | + if e.stdout: |
| 24 | + print("STDOUT:", e.stdout) |
| 25 | + if e.stderr: |
| 26 | + print("STDERR:", e.stderr) |
| 27 | + return False |
| 28 | + |
| 29 | + |
| 30 | +def main(): |
| 31 | + """Run all linting tools.""" |
| 32 | + project_root = Path(__file__).parent |
| 33 | + python_files = ["pytrickle", "tests", "examples"] |
| 34 | + |
| 35 | + # Change to project root |
| 36 | + import os |
| 37 | + os.chdir(project_root) |
| 38 | + |
| 39 | + success = True |
| 40 | + |
| 41 | + # Run Black formatter |
| 42 | + success &= run_command( |
| 43 | + ["black", "--check", "--diff"] + python_files, |
| 44 | + "Black code formatting check" |
| 45 | + ) |
| 46 | + |
| 47 | + # Run isort import sorting |
| 48 | + success &= run_command( |
| 49 | + ["isort", "--check-only", "--diff"] + python_files, |
| 50 | + "isort import sorting check" |
| 51 | + ) |
| 52 | + |
| 53 | + # Run Ruff linter |
| 54 | + success &= run_command( |
| 55 | + ["ruff", "check"] + python_files, |
| 56 | + "Ruff linting" |
| 57 | + ) |
| 58 | + |
| 59 | + # Run Ruff formatter |
| 60 | + success &= run_command( |
| 61 | + ["ruff", "format", "--check"] + python_files, |
| 62 | + "Ruff formatting check" |
| 63 | + ) |
| 64 | + |
| 65 | + # Run MyPy type checking |
| 66 | + success &= run_command( |
| 67 | + ["mypy"] + python_files, |
| 68 | + "MyPy type checking" |
| 69 | + ) |
| 70 | + |
| 71 | + if success: |
| 72 | + print("\n🎉 All linting checks passed!") |
| 73 | + return 0 |
| 74 | + else: |
| 75 | + print("\n💥 Some linting checks failed!") |
| 76 | + return 1 |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + sys.exit(main()) |
0 commit comments