From db93568d9f8423c4fe6399562f13fa54f7c96494 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 23 Jun 2026 18:10:36 +0200 Subject: use default settings for Black --- tools/ctest-driver.py | 100 +++++++++++++++++++++--------------------- tools/project-clang-format.py | 82 +++++++++++++++++----------------- 2 files changed, 91 insertions(+), 91 deletions(-) (limited to 'tools') diff --git a/tools/ctest-driver.py b/tools/ctest-driver.py index e8e9a45..7ae059e 100755 --- a/tools/ctest-driver.py +++ b/tools/ctest-driver.py @@ -5,7 +5,7 @@ # For details, see https://github.com/egor-tensin/cmake-common. # Distributed under the MIT License. -'''Wrap your actual test driver to use with CTest +"""Wrap your actual test driver to use with CTest CTest suffers from at least two issues, in particular with regard to its PASS_REGULAR_EXPRESSION feature: @@ -14,7 +14,7 @@ PASS_REGULAR_EXPRESSION feature: 2. The exit code of a test is ignored if one of the regexes matches. This script tries to fix them. -''' +""" import argparse import os @@ -26,7 +26,7 @@ SCRIPT_NAME = os.path.basename(__file__) def dump(msg, **kwargs): - print(f'{SCRIPT_NAME}: {msg}', **kwargs) + print(f"{SCRIPT_NAME}: {msg}", **kwargs) def err(msg): @@ -34,7 +34,7 @@ def err(msg): def read_file(path): - with open(path, mode='r') as fd: + with open(path, mode="r") as fd: return fd.read() @@ -95,7 +95,7 @@ def match_pass_regexes(output, regexes): " regular expressions:" ) for regex in regexes: - err(f'\t{regex}') + err(f"\t{regex}") sys.exit(1) @@ -105,7 +105,7 @@ def match_fail_regexes(output, regexes): if match_any(output, regexes): err("Matched test program's output against some of the regular" " expressions:") for regex in regexes: - err(f'\t{regex}') + err(f"\t{regex}") sys.exit(1) @@ -137,80 +137,80 @@ def parse_args(argv=None): description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter ) - subparsers = parser.add_subparsers(dest='command') + subparsers = parser.add_subparsers(dest="command") parser_run = subparsers.add_parser( - 'run', help='run an executable and check its output' + "run", help="run an executable and check its output" ) parser_run.add_argument( - '-p', - '--pass-regex', - nargs='*', - dest='pass_regexes', - metavar='REGEX', - help='pass if all of these regexes match', + "-p", + "--pass-regex", + nargs="*", + dest="pass_regexes", + metavar="REGEX", + help="pass if all of these regexes match", ) parser_run.add_argument( - '-f', - '--fail-regex', - nargs='*', - dest='fail_regexes', - metavar='REGEX', - help='fail if any of these regexes matches', + "-f", + "--fail-regex", + nargs="*", + dest="fail_regexes", + metavar="REGEX", + help="fail if any of these regexes matches", ) parser_run.add_argument( - '-e', - '--exit-code', - nargs='*', + "-e", + "--exit-code", + nargs="*", type=int, default=[0], - dest='exit_codes', - metavar='NUM', - help='allowed exit_codes (only 0 by default)', + dest="exit_codes", + metavar="NUM", + help="allowed exit_codes (only 0 by default)", ) parser_run.add_argument( - '-n', - '--new-window', - action='store_true', - help='launch child process in a new console window', + "-n", + "--new-window", + action="store_true", + help="launch child process in a new console window", ) parser_run.add_argument( - 'exe_path', metavar='PATH', help='path to the test executable' + "exe_path", metavar="PATH", help="path to the test executable" ) # nargs='*' here would discard additional '--'s. parser_run.add_argument( - 'exe_args', - metavar='ARG', + "exe_args", + metavar="ARG", nargs=argparse.REMAINDER, - help='test executable arguments', + help="test executable arguments", ) parser_run.set_defaults(func=run_actual_test_driver) parser_grep = subparsers.add_parser( - 'grep', help='check file contents for matching patterns' + "grep", help="check file contents for matching patterns" ) parser_grep.add_argument( - '-p', - '--pass-regex', - nargs='*', - dest='pass_regexes', - metavar='REGEX', - help='pass if all of these regexes match', + "-p", + "--pass-regex", + nargs="*", + dest="pass_regexes", + metavar="REGEX", + help="pass if all of these regexes match", ) parser_grep.add_argument( - '-f', - '--fail-regex', - nargs='*', - dest='fail_regexes', - metavar='REGEX', - help='fail if any of these regexes matches', + "-f", + "--fail-regex", + nargs="*", + dest="fail_regexes", + metavar="REGEX", + help="fail if any of these regexes matches", ) - parser_grep.add_argument('path', metavar='PATH', help='text file path') + parser_grep.add_argument("path", metavar="PATH", help="text file path") parser_grep.set_defaults(func=grep_file) args = parser.parse_args(argv) if args.command is None: - parser.error('please specify a subcommand to run') + parser.error("please specify a subcommand to run") return args @@ -219,5 +219,5 @@ def main(argv=None): args.func(args) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/tools/project-clang-format.py b/tools/project-clang-format.py index 148e04c..ea89996 100755 --- a/tools/project-clang-format.py +++ b/tools/project-clang-format.py @@ -5,12 +5,12 @@ # For details, see https://github.com/egor-tensin/cmake-common. # Distributed under the MIT License. -'''clang-format all C/C++ files in the project +"""clang-format all C/C++ files in the project This script feeds every C/C++ file in the repository to clang-format, either printing a unified diff between the original and the formatted versions, or formatting the files in-place. -''' +""" import argparse from contextlib import contextmanager @@ -24,19 +24,19 @@ import sys @contextmanager def setup_logging(): level_names = { - logging.DEBUG: 'DBG', - logging.INFO: 'INFO', - logging.WARNING: 'WARN', - logging.ERROR: 'ERR', - logging.CRITICAL: 'CRIT', + logging.DEBUG: "DBG", + logging.INFO: "INFO", + logging.WARNING: "WARN", + logging.ERROR: "ERR", + logging.CRITICAL: "CRIT", } for lvl, name in level_names.items(): logging.addLevelName(lvl, name) logging.basicConfig( level=logging.INFO, - datefmt='%Y-%m-%d %H:%M:%S%z', - format='%(asctime)s | %(levelname)4s | %(message)s', + datefmt="%Y-%m-%d %H:%M:%S%z", + format="%(asctime)s | %(levelname)4s | %(message)s", ) try: yield @@ -60,7 +60,7 @@ def normalize_path(entry): def run(cmd_line): - logging.debug('Running executable: %s', cmd_line) + logging.debug("Running executable: %s", cmd_line) try: return subprocess.run( cmd_line, @@ -70,8 +70,8 @@ def run(cmd_line): stdout=subprocess.PIPE, ) except subprocess.CalledProcessError as e: - logging.error('Process finished with exit code %d: %s', e.returncode, cmd_line) - logging.error('Its output was:\n%s', e.output) + logging.error("Process finished with exit code %d: %s", e.returncode, cmd_line) + logging.error("Its output was:\n%s", e.output) raise @@ -86,10 +86,10 @@ class ClangFormat: self.style = style def _get_command_line(self, paths, in_place=False): - cmd_line = [self.path, f'-style={self.style}'] + cmd_line = [self.path, f"-style={self.style}"] if in_place: - cmd_line.append('-i') - cmd_line.append('--') + cmd_line.append("-i") + cmd_line.append("--") cmd_line += list(paths) return cmd_line @@ -103,17 +103,17 @@ class ClangFormat: # Assuming this file is ignored in .clang-format-ignore. return True - original = original.split('\n') - formatted = formatted.split('\n') - original_lbl = f'{path} (original)' - formatted_lbl = f'{path} (formatted)' + original = original.split("\n") + formatted = formatted.split("\n") + original_lbl = f"{path} (original)" + formatted_lbl = f"{path} (formatted)" diff = difflib.unified_diff( original, formatted, fromfile=original_lbl, tofile=formatted_lbl, - lineterm='', + lineterm="", ) clean = True @@ -131,17 +131,17 @@ class ClangFormat: def git_root_dir(): - cmd_line = ['git', 'rev-parse', '--show-toplevel'] + cmd_line = ["git", "rev-parse", "--show-toplevel"] root_dir = run(cmd_line).stdout - if root_dir[-1] != '\n': - raise RuntimeError('git rev-parse --show-toplevel should append a newline?') + if root_dir[-1] != "\n": + raise RuntimeError("git rev-parse --show-toplevel should append a newline?") return root_dir[:-1] def list_git_files(): - cmd_line = ['git', 'ls-tree', '-r', '-z', '--name-only', 'HEAD'] + cmd_line = ["git", "ls-tree", "-r", "-z", "--name-only", "HEAD"] repo_files = run(cmd_line).stdout - repo_files = repo_files.split('\0') + repo_files = repo_files.split("\0") return repo_files @@ -163,7 +163,7 @@ def filter_files(paths, exclude): CPP_FILE_EXTENSIONS = set( - ('.c', '.h', '.cc', '.hh', '.cpp', '.hpp', '.cxx', '.hxx', '.cp', '.c++') + (".c", ".h", ".cc", ".hh", ".cpp", ".hpp", ".cxx", ".hxx", ".cp", ".c++") ) @@ -174,8 +174,8 @@ def list_cpp_files(): yield path -DEFAULT_VERSION = 'clang-format' -DEFAULT_STYLE = 'file' +DEFAULT_VERSION = "clang-format" +DEFAULT_STYLE = "file" def process_cpp_files( @@ -200,27 +200,27 @@ def parse_args(argv=None): ) parser.add_argument( - '-b', - '--clang-format', - dest='version', + "-b", + "--clang-format", + dest="version", default=DEFAULT_VERSION, - help='clang-format executable file path', + help="clang-format executable file path", ) parser.add_argument( - '-s', - '--style', + "-s", + "--style", default=DEFAULT_STYLE, - help='clang-format -style parameter argument', + help="clang-format -style parameter argument", ) parser.add_argument( - '-i', '--in-place', action='store_true', help='edit the files in-place' + "-i", "--in-place", action="store_true", help="edit the files in-place" ) parser.add_argument( - '-e', - '--exclude', - nargs='*', + "-e", + "--exclude", + nargs="*", type=normalize_path, - help='files or directories to exclude', + help="files or directories to exclude", ) return parser.parse_args(argv) @@ -232,5 +232,5 @@ def main(argv=None): process_cpp_files(**vars(args)) -if __name__ == '__main__': +if __name__ == "__main__": main() -- cgit v1.3