From 0a7ee32b56f49de1c55c30cb3b8bd7af5201f0aa Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Tue, 20 Aug 2024 14:52:32 +0200 Subject: [PATCH 1/4] add pre-commit hook --- .pre-commit-config.yaml | 28 +++++++++++++++ ruff.toml | 76 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..39615d7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: debug-statements + stages: [ commit ] + - id: end-of-file-fixer + stages: [ commit ] + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.6.1 + hooks: + # Run the linter. + - id: ruff + + # Run the formatter. + - id: ruff-format + args: ["--check"] + + - repo: local + hooks: + - id: pytest-check + name: pytest-check + entry: pytest scrunch/tests + language: python + pass_filenames: false + always_run: true + types: [python] diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..1fca1a1 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,76 @@ +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +# Same as Black. +line-length = 88 +indent-width = 4 + +target-version = "py311" + +[lint] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or +# McCabe complexity (`C901`) by default. +select = ["E4", "E7", "E9", "F"] +ignore = [] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" + +# Enable auto-formatting of code examples in docstrings. Markdown, +# reStructuredText code/literal blocks and doctests are all supported. +# +# This is currently disabled by default, but it is planned for this +# to be opt-out in the future. +docstring-code-format = false + +# Set the line length limit used when formatting code snippets in +# docstrings. +# +# This only has an effect when the `docstring-code-format` setting is +# enabled. +docstring-code-line-length = "dynamic" From 529228b3da7670602e6dcf96df649eb05c7f953d Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Tue, 20 Aug 2024 15:08:05 +0200 Subject: [PATCH 2/4] fix pre-commit hook configuration --- .coveragerc | 6 ------ .gitignore | 1 + .pre-commit-config.yaml | 1 - ruff.toml | 4 +++- 4 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 9e2afda..0000000 --- a/.coveragerc +++ /dev/null @@ -1,6 +0,0 @@ -[run] -omit = scrunch/tests/* - - -[report] -show_missing = True \ No newline at end of file diff --git a/.gitignore b/.gitignore index bc0bc31..43fa795 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ pip-delete-this-directory.txt htmlcov/ .tox/ .coverage +.coveragerc .coverage.* .cache nosetests.xml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 39615d7..8141159 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,6 @@ repos: hooks: # Run the linter. - id: ruff - # Run the formatter. - id: ruff-format args: ["--check"] diff --git a/ruff.toml b/ruff.toml index 1fca1a1..7ccae34 100644 --- a/ruff.toml +++ b/ruff.toml @@ -26,6 +26,8 @@ exclude = [ "node_modules", "site-packages", "venv", + "COPYING", + "COPYING.LESSER" ] # Same as Black. @@ -38,7 +40,7 @@ target-version = "py311" # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or # McCabe complexity (`C901`) by default. -select = ["E4", "E7", "E9", "F"] +select = ["E4", "E7", "E9", "F", "I"] ignore = [] # Allow fix for all enabled rules (when `--fix`) is provided. From a12ac1477936608d4b174c06d1231bd16e1b3079 Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Tue, 20 Aug 2024 15:09:14 +0200 Subject: [PATCH 3/4] add pytest check only on push --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8141159..7ea283f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,7 @@ repos: - repo: local hooks: - id: pytest-check + stages: [ push ] name: pytest-check entry: pytest scrunch/tests language: python From 1153ae6dc54ede7c6e80e5ae7490994e01521934 Mon Sep 17 00:00:00 2001 From: Alessio Izzo Date: Wed, 21 Aug 2024 10:52:51 +0200 Subject: [PATCH 4/4] use black for format: ruff breaks py2 compat --- .pre-commit-config.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ea283f..bfeb94f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,9 +12,11 @@ repos: hooks: # Run the linter. - id: ruff - # Run the formatter. - - id: ruff-format - args: ["--check"] + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.8.0 + hooks: + - id: black - repo: local hooks: