From 2a174b25437ac7bbe763d790d231ecd04bbe2168 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Thu, 2 May 2024 19:11:02 +0200 Subject: [PATCH] CONTRIBUTING: introduce pre-commit (#2479) --- .pre-commit-config.yaml | 14 ++++++++++++++ CONTRIBUTING.md | 11 +++++++++++ dev-requirements.txt | 2 ++ 3 files changed, 27 insertions(+) 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..cbdffe129b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +repos: + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.3.0 + hooks: + - id: black + language_version: python3.11 + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + - repo: https://github.com/pycqa/flake8 + rev: '6.1.0' + hooks: + - id: flake8 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3c4bae0f47..3de25a4e67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,6 +70,17 @@ An easier way to do so is: 1. Run `.tox/lint-some-package/bin/black .` 2. Run `.tox/lint-some-package/bin/isort .` +Or you can call formatting and linting in one command by [pre-commit](https://pre-commit.com/): + +```console +$ pre-commit +``` + +You can also configure it to run lint tools automatically before committing with: + +```console +$ pre-commit install + See [`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/tox.ini) for more detail on available tox commands. diff --git a/dev-requirements.txt b/dev-requirements.txt index 1c49c57b7e..be65b731c7 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -17,3 +17,5 @@ codespell==2.1.0 requests==2.31.0 ruamel.yaml==0.17.21 flaky==3.7.0 +pre-commit==3.7.0; python_version >= '3.9' +pre-commit==3.5.0; python_version < '3.9'