Skip to content

Commit

Permalink
setup pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Czaki committed Aug 26, 2023
1 parent 8017a8f commit a098b28
Show file tree
Hide file tree
Showing 106 changed files with 1,531 additions and 1,122 deletions.
331 changes: 35 additions & 296 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,297 +1,36 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

minimum_pre_commit_version: '2.10.0'

default_language_version:
python: python3

default_stages: [commit]


repos:
# Meta checks
- repo: meta
hooks:
- id: check-useless-excludes

# General fixers
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
name: Trim trailing whitespace
exclude_types: [svg]
- id: mixed-line-ending
name: Normalize mixed line endings
args: [--fix=lf]
exclude_types: [batch]
- id: end-of-file-fixer
name: Fix end of files
exclude_types: [svg]
- id: fix-byte-order-marker
name: Remove Unicode BOM


# More general fixers
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: remove-tabs
name: Replace tabs with spaces
types: [text]
exclude_types: [svg, batch]
args: [--whitespaces-count, '4']


# Check and fix spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
# Define separate hooks for checking and correcting spelling errors
# since codespell doesn't print verbose output when writing changes
- id: codespell
name: Check spelling
exclude: '\.codespellrc|\.gitattributes'
- id: codespell
name: Fix spelling
exclude: '\.codespellrc|\.gitattributes'
args: [--write-changes]

# Lint and fix CSS with stylelint
- repo: https://github.com/awebdeveloper/pre-commit-stylelint
rev: '0.0.2'
hooks:
- id: stylelint
name: Lint and fix CSS (stylelint)
args: [--fix, --color, --maxWarnings, '0']
additional_dependencies:
- 'stylelint@14.9.1'
- 'stylelint-config-standard@26.0.0'
- 'stylelint-csstree-validator@2.0.0'
- 'stylelint-declaration-block-no-ignored-properties@2.5.0'
- 'stylelint-no-unsupported-browser-features@5.0.3'
- 'stylelint-order@5.0.0'

# Lint CSS with CSSlint
- repo: https://github.com/pre-commit/mirrors-csslint
rev: v1.0.5
hooks:
- id: csslint
name: Check CSS (CSSlint)

# Pretty-format INI
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.4.0
hooks:
- id: pretty-format-ini
name: Format INI
types: [ini]
args: [--autofix]

# Check JSON
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-json
name: Check JSON

# Add doctoc to Markdown
- repo: https://github.com/thlorenz/doctoc
rev: v2.2.0
hooks:
- id: doctoc
name: Generate Markdown ToCs
args: [--maxlevel, '3', --update-only]

# Lint Markdown
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.1
hooks:
- id: markdownlint
name: Lint Markdown
args: [--fix]

# Format packaging
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
name: Format packaging with setup-cfg-fmt

# Check packaging
- repo: https://github.com/regebro/pyroma
rev: '3.2'
hooks:
- id: pyroma

# Fix Python
- repo: https://github.com/asottile/pyupgrade
rev: v2.24.0
hooks:
- id: pyupgrade
name: Fix Python with Pyupgrade
args: ['--py37-plus', '--keep-runtime-typing']

# Check Python
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-ast
name: Check Python

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-check-mock-methods
name: Check for bad mock methods
- id: python-no-log-warn
name: Check for logger.warn

# Format Python
- repo: https://github.com/psf/black
rev: '21.7b0'
hooks:
- id: black
name: Format Python with Black

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
args: [--py36-plus]

- repo: https://github.com/pycqa/isort
rev: '5.9.3'
hooks:
- id: isort
name: Format Python imports with isort

# Lint Python
- repo: https://github.com/pycqa/flake8
rev: '4.0.1'
hooks:
- id: flake8
name: Lint Python with Flake8
exclude: '\bworkshops\b'

- repo: https://github.com/pycqa/pylint
rev: v2.14.5
hooks:
- id: pylint
name: Lint Python with Pylint
exclude: '\bworkshops\b'

# Check Python dependencies
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.3.0
hooks:
- id: python-safety-dependencies-check
name: Run Safety check on dependencies
files: 'requirements*.txt'

# Check RST
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: rst-backticks
name: Check RST backticks
- id: rst-directive-colons
name: Check RST directive colons
- id: rst-inline-touching-normal
name: Check RST inline touching normal

# Lint RST
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: 'v0.6.1'
hooks:
- id: sphinx-lint
name: Lint RST
args: [--enable, all, --disable, line-too-long]

# Check TOML and XML
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-toml
name: Check TOML
- id: check-xml
name: Check XML

# Pretty-format YAML
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.4.0
hooks:
- id: pretty-format-yaml
name: Format YAML
exclude: '\bworkshops\b'
args: [--autofix, --indent, '2', --preserve-quotes]

# Check YAML
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-yaml
name: Check YAML

# Lint YAML
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.27.1
hooks:
- id: yamllint
name: Lint YAML
types: [yaml]
args: [-s, -f, colored]

# Replace CRLF with LF post-prettify
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: remove-crlf
name: Replace CRLFs with LF
types: [text]
exclude_types: [batch, svg]


# General checkers

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: text-unicode-replacement-char
name: Check for Unicode replacement chars

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
name: Check for added large files
args: [--maxkb=1025]
- id: check-case-conflict
name: Check for case conflicts
- id: check-executables-have-shebangs
name: Check that executables have shebangs
exclude: 'pre\-commit\-config\.yaml'
- id: check-shebang-scripts-are-executable
name: Check that shebangs are executable
exclude: 'pre\-commit\-config\.yaml'
- id: check-merge-conflict
name: Check for merge conflicts


# Commit message hooks #

# Check that commit message follows basic rules
- repo: https://github.com/jorisroovers/gitlint
rev: v0.17.0
hooks:
- id: gitlint
name: Check commit message

# Check commit message spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
name: Check commit message spelling
stages: [commit-msg]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.7.0
hooks:
- id: black
pass_filenames: true
exclude: _vendor|vendored|examples
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.281
hooks:
- id: ruff
exclude: _vendor|vendored
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.3
hooks:
- id: check-github-workflows
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
- id: check-yaml
- id: check-toml
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: .*\.md
- id: debug-statements
- id: mixed-line-ending
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.4.0
hooks:
- id: setup-cfg-fmt
args: ["--include-version-classifiers", "--max-py-version", "3.11", "--min-py-version", "3.7"]

ci:
autoupdate_schedule: monthly
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ python -m pip install -e .[test]
You can then import and use QtPy as normal.
When you make changes in your local copy of the git repository, they will be reflected in your installed copy as soon as you re-run Python.

### Pre-commit hooks

We use [pre-commit](https://pre-commit.com/) to run some checks before each commit. To install it in local environment, run:

```bash
pip install pre-commit
```

or globally with pipx:

```bash
pipx install pre-commit
```

or from conda:

```bash
conda install -c conda-forge pre-commit
```

Then, install the pre-commit hooks with:

```bash
pre-commit install
```

If you do not want to run the hooks locally the `pre-commit.ci` workflow will run them for you on GitHub.


## Deciding Which Branch to Use
Expand Down
Loading

0 comments on commit a098b28

Please sign in to comment.