From 218da982919f5df7222eb95063ff4b19b9a8091c Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:17:34 -0500 Subject: [PATCH 1/7] Add gersemi to format CMake files --- wpiformat/pyproject.toml | 3 ++- wpiformat/wpiformat/__init__.py | 2 ++ wpiformat/wpiformat/cmakeformat.py | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 wpiformat/wpiformat/cmakeformat.py diff --git a/wpiformat/pyproject.toml b/wpiformat/pyproject.toml index 3337de4..30fb863 100644 --- a/wpiformat/pyproject.toml +++ b/wpiformat/pyproject.toml @@ -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", diff --git a/wpiformat/wpiformat/__init__.py b/wpiformat/wpiformat/__init__.py index f84b6fe..7cd8d05 100644 --- a/wpiformat/wpiformat/__init__.py +++ b/wpiformat/wpiformat/__init__.py @@ -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 @@ -483,6 +484,7 @@ def main(): task_pipeline = [ BraceComment(), CIdentList(), + CMakeFormat(), EofNewline(), GTestName(), IncludeGuard(), diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py new file mode 100644 index 0000000..4d708c2 --- /dev/null +++ b/wpiformat/wpiformat/cmakeformat.py @@ -0,0 +1,23 @@ +"""This task runs gersemi on CMakeLists.txt 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") + + @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 From 07f0d21909cfa50c303f825f60cb21aa2342a56a Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:25:00 -0500 Subject: [PATCH 2/7] Check for .cmake extension --- wpiformat/wpiformat/cmakeformat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py index 4d708c2..51a2277 100644 --- a/wpiformat/wpiformat/cmakeformat.py +++ b/wpiformat/wpiformat/cmakeformat.py @@ -9,7 +9,7 @@ class CMakeFormat(Task): @staticmethod def should_process_file(config_file, name): - return name.endswith("CMakeLists.txt") + return name.endswith("CMakeLists.txt") or name.endswith(".cmake") @staticmethod def run_batch(config_file, names): From 28fc72a8983bfa690eec08831aba4d5fb16ce838 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:25:48 -0500 Subject: [PATCH 3/7] Format --- wpiformat/wpiformat/cmakeformat.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py index 51a2277..698ee1b 100644 --- a/wpiformat/wpiformat/cmakeformat.py +++ b/wpiformat/wpiformat/cmakeformat.py @@ -17,7 +17,6 @@ def run_batch(config_file, names): 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) + print("Error: gersemi not found in PATH. Is it installed?", file=sys.stderr) return False return True From c979fca9fff9f80f38d1c165e9d93e1aff7a9f9c Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 28 Nov 2023 23:46:15 -0500 Subject: [PATCH 4/7] Remove line length option --- wpiformat/wpiformat/cmakeformat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py index 698ee1b..fd37ce4 100644 --- a/wpiformat/wpiformat/cmakeformat.py +++ b/wpiformat/wpiformat/cmakeformat.py @@ -14,7 +14,7 @@ def should_process_file(config_file, name): @staticmethod def run_batch(config_file, names): try: - args = [sys.executable, "-m", "gersemi", "-l", "150", "-i", "."] + 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) From 956c89081705ff9791ebe33b5b179b3647a67b8a Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Wed, 29 Nov 2023 01:40:13 -0500 Subject: [PATCH 5/7] Change CMake formatter description Co-authored-by: Tyler Veness --- wpiformat/wpiformat/cmakeformat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py index fd37ce4..2de636f 100644 --- a/wpiformat/wpiformat/cmakeformat.py +++ b/wpiformat/wpiformat/cmakeformat.py @@ -1,4 +1,4 @@ -"""This task runs gersemi on CMakeLists.txt files.""" +"""This task runs gersemi on CMake files.""" import subprocess import sys From fcd8316c9a755b76696728a7f7df0a0c5751df7c Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:56:56 -0500 Subject: [PATCH 6/7] Explicitly list all folders --- wpiformat/wpiformat/cmakeformat.py | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py index 2de636f..76ba183 100644 --- a/wpiformat/wpiformat/cmakeformat.py +++ b/wpiformat/wpiformat/cmakeformat.py @@ -14,7 +14,38 @@ def should_process_file(config_file, name): @staticmethod def run_batch(config_file, names): try: - args = [sys.executable, "-m", "gersemi", "-i", "."] + args = [ + sys.executable, + "-m", + "gersemi", + "-i", + "apriltag", + "cameraserver", + "cmake/modules", + "cmake/scripts", + "cscore", + "datalogtool", + "fieldImages", + "hal", + "imgui", + "ntcore", + "outlineviewer", + "roborioteamnumbersetter", + "romiVendordep", + "simulation", + "sysid", + "wpigui", + "wpilibc", + "wpilibcExamples", + "wpilibj", + "wpilibNewCommands", + "wpimath", + "wpinet", + "wpiunits", + "wpiutil", + "xrpVendordep", + "CMakeLists.txt", + ] returncode = subprocess.run(args + names).returncode except FileNotFoundError: print("Error: gersemi not found in PATH. Is it installed?", file=sys.stderr) From 8a682d89e08fa7c961f6a8129a6c7027f985dec5 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:56:07 -0500 Subject: [PATCH 7/7] Remove explicit directory names --- wpiformat/wpiformat/cmakeformat.py | 33 +----------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/wpiformat/wpiformat/cmakeformat.py b/wpiformat/wpiformat/cmakeformat.py index 76ba183..b490c70 100644 --- a/wpiformat/wpiformat/cmakeformat.py +++ b/wpiformat/wpiformat/cmakeformat.py @@ -14,38 +14,7 @@ def should_process_file(config_file, name): @staticmethod def run_batch(config_file, names): try: - args = [ - sys.executable, - "-m", - "gersemi", - "-i", - "apriltag", - "cameraserver", - "cmake/modules", - "cmake/scripts", - "cscore", - "datalogtool", - "fieldImages", - "hal", - "imgui", - "ntcore", - "outlineviewer", - "roborioteamnumbersetter", - "romiVendordep", - "simulation", - "sysid", - "wpigui", - "wpilibc", - "wpilibcExamples", - "wpilibj", - "wpilibNewCommands", - "wpimath", - "wpinet", - "wpiunits", - "wpiutil", - "xrpVendordep", - "CMakeLists.txt", - ] + 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)