Skip to content

Instantly share code, notes, and snippets.

@odinokov
Last active August 26, 2024 03:52
Show Gist options
  • Save odinokov/405101030f86edbe858b6c672ea457d9 to your computer and use it in GitHub Desktop.
Save odinokov/405101030f86edbe858b6c672ea457d9 to your computer and use it in GitHub Desktop.
The series of commands and the YAML configuration sets up a pre-commit hook environment in a Python project
pip install --user ruff black isort pre-commit codespell
echo 'repos:
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args:
- "--profile=black" # Optional: Ensures isort uses the same formatting style as Black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format # Ensure this hook id exists
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
- id: check-json
- id: check-ast
- id: check-executables-have-shebangs
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ["--skip=.git", "--ignore-words-list=quiet,import"]' > .pre-commit-config.yaml
pre-commit autoupdate
# This command installs the `pre-commit` hook into your Git repository,
# ensuring that `isort`, `black`,`ruff` and `codespell` are automatically run before each commit.
pre-commit install
pre-commit run --all-files
# pre-commit clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment