1
0

Minor alignment of CLI formatting commands (#25946)

This commit is contained in:
Joel Challis
2026-01-11 20:37:34 +00:00
committed by GitHub
parent e5d1cf0105
commit adbd077b15
3 changed files with 9 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ from subprocess import CalledProcessError, DEVNULL, Popen, PIPE
from argcomplete.completers import FilesCompleter from argcomplete.completers import FilesCompleter
from milc import cli 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 from qmk.c_parse import c_source_files
c_file_suffixes = ('c', 'h', 'cpp', 'hpp') 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') 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(): def find_clang_format():
"""Returns the path to clang-format. """Returns the path to clang-format.
""" """
@@ -105,7 +99,7 @@ def format_c(cli):
if not files: if not files:
cli.log.error('No C files in filelist: %s', ', '.join(map(str, cli.args.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: if cli.args.all_files:
cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files))) cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files)))

View File

@@ -47,7 +47,7 @@ def format_python(cli):
if not files: if not files:
cli.log.error('No Python files in filelist: %s', ', '.join(map(str, cli.args.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: if cli.args.all_files:
cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files))) cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(map(str, files)))

View File

@@ -144,6 +144,12 @@ def normpath(path):
return Path(os.environ['ORIG_CWD']) / 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): def unix_style_path(path):
"""Converts a Windows-style path with drive letter to a Unix path. """Converts a Windows-style path with drive letter to a Unix path.