Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gersemi to format CMake files #265

Merged
merged 7 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
23 changes: 23 additions & 0 deletions wpiformat/wpiformat/cmakeformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""This task runs gersemi on CMakeLists.txt files."""
Gold856 marked this conversation as resolved.
Show resolved Hide resolved

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")
Gold856 marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def run_batch(config_file, names):
try:
args = [sys.executable, "-m", "gersemi", "-l", "150", "-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
Loading