Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

## Next Release

### API

- Add `dirs` argument to `cpp_checks` cli

### Bug Fixes

#### Config

- generated default .toml file contains now key `license_header`

<!-- insertion marker -->
## [0.0.1](https://github.com/repo/owner/releases/tag/0.0.1) - 2025-12-20

Expand Down
23 changes: 0 additions & 23 deletions devops.toml.template

This file was deleted.

8 changes: 6 additions & 2 deletions src/devops/config/config_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def to_toml_lines(self) -> list[str]:
f"#license_header_check = {str(self.license_header_check).lower()}\n"
)

if self.license_header is not None:
lines.append(f'#license_header = "{self.license_header}"\n')
if self.license_header is None:
license_header = "<some file path>"
else:
license_header = f'"{self.license_header}"'

lines.append(f"#license_header = {license_header}\n")

lines.append(
f"#check_only_staged_files = {str(self.check_only_staged_files).lower()}\n"
Expand Down
11 changes: 9 additions & 2 deletions src/devops/cpp/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def run_file_rules(rules: list[Rule], file: Path) -> list[ResultType]:


def run_cpp_checks(
rules: list[Rule], config: CppConfig = __GLOBAL_CONFIG__.cpp
rules: list[Rule],
config: CppConfig = __GLOBAL_CONFIG__.cpp,
dirs: list[Path] | None = None,
) -> None:
"""Run C++ checks based on the provided rules.

Expand All @@ -126,7 +128,12 @@ def run_cpp_checks(
If invalid (non-file or non-line) rules are provided.

"""
if config.check_only_staged_files:
if dirs is not None:
cpp_check_logger.info(
f"Running checks in directories: {[str(d) for d in dirs]}"
)
files = get_files_in_dirs(dirs)
elif config.check_only_staged_files:
cpp_check_logger.info("Running checks on staged files...")
files = get_staged_files()
else:
Expand Down
16 changes: 14 additions & 2 deletions src/devops/scripts/cpp_checks.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
"""Module defining C++ check rules."""

from dataclasses import replace
from pathlib import Path

import typer

from devops import __GLOBAL_CONFIG__
from devops.cpp import build_cpp_rules, run_cpp_checks
from devops.files import filter_cpp_files, get_dirs_in_dir, get_files_in_dirs

app = typer.Typer(help="C++ code quality checks.")


@app.command()
def cpp_checks(license_header: str | None = None) -> None:
def cpp_checks(
license_header: str | None = None, dirs: list[str] | None = None
) -> None:
"""Run C++ code quality checks.

Parameters
----------
license_header: str | None
The path to the license header file. If None, uses the global configuration.
dirs: list[str] | None
List of directories to check.
If None, uses all directories in the current directory.

"""
if license_header is None:
Expand All @@ -28,5 +35,10 @@ def cpp_checks(license_header: str | None = None) -> None:
license_header=license_header,
)

dirs = get_dirs_in_dir() if dirs is None else [Path(d) for d in dirs]

files = get_files_in_dirs(dirs)
files = filter_cpp_files(files)

rules = build_cpp_rules(config)
run_cpp_checks(rules, config)
run_cpp_checks(rules, config, dirs=dirs)