From c5d5dee963a9480593201f1c5eae49d264b15ee9 Mon Sep 17 00:00:00 2001 From: Dobri Y Date: Mon, 27 Jan 2025 21:34:14 +0000 Subject: [PATCH 1/2] Add pre-commit Signed-off-by: Dobri Y --- .pre-commit-config.yaml | 14 ++++++++++++++ Developing.md | 5 +++++ docker/build/cudaq.dev.Dockerfile | 11 ++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..f71d2d99cb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v19.1.7 + hooks: + - id: clang-format + - repo: https://github.com/google/yapf + rev: v0.43.0 + hooks: + - id: yapf-diff diff --git a/Developing.md b/Developing.md index 4f0e868ac5..8685ce57c4 100644 --- a/Developing.md +++ b/Developing.md @@ -61,6 +61,11 @@ for Python. The CUDA-Q internals on the other hand follow the [MLIR/LLVM style guide][llvm_style]. Please ensure that your code includes comprehensive doc comments as well as a comment at the top of the file to indicating its purpose. +`pre-commit` is being test-flown in this repository. If you have the tool +installed or are using the provided Dev container, run `pre-commit install` to +enable the hooks. `clang-format` and `yapf` will be automatically run on all +staged changes. + [python_style]: https://google.github.io/styleguide/pyguide.html [cpp_style]: https://www.gnu.org/prep/standards/standards.html [llvm_style]: https://llvm.org/docs/CodingStandards.html diff --git a/docker/build/cudaq.dev.Dockerfile b/docker/build/cudaq.dev.Dockerfile index 749a8f6c59..a9bacdf434 100644 --- a/docker/build/cudaq.dev.Dockerfile +++ b/docker/build/cudaq.dev.Dockerfile @@ -10,9 +10,9 @@ # Build from the repo root with # docker build -t nvidia/cuda-quantum-dev:latest -f docker/build/cudaq.dev.Dockerfile . # -# If a custom base image is used, then that image (i.e. the build environment) must +# If a custom base image is used, then that image (i.e. the build environment) must # 1) have all the necessary build dependendencies installed -# 2) define the LLVM_INSTALL_PREFIX environment variable indicating where the +# 2) define the LLVM_INSTALL_PREFIX environment variable indicating where the # the LLVM binaries that CUDA-Q depends on are installed # 3) set the CC and CXX environment variable to use the same compiler toolchain # as the LLVM dependencies have been built with. @@ -41,8 +41,13 @@ RUN if [ -n "$mpi" ]; \ fi \ fi +# Install pre-commit +RUN apt-get update && apt-get install -y --no-install-recommends git \ + && python3 -m pip install --no-cache-dir pre-commit==4.1.0 \ + && apt-get autoremove -y --purge && apt-get clean && rm -rf /var/lib/apt/lists/* + # Configuring a base image that contains the necessary dependencies for GPU -# accelerated components and passing a build argument +# accelerated components and passing a build argument # install="CMAKE_BUILD_TYPE=Release CUDA_QUANTUM_VERSION=latest" # creates a dev image that can be used as argument to docker/release/cudaq.Dockerfile # to create the released cuda-quantum image. From 0801faee0c6bb4be2ebdaa4ebf5c87fc5b04cc44 Mon Sep 17 00:00:00 2001 From: Dobri Y Date: Mon, 27 Jan 2025 21:52:31 +0000 Subject: [PATCH 2/2] Fix spelling nit Signed-off-by: Dobri Y --- Developing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Developing.md b/Developing.md index 8685ce57c4..39ceb46117 100644 --- a/Developing.md +++ b/Developing.md @@ -62,7 +62,7 @@ guide][llvm_style]. Please ensure that your code includes comprehensive doc comments as well as a comment at the top of the file to indicating its purpose. `pre-commit` is being test-flown in this repository. If you have the tool -installed or are using the provided Dev container, run `pre-commit install` to +installed or are using the provided container, run `pre-commit install` to enable the hooks. `clang-format` and `yapf` will be automatically run on all staged changes.