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

Conversation

bdice
Copy link
Contributor

@bdice bdice commented Jan 4, 2023

Description

This PR adopts pre-commit for style checks in rapids-cmake. In addition to cmake-format and cmake-lint, this will help with frequently encountered PR review notes, like formatting C++ code, standardizing copyright notices, and catching typos via codespell.

For now, codespell and whitespace linting are disabled to reduce PR size.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.
  • The cmake-format.json is up to date with these changes.
  • I have added new files under rapids-cmake/
    • I have added include guards (include_guard(GLOBAL))
    • I have added the associated docs/ rst file and update the api.rst

Comment on lines +47 to +48
for cmake_file in "${@:2}"; do
cmake-format --in-place --first-comment-is-literal --config-files ${RAPIDS_CMAKE_FORMAT_FILE} ${RAPIDS_CMAKE_ROOT}/ci/checks/cmake_config_format.json -- ${cmake_file}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vyasr I tried passing cmake-format ... -- ${@:2} like we do in cudf, but for some reason, it seems that cmake-format only respects the config files for the first input and not for later files.

I played with this locally and this appears to reproduce the failure:

# One file is fine
cmake-format --in-place --first-comment-is-literal --config-files cmake-format-rapids-cmake.json ci/checks/cmake_config_format.json -- rapids-cmake/rapids-cpm.cmake

# For multiple files, only the first file respects the configs
cmake-format --in-place --first-comment-is-literal --config-files cmake-format-rapids-cmake.json ci/checks/cmake_config_format.json -- rapids-cmake/rapids-cpm.cmake rapids-cmake/rapids-cuda.cmake

This seems like a manifestation of https://github.com/cheshirekow/cmake_format/issues/284 because we're using --first-comment-is-literal in this repo but not in cudf, which handles multiple files just fine. If you have any further insight, feel free to share.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have not seen this before either. Your diagnosis seems reasonable, though, and as you say below switching to a direct invocation should bypass the issue.


# Copyright (c) 2021-2023, NVIDIA CORPORATION.

# This script is a wrapper for cmakelang that may be used with pre-commit. The
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we use the upstream pre-commit hook (https://github.com/cheshirekow/cmake-format-precommit) instead of copying the run-cmake-format.sh file, since this repo contains the original config file and it doesn't need to be fetched?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am happy to defer this to a follow up PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should switch, yes. The fetch was the only reason I implemented the script in the first place. Hopefully switching to the hook will also address the issue you observed with --first-comment-is-literal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I attempted to switch to the official pre-commit hook, but failed. There is no option to require pre-commit to run one file at a time, so the use of --first-comment-is-literal means we always run into the bug mentioned above. We have to use an intermediate shell script to split the work and execute cmake-format on individual files, so I guess we're stuck with using run-cmake-format.sh.

@bdice bdice added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Jan 4, 2023
@bdice bdice self-assigned this Jan 4, 2023
@bdice bdice marked this pull request as ready for review January 4, 2023 19:56
@bdice bdice requested review from a team as code owners January 4, 2023 19:56

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?

@bdice
Copy link
Contributor Author

bdice commented Jan 4, 2023

/merge

@rapids-bot rapids-bot bot merged commit 9ee2450 into rapidsai:branch-23.02 Jan 4, 2023
ajschmidt8 pushed a commit to ajschmidt8/rapids-cmake that referenced this pull request Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants