Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pre-commit for style checks #336

Merged
merged 16 commits into from
Jan 4, 2023
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
71 changes: 71 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2023, NVIDIA CORPORATION.

repos:
#- repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v4.4.0
# hooks:
# - id: trailing-whitespace
# exclude: |
# (?x)^(
# ^rapids-cmake/cpm/patches/.*
# )
# - id: end-of-file-fixer
# exclude: |
# (?x)^(
# ^rapids-cmake/cpm/patches/.*
# )
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v11.1.0
hooks:
- id: clang-format
types_or: [c, c++, cuda]
args: ["-fallback-style=none", "-style=file", "-i"]
#- repo: https://github.com/codespell-project/codespell
# rev: v2.2.2
# hooks:
# - id: codespell
# exclude: |
# (?x)^(
# ^CHANGELOG.md$
# )
- repo: local
hooks:
- id: copyright-check
name: copyright-check
entry: python ./ci/checks/copyright.py --git-modified-only --update-current-year
language: python
pass_filenames: false
additional_dependencies: [gitpython]
- id: cmake-format
name: cmake-format
entry: ./ci/checks/run-cmake-format.sh cmake-format
language: python
types: [cmake]
# Note that pre-commit autoupdate does not update the versions
# of dependencies, so we'll have to update this manually.
additional_dependencies:
- cmakelang==0.6.13
verbose: true
require_serial: true
files: |
(?x)^(
^rapids-cmake/.*$
)
- id: cmake-lint
name: cmake-lint
entry: ./ci/checks/run-cmake-format.sh cmake-lint
language: python
types: [cmake]
# Note that pre-commit autoupdate does not update the versions
# of dependencies, so we'll have to update this manually.
additional_dependencies:
- cmakelang==0.6.13
verbose: true
require_serial: true
files: |
(?x)^(
^rapids-cmake/.*$
)

default_language_version:
python: python3
61 changes: 4 additions & 57 deletions ci/check_style.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

set -euo pipefail

Expand All @@ -13,62 +13,9 @@ rapids-dependency-file-generator \

rapids-mamba-retry env create --force -f env.yaml -n checks

set +eu
set +u
conda activate checks
set -u


CMAKE_FILES=(`find rapids-cmake/ | grep -E "^.*\.cmake?$|^.*/CMakeLists.txt$"`)
CMAKE_FILES+=("CMakeLists.txt")

CMAKE_FORMATS=()
CMAKE_FORMAT_RETVAL=0

CMAKE_LINTS=()
CMAKE_LINT_RETVAL=0

for cmake_file in "${CMAKE_FILES[@]}"; do
cmake-format --in-place --first-comment-is-literal --config-files ./cmake-format-rapids-cmake.json ./ci/checks/cmake_config_format.json -- ${cmake_file}
TMP_CMAKE_FORMAT=`git diff --color --exit-code -- ${cmake_file}`
TMP_CMAKE_FORMAT_RETVAL=$?
if [ "$TMP_CMAKE_FORMAT_RETVAL" != "0" ]; then
CMAKE_FORMAT_RETVAL=1
CMAKE_FORMATS+=("$TMP_CMAKE_FORMAT")
fi

TMP_CMAKE_LINT=`cmake-lint --config-files ./cmake-format-rapids-cmake.json ./ci/checks/cmake_config_format.json ./ci/checks/cmake_config_lint.json -- ${cmake_file}`
TMP_CMAKE_LINT_RETVAL=$?
if [ "$TMP_CMAKE_LINT_RETVAL" != "0" ]; then
CMAKE_LINT_RETVAL=1
CMAKE_LINTS+=("$TMP_CMAKE_LINT")
fi
done

# Output results if failure otherwise show pass
if [ "$CMAKE_FORMAT_RETVAL" != "0" ]; then
echo -e "\n\n>>>> FAILED: cmake format check; begin output\n\n"
for CMAKE_FORMAT in "${CMAKE_FORMATS[@]}"; do
echo -e "$CMAKE_FORMAT"
echo -e "\n"
done
echo -e "\n\n>>>> FAILED: cmake format check; end output\n\n"
else
echo -e "\n\n>>>> PASSED: cmake format check\n\n"
fi

if [ "$CMAKE_LINT_RETVAL" != "0" ]; then
echo -e "\n\n>>>> FAILED: cmake lint check; begin output\n\n"
for CMAKE_LINT in "${CMAKE_LINTS[@]}"; do
echo -e "$CMAKE_LINT"
echo -e "\n"
done
echo -e "\n\n>>>> FAILED: cmake lint check; end output\n\n"
else
echo -e "\n\n>>>> PASSED: cmake lint check\n\n"
fi

RETVALS=($CMAKE_FORMAT_RETVAL $CMAKE_LINT_RETVAL)
IFS=$'\n'
RETVAL=`echo "${RETVALS[*]}" | sort -nr | head -n1`

exit $RETVAL
# Run pre-commit checks
pre-commit run --all-files --show-diff-on-failure
Copy link
Member

@ajschmidt8 ajschmidt8 Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't make a suggestion for this via the web interface, but can you remove the +e on line 16 of this file?

Loading