Skip to content

Commit 13ec6da

Browse files
committed
Allow file path to exclude in formatting
1 parent 40c6b72 commit 13ec6da

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/fprime/util/code_formatter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ def exclude_file(self, filepath: Path) -> None:
7979
it will be excluded to clang-format when the execute() function is called.
8080
8181
Args:
82-
filepath (str): file path to file to be excluded.
82+
filepath (str): file path to be excluded.
8383
"""
8484
if filepath in self._files_to_format:
8585
if self.verbose:
8686
print(f"[INFO] Excluding {filepath} from formatting.")
8787
self._files_to_format.remove(filepath)
88+
else:
89+
if self.verbose:
90+
print(f"[INFO] {filepath} was not staged for formatting. Skipping.")
8891

8992
def execute(
9093
self, builder: "Build", context: "Path", args: Tuple[Dict[str, str], List[str]]

src/fprime/util/commands.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,15 @@ def run_code_format(
204204
# Remove staged files that are within excluded directories
205205
for excluded_dir in parsed.exclude:
206206
excluded_path = Path(excluded_dir)
207-
if not excluded_path.is_dir():
208-
print(
209-
f"[INFO] {excluded_path} is not a directory. Skipping it from excluded directories."
210-
)
207+
if excluded_path.is_file():
208+
clang_formatter.exclude_file(excluded_path)
209+
elif excluded_path.is_dir():
210+
for allowed_ext in clang_formatter.allowed_extensions:
211+
for file in excluded_path.rglob(f"*{allowed_ext}"):
212+
clang_formatter.exclude_file(file)
213+
else:
214+
print(f"[INFO] {excluded_path} is not a valid path. Skipping.")
211215
continue
212-
for allowed_ext in clang_formatter.allowed_extensions:
213-
for file in excluded_path.rglob(f"*{allowed_ext}"):
214-
clang_formatter.exclude_file(file)
215216

216217
return clang_formatter.execute(build, parsed.path, ({}, parsed.pass_through))
217218

0 commit comments

Comments
 (0)