mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
feat: Introduce isort and Python-based code quality tools (#446)
This commit is contained in:
33
scripts/format_code.py
Normal file
33
scripts/format_code.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Helper script to format Python code using isort and autopep8."""
|
||||
|
||||
import subprocess, sys
|
||||
|
||||
from scripts.git_utils import get_modified_python_files
|
||||
|
||||
|
||||
def format_files() -> int:
|
||||
"""Format Python files using isort and autopep8.
|
||||
|
||||
Returns:
|
||||
int: 0 on success, non-zero on failure
|
||||
"""
|
||||
try:
|
||||
# Format imports in modified files
|
||||
py_files = get_modified_python_files()
|
||||
if py_files:
|
||||
subprocess.run(['isort', *py_files], check=True)
|
||||
|
||||
# Format all files with autopep8
|
||||
subprocess.run(
|
||||
['autopep8', '--recursive', '--in-place', 'src', 'tests', '--verbose'],
|
||||
check=True
|
||||
)
|
||||
return 0
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error during formatting: {e}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(format_files())
|
||||
Reference in New Issue
Block a user