Skip to content

Commit

Permalink
Allow configuration of run-clang-tidy via pyproject.toml.
Browse files Browse the repository at this point in the history
To make it easier for developers to reproducibly run it.
  • Loading branch information
csadorf committed Jul 12, 2023
1 parent 058bd31 commit 6c7d284
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ci/run_clang_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ set +u && conda activate clang_tidy && set -u

rapids-logger "Run clang-tidy"

python cpp/scripts/run-clang-tidy.py -ignore '[.]cu$|_deps|examples/kmeans/'
python cpp/scripts/run-clang-tidy.py
29 changes: 29 additions & 0 deletions cpp/scripts/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import json
import multiprocessing as mp
import shutil
from pathlib import Path

import tomli


EXPECTED_VERSION = "15.0.7"
Expand All @@ -30,6 +33,17 @@
SEPARATOR = "-" * 16


def _read_config_file(config_file):
try:
return tomli.loads(Path(config_file).read_text())["tool"]["run-clang-tidy"]
except KeyError:
return {}
except tomli.TOMLDecodeError as error:
raise RuntimeError(
f"Failed to read config file '{config_file}' due to syntax error: {error}"
)


def parse_args():
argparser = argparse.ArgumentParser("Runs clang-tidy on a project")
argparser.add_argument(
Expand Down Expand Up @@ -59,7 +73,22 @@ def parse_args():
argparser.add_argument(
"-j", type=int, default=-1, help="Number of parallel jobs to launch."
)
argparser.add_argument(
"-c", "--config", type=str, help="Path to config file (default=pyproject.toml)."
)
args = argparser.parse_args()

# Read from config file.
try:
config = _read_config_file(args.config or "./pyproject.toml")
except FileNotFoundError:
if args.config:
# only raise if config argument was explicitly used
raise RuntimeError(f"File '{args.config}' does not exist.")
else:
argparser.set_defaults(**config)
args = argparser.parse_args()

if args.j <= 0:
args.j = mp.cpu_count()
args.ignore_compiled = re.compile(args.ignore) if args.ignore else None
Expand Down
1 change: 1 addition & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies:
- clang==15.0.7
- clang-tools==15.0.7
- ninja
- tomli
common_build:
common:
- output_types: [conda, requirements, pyproject]
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ quiet-level = 3
# TODO: Re-enable E501 with a reasonable line length
max-line-length = 999
ignore = ['E501']


[tool.run-clang-tidy]
ignore = "[.]cu$|_deps|examples/kmeans/"

0 comments on commit 6c7d284

Please sign in to comment.