Skip to content
Open
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
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_style = space
indent_size = 4
max_line_length = 88

[*.{yml,yaml}]
indent_style = space
indent_size = 2

[*.{json,js,ts}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: mixed-line-ending
args: ['--fix=lf']
- id: check-case-conflict

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3
args: [--line-length=88]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black, --line-length=88]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-requests]
exclude: ^(tests/|examples/)
80 changes: 80 additions & 0 deletions lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3
"""
Lint runner script for pytrickle project.
Runs all configured linting tools with proper 4-space indentation and POSIX line endings.
"""

import subprocess
import sys
from pathlib import Path


def run_command(cmd: list[str], description: str) -> bool:
"""Run a command and return True if successful."""
print(f"\n🔍 Running {description}...")
try:
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
print(f"✅ {description} passed")
if result.stdout:
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"❌ {description} failed")
if e.stdout:
print("STDOUT:", e.stdout)
if e.stderr:
print("STDERR:", e.stderr)
return False


def main():
"""Run all linting tools."""
project_root = Path(__file__).parent
python_files = ["pytrickle", "tests", "examples"]

# Change to project root
import os
os.chdir(project_root)

success = True

# Run Black formatter
success &= run_command(
["black", "--check", "--diff"] + python_files,
"Black code formatting check"
)

# Run isort import sorting
success &= run_command(
["isort", "--check-only", "--diff"] + python_files,
"isort import sorting check"
)

# Run Ruff linter
success &= run_command(
["ruff", "check"] + python_files,
"Ruff linting"
)

# Run Ruff formatter
success &= run_command(
["ruff", "format", "--check"] + python_files,
"Ruff formatting check"
)

# Run MyPy type checking
success &= run_command(
["mypy"] + python_files,
"MyPy type checking"
)

if success:
print("\n🎉 All linting checks passed!")
return 0
else:
print("\n💥 Some linting checks failed!")
return 1


if __name__ == "__main__":
sys.exit(main())