From 048bdd73f59726f40a4f7343289ed5aa64c2c820 Mon Sep 17 00:00:00 2001 From: Varun Sharma Date: Thu, 7 Jul 2022 17:22:03 -0700 Subject: [PATCH] Add pre-commit --- .pre-commit-config.yaml | 21 +++++++++++++++++++++ CONTRIBUTING.rst | 3 ++- Dockerfile | 1 + docs/dependencies.rst | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..2768403b4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + # Python hooks + - repo: https://github.com/psf/black + rev: 22.3.0 + hooks: + - id: black + # C++ hooks + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v13.0.0 + hooks: + - id: clang-format + # general hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-added-large-files + - id: pretty-format-json + args: [--autofix] + - id: check-merge-conflict + - id: trailing-whitespace + - id: end-of-file-fixer diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6952de94a..1908099e9 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -79,5 +79,6 @@ Here is an example Signed-off-by line which indicates that the contributor accep Style Guide ----------- -Please run clang-format, clang-tidy and cpplint on your requests prior to submitting them. +``pre-commit`` is used to enforce style and is included in the development container. +Install it with ``pre-commit install`` to configure the pre-commit hook. Add tests to validate your changes. diff --git a/Dockerfile b/Dockerfile index 67606db4a..6e19a909f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -560,6 +560,7 @@ RUN apt-get update \ black \ cpplint \ cmakelang \ + pre-commit \ # install opencv opencv-python-headless \ # install benchmarking dependencies diff --git a/docs/dependencies.rst b/docs/dependencies.rst index 9dbe91bc6..6e6c288ad 100644 --- a/docs/dependencies.rst +++ b/docs/dependencies.rst @@ -122,6 +122,7 @@ The following packages (and any dependencies) are installed from the Python Pack :pypipackages:`numpy`,latest,BSD-3,Scientific computing package for Python\ :superscript:`d 0` :pypipackages:`opencv-python-headless`,latest,MIT,Python bindings for OpenCV\ :superscript:`d 0` :pypipackages:`pip`,latest,MIT,Python package installer\ :superscript:`d 0` + :pypipackages:`pre-commit`,latest,MIT,Pre-commit hook framework\ :superscript:`d 0` :pypipackages:`pybind11_mkdoc`,latest,MIT,Used to extract function documentation for Python binding\ :superscript:`d 0` :pypipackages:`pybind11-stubgen`,latest,BSD-3,Used to generate type stubs for Python binding\ :superscript:`d 0` :pypipackages:`pytest`,latest,MIT,Python testing infrastructure\ :superscript:`d 0`