devops.cpp

Package defining C++ check rules.

devops.cpp.add_license_header(file, header_to_add, *, dry_run=False)[source]

Add the license header to the file content if it’s missing.

Parameters:
  • file (str | Path) – The path to the file to modify.

  • header_to_add (str | Path) – The path to the file containing the license header to add.

  • dry_run (bool) – If True, do not modify the file, only simulate the addition.

Returns:

bool – True if the license header was added, False if it was already present.

Raises:

DevOpsFileNotFoundError – If the header file does not exist.

Return type:

bool

devops.cpp.build_cpp_rules(config=CppConfig(style_checks=True, license_header_check=True, license_header=None, check_only_staged_files=False, check_dirs=[], exclude_dirs=[], header_guards_according_to_filepath=False, header_guard_pattern=None, ast_checks=True, ast_check_compile_args=['-std=c++23'], ast_check_compile_commands_db=None, ast_check_enabled_ids=[], ast_check_disabled_ids=[], ast_check_config={}, forbidden_spellings={}, incremental_state_file=None, fail_fast=True, parallel_jobs=1))[source]

Build and return the list of C++ rules based on the global configuration.

Parameters:

config (CppConfig) – The global C++ configuration.

Returns:

list[Rule] – The list of C++ rules.

Return type:

list[Rule]

devops.cpp.filter_buggy_cpp(files)[source]

Filter out known buggy C++ header files from a list of files.

Parameters:

files (list[str]) – The list of file paths to filter.

Returns:

list[str] – The filtered list of file paths excluding known buggy C++ headers.

Return type:

list[str]

devops.cpp.run_cpp_checks(rules, config=CppConfig(style_checks=True, license_header_check=True, license_header=None, check_only_staged_files=False, check_dirs=[], exclude_dirs=[], header_guards_according_to_filepath=False, header_guard_pattern=None, ast_checks=True, ast_check_compile_args=['-std=c++23'], ast_check_compile_commands_db=None, ast_check_enabled_ids=[], ast_check_disabled_ids=[], ast_check_config={}, forbidden_spellings={}, incremental_state_file=None, fail_fast=True, parallel_jobs=1), dirs=None, state_file=None, base_ref=None, config_file=None)[source]

Run C++ checks based on the provided rules.

By default the function returns immediately after encountering the first file with errors (fail-fast). Set config.fail_fast = False (or pass --no-fail-fast on the CLI) to check all files regardless.

When state_file is given the run is incremental: results are persisted to state_file after every checked file, and only files that are new, previously failed, or modified since the last run are re-checked. The return value is False whenever any entry in the accumulated state is failed. The state is discarded whenever config_file changed since it was written.

When config.parallel_jobs != 1 and an AST-checks rule is present, the libclang parse (the one CPU-bound, per-file cost) is dispatched across a process pool instead of running serially; every other rule (line/file/style rules) still runs once per file in the main process, since that work is cheap. With parallel_jobs > 1 and fail_fast enabled, the run stops scheduling further files soon after a failure is seen, rather than at the exact first failing file in listing order.

Parameters:
  • rules (list[Rule]) – The list of rules to apply.

  • config (CppConfig) – The global C++ configuration.

  • dirs (list[Path] | None) – If given, only files under these directories are checked.

  • state_file (Path | None) – Path to the JSON state file used for incremental runs. When None (the default) no state is read or written and the classic fail-fast behavior is used.

  • base_ref (str | None) – A git commit hash or branch name. When given, only files changed relative to it (see get_changed_files) are checked, overriding check_only_staged_files. The changed files are still further restricted to config.check_dirs (if set) and, when given, to dirs, which takes precedence over config.check_dirs.

  • config_file (Path | None) – The TOML config file in use. Its content hash is stored in the state file; when it differs on the next run, all incremental state is invalidated and every file is re-checked.

Raises:
  • CppCheckError – If invalid (non-file or non-line) rules are provided.

  • GitRefError – If base_ref cannot be resolved.

Returns:

bool – True if all checks pass, False if any check fails.

Return type:

bool

Modules

ast

AST-based (libclang) C++ checks for devops.

buggy_cpp_files

Module for filtering known buggy C++ header files.

build_rules

Module to build C++ rules based on global configuration.

checks

C++ checks module.

cpp_only_include_scan

Plain-text scanning for cpp-only header violations.

forbidden_spellings

File-based rule flagging forbidden spellings, like a reverse dictionary.

license_header

Module to check for license headers in C++ files.

path_patterns

Shared file-path pattern matching for per-check path exceptions/exclusions.

state

State persistence for incremental C++ checks.

style_rules

C++ rules for mstd devops.