mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2026-03-09 05:20:21 +00:00
add(format): implement formatting and format check tasks for source files
This commit is contained in:
parent
82a7efad5e
commit
fa08fcfe65
6 changed files with 164 additions and 2 deletions
103
tasks.py
103
tasks.py
|
|
@ -1,6 +1,8 @@
|
|||
from invoke import task
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
@task
|
||||
def cleanbuild(c):
|
||||
|
|
@ -41,7 +43,7 @@ def clean(c):
|
|||
c.run("idf.py fullclean")
|
||||
|
||||
|
||||
@task
|
||||
@task
|
||||
def config(c):
|
||||
"""Open menuconfig to edit project settings"""
|
||||
c.run("idf.py menuconfig --color-scheme=monochrome", pty=True)
|
||||
|
|
@ -52,11 +54,13 @@ def saveconfig(c):
|
|||
"""Save current config as sdkconfig.defaults"""
|
||||
c.run("idf.py save-defconfig")
|
||||
|
||||
|
||||
@task
|
||||
def update(c):
|
||||
"""Update project dependencies"""
|
||||
c.run("idf.py update-dependencies")
|
||||
|
||||
|
||||
@task
|
||||
def reset(c):
|
||||
"""Reset project to clean state: remove build, config, and managed components"""
|
||||
|
|
@ -68,4 +72,99 @@ def reset(c):
|
|||
shutil.rmtree("build")
|
||||
if os.path.exists("managed_components"):
|
||||
shutil.rmtree("managed_components")
|
||||
|
||||
|
||||
|
||||
@task
|
||||
def format(c):
|
||||
"""Format all source files with clang-format, black, prettier, nixfmt, and svgo"""
|
||||
missing_tools = []
|
||||
|
||||
print("Formatting C files...")
|
||||
result = c.run(
|
||||
"find main components -name '*.c' -o -name '*.h' | xargs clang-format -i",
|
||||
warn=True,
|
||||
)
|
||||
if result and not result.ok:
|
||||
missing_tools.append("clang-format")
|
||||
|
||||
print("Formatting Python files...")
|
||||
result = c.run("black tasks.py", warn=True)
|
||||
if result and not result.ok:
|
||||
missing_tools.append("black")
|
||||
|
||||
print("Formatting Nix files...")
|
||||
result = c.run("nixfmt flake.nix", warn=True)
|
||||
if result and not result.ok:
|
||||
missing_tools.append("nixfmt")
|
||||
|
||||
print("Formatting SVG files...")
|
||||
result = c.run(
|
||||
"find . -name '*.svg' -not -path './build/*' -not -path './managed_components/*' | xargs svgo",
|
||||
warn=True,
|
||||
)
|
||||
if result and not result.ok:
|
||||
missing_tools.append("svgo")
|
||||
|
||||
print("Formatting other files...")
|
||||
result = c.run("prettier --write '**/*.{js,json,yaml,yml,md,html,css}'", warn=True)
|
||||
if result and not result.ok:
|
||||
missing_tools.append("prettier")
|
||||
|
||||
if missing_tools:
|
||||
print(f"\n❌ ERROR: Missing formatting tools: {', '.join(missing_tools)}")
|
||||
print("Please install them or reload the nix-shell.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@task
|
||||
def format_check(c):
|
||||
"""Check if all files are formatted correctly"""
|
||||
missing_tools = []
|
||||
format_errors = []
|
||||
|
||||
print("Checking C file formatting...")
|
||||
result = c.run(
|
||||
"find main components -name '*.c' -o -name '*.h' | xargs clang-format --dry-run --Werror",
|
||||
warn=True,
|
||||
)
|
||||
if result:
|
||||
if result.return_code == 127: # Command not found
|
||||
missing_tools.append("clang-format")
|
||||
elif not result.ok:
|
||||
format_errors.append("C files")
|
||||
|
||||
print("Checking Python file formatting...")
|
||||
result = c.run("black --check tasks.py", warn=True)
|
||||
if result:
|
||||
if result.return_code == 127:
|
||||
missing_tools.append("black")
|
||||
elif not result.ok:
|
||||
format_errors.append("Python files")
|
||||
|
||||
print("Checking Nix file formatting...")
|
||||
result = c.run("nixfmt --check flake.nix", warn=True)
|
||||
if result:
|
||||
if result.return_code == 127:
|
||||
missing_tools.append("nixfmt")
|
||||
elif not result.ok:
|
||||
format_errors.append("Nix files")
|
||||
|
||||
print("Checking other file formatting...")
|
||||
result = c.run("prettier --check '**/*.{js,json,yaml,yml,md,html,css}'", warn=True)
|
||||
if result:
|
||||
if result.return_code == 127:
|
||||
missing_tools.append("prettier")
|
||||
elif not result.ok:
|
||||
format_errors.append("JS/JSON/YAML/HTML/CSS files")
|
||||
|
||||
if missing_tools:
|
||||
print(f"\n❌ ERROR: Missing formatting tools: {', '.join(missing_tools)}")
|
||||
print("Please install them or reload the nix-shell.")
|
||||
sys.exit(1)
|
||||
|
||||
if format_errors:
|
||||
print(f"\n❌ ERROR: Formatting issues in: {', '.join(format_errors)}")
|
||||
print("Run 'invoke format' to fix them.")
|
||||
sys.exit(1)
|
||||
|
||||
print("\n✅ All files are correctly formatted!")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue