Implementation:Rapidsai Cuml Include Checker
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Code_Quality |
| Last Updated | 2026-02-08 12:00 GMT |
Overview
A Python linting script that validates C/C++/CUDA include syntax consistency across the cuML codebase, enforcing correct use of angle-bracket versus quoted includes.
Description
include_checker.py scans C++ source files and validates that #include directives use the correct syntax: quoted includes (#include "...") for files that exist as relative paths, and angle-bracket includes (#include <...>) for system or installed headers.
The script performs the following checks:
- Include Style Validation -- If a quoted include references a file that does not exist relative to the source file, it flags an error recommending
#include <...>. Conversely, if an angle-bracket include references a file that does exist as a relative path, it flags an error recommending#include "...". - Pragma Once Ordering -- Verifies that
#pragma onceappears before any#includedirectives. - Relative Include Warnings -- Generates warnings for questionable relative include patterns:
- References to the current directory (
./) - Relative paths that cross top-level include directories (
src,src_prims) - Complex relative paths with more than two folders mixing parent references (
..) with named directories
- References to the current directory (
- Inplace Fix -- With the
--inplaceflag, automatically rewrites include directives to use the correct syntax.
The script uses an Issue dataclass to track errors and warnings with file location, message, and fix information. It processes files matching a configurable regex pattern (defaulting to [.](cu|cuh|h|hpp|hxx|cpp)$).
Usage
Run this script as a code quality check during development or as part of CI to ensure consistent include syntax across the C++ codebase. Use --inplace to automatically fix detected issues.
Code Reference
Source Location
- Repository: Rapidsai_Cuml
- File:
cpp/scripts/include_checker.py
Signature
def main():
def parse_args():
def check_includes_in(src, inplace, top_inc_dirs) -> typing.List[Issue]:
def list_all_source_file(file_regex, srcdirs):
def rel_include_warnings(dir, src, line_num, inc_file, top_inc_dirs) -> typing.List[Issue]:
@dataclasses.dataclass()
class Issue:
is_error: bool
msg: str
file: str
line: int
fixed_str: str = None
was_fixed: bool = False
Import
# Run from the cpp directory:
python scripts/include_checker.py [--regex PATTERN] [--inplace] [--top_include_dirs DIRS] [dirs...]
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| dirs | string(s) | Yes | Directories to scan for source files |
| --regex | string | No | cuh|h|hpp|hxx|cpp)$) |
| --inplace | flag | No | If set, automatically fix detected include issues in-place |
| --top_include_dirs | string | No | Comma-separated list of top-level include dirs (default: src,src_prims)
|
Outputs
| Name | Type | Description |
|---|---|---|
| PASSED/FAILED | stdout | Overall check result |
| Error messages | stdout | Formatted error messages with file path and line number |
| Fixed files | Modified source files | Source files with corrected includes (when --inplace is used)
|
Usage Examples
# Check all source files in the src directory
python cpp/scripts/include_checker.py cpp/src cpp/src_prims
# Check and automatically fix issues
python cpp/scripts/include_checker.py --inplace cpp/src
# Check only header files
python cpp/scripts/include_checker.py --regex "[.](h|hpp)$" cpp/src