From adbd077b159f38ca9859f4b084af763733e7baa3 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 11 Jan 2026 20:37:34 +0000 Subject: [PATCH] Minor alignment of CLI formatting commands (#25946) --- lib/python/qmk/cli/format/c.py | 10 ++-------- lib/python/qmk/cli/format/python.py | 2 +- lib/python/qmk/path.py | 6 ++++++ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/python/qmk/cli/format/c.py b/lib/python/qmk/cli/format/c.py index 65818155b0f..4f1c0e2b2c1 100644 --- a/lib/python/qmk/cli/format/c.py +++ b/lib/python/qmk/cli/format/c.py @@ -6,7 +6,7 @@ from subprocess import CalledProcessError, DEVNULL, Popen, PIPE from argcomplete.completers import FilesCompleter from milc import cli -from qmk.path import normpath +from qmk.path import normpath, is_relative_to from qmk.c_parse import c_source_files c_file_suffixes = ('c', 'h', 'cpp', 'hpp') @@ -14,12 +14,6 @@ core_dirs = ('drivers', 'quantum', 'tests', 'tmk_core', 'platforms', 'modules') ignored = ('tmk_core/protocol/usb_hid', 'platforms/chibios/boards') -def is_relative_to(file, other): - """Provide similar behavior to PurePath.is_relative_to in Python > 3.9 - """ - return str(normpath(file).resolve()).startswith(str(normpath(other).resolve())) - - def find_clang_format(): """Returns the path to clang-format. """ @@ -105,7 +99,7 @@ def format_c(cli): if not files: cli.log.error('No C files in filelist: %s', ', '.join(map(str, cli.args.files))) - exit(0) + return False if cli.args.all_files: cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files))) diff --git a/lib/python/qmk/cli/format/python.py b/lib/python/qmk/cli/format/python.py index e7b545109f2..a455ce50c2d 100755 --- a/lib/python/qmk/cli/format/python.py +++ b/lib/python/qmk/cli/format/python.py @@ -47,7 +47,7 @@ def format_python(cli): if not files: cli.log.error('No Python files in filelist: %s', ', '.join(map(str, cli.args.files))) - exit(0) + return False if cli.args.all_files: cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files))) diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py index 1739689adff..542ba260892 100644 --- a/lib/python/qmk/path.py +++ b/lib/python/qmk/path.py @@ -144,6 +144,12 @@ def normpath(path): return Path(os.environ['ORIG_CWD']) / path +def is_relative_to(file, other): + """Provide normpath behavior to Path.is_relative_to + """ + return normpath(file).is_relative_to(normpath(other)) + + def unix_style_path(path): """Converts a Windows-style path with drive letter to a Unix path.