Skip to content

Commit

Permalink
Add gersemi to format CMake files (#265)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
  • Loading branch information
Gold856 and calcmogul authored Nov 30, 2023
1 parent e67e029 commit 1469a0d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion wpiformat/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ dependencies = [
"regex==2023.10.3",
"black==23.9.1",
"clang-format==17.0.5",
"clang-tidy==17.0.1"
"clang-tidy==17.0.1",
"gersemi==0.9.3"
]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down
2 changes: 2 additions & 0 deletions wpiformat/wpiformat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from wpiformat.cidentlist import CIdentList
from wpiformat.clangformat import ClangFormat
from wpiformat.clangtidy import ClangTidy
from wpiformat.cmakeformat import CMakeFormat
from wpiformat.config import Config
from wpiformat.eofnewline import EofNewline
from wpiformat.gtestname import GTestName
Expand Down Expand Up @@ -483,6 +484,7 @@ def main():
task_pipeline = [
BraceComment(),
CIdentList(),
CMakeFormat(),
EofNewline(),
GTestName(),
IncludeGuard(),
Expand Down
22 changes: 22 additions & 0 deletions wpiformat/wpiformat/cmakeformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""This task runs gersemi on CMake files."""

import subprocess
import sys

from wpiformat.task import Task


class CMakeFormat(Task):
@staticmethod
def should_process_file(config_file, name):
return name.endswith("CMakeLists.txt") or name.endswith(".cmake")

@staticmethod
def run_batch(config_file, names):
try:
args = [sys.executable, "-m", "gersemi", "-i"]
returncode = subprocess.run(args + names).returncode
except FileNotFoundError:
print("Error: gersemi not found in PATH. Is it installed?", file=sys.stderr)
return False
return True

0 comments on commit 1469a0d

Please sign in to comment.