Skip to content

Commit 354461c

Browse files
authored
PR: Setup pre-commit and format all code with Black (#451)
2 parents 8017a8f + 4b12ece commit 354461c

File tree

107 files changed

+1533
-1122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1533
-1122
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# setup pre-commit
2+
a098b2819173fb56a6f479df9b29ef76d2b63d56

.pre-commit-config.yaml

Lines changed: 35 additions & 296 deletions
Original file line numberDiff line numberDiff line change
@@ -1,297 +1,36 @@
1-
# See https://pre-commit.com for more information
2-
# See https://pre-commit.com/hooks.html for more hooks
3-
4-
minimum_pre_commit_version: '2.10.0'
5-
6-
default_language_version:
7-
python: python3
8-
9-
default_stages: [commit]
10-
11-
121
repos:
13-
# Meta checks
14-
- repo: meta
15-
hooks:
16-
- id: check-useless-excludes
17-
18-
# General fixers
19-
- repo: https://github.com/pre-commit/pre-commit-hooks
20-
rev: v4.3.0
21-
hooks:
22-
- id: trailing-whitespace
23-
name: Trim trailing whitespace
24-
exclude_types: [svg]
25-
- id: mixed-line-ending
26-
name: Normalize mixed line endings
27-
args: [--fix=lf]
28-
exclude_types: [batch]
29-
- id: end-of-file-fixer
30-
name: Fix end of files
31-
exclude_types: [svg]
32-
- id: fix-byte-order-marker
33-
name: Remove Unicode BOM
34-
35-
36-
# More general fixers
37-
- repo: https://github.com/Lucas-C/pre-commit-hooks
38-
rev: v1.3.0
39-
hooks:
40-
- id: remove-tabs
41-
name: Replace tabs with spaces
42-
types: [text]
43-
exclude_types: [svg, batch]
44-
args: [--whitespaces-count, '4']
45-
46-
47-
# Check and fix spelling
48-
- repo: https://github.com/codespell-project/codespell
49-
rev: v2.1.0
50-
hooks:
51-
# Define separate hooks for checking and correcting spelling errors
52-
# since codespell doesn't print verbose output when writing changes
53-
- id: codespell
54-
name: Check spelling
55-
exclude: '\.codespellrc|\.gitattributes'
56-
- id: codespell
57-
name: Fix spelling
58-
exclude: '\.codespellrc|\.gitattributes'
59-
args: [--write-changes]
60-
61-
# Lint and fix CSS with stylelint
62-
- repo: https://github.com/awebdeveloper/pre-commit-stylelint
63-
rev: '0.0.2'
64-
hooks:
65-
- id: stylelint
66-
name: Lint and fix CSS (stylelint)
67-
args: [--fix, --color, --maxWarnings, '0']
68-
additional_dependencies:
69-
70-
71-
72-
73-
74-
75-
76-
# Lint CSS with CSSlint
77-
- repo: https://github.com/pre-commit/mirrors-csslint
78-
rev: v1.0.5
79-
hooks:
80-
- id: csslint
81-
name: Check CSS (CSSlint)
82-
83-
# Pretty-format INI
84-
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
85-
rev: v2.4.0
86-
hooks:
87-
- id: pretty-format-ini
88-
name: Format INI
89-
types: [ini]
90-
args: [--autofix]
91-
92-
# Check JSON
93-
- repo: https://github.com/pre-commit/pre-commit-hooks
94-
rev: v4.3.0
95-
hooks:
96-
- id: check-json
97-
name: Check JSON
98-
99-
# Add doctoc to Markdown
100-
- repo: https://github.com/thlorenz/doctoc
101-
rev: v2.2.0
102-
hooks:
103-
- id: doctoc
104-
name: Generate Markdown ToCs
105-
args: [--maxlevel, '3', --update-only]
106-
107-
# Lint Markdown
108-
- repo: https://github.com/igorshubovych/markdownlint-cli
109-
rev: v0.32.1
110-
hooks:
111-
- id: markdownlint
112-
name: Lint Markdown
113-
args: [--fix]
114-
115-
# Format packaging
116-
- repo: https://github.com/asottile/setup-cfg-fmt
117-
rev: v1.17.0
118-
hooks:
119-
- id: setup-cfg-fmt
120-
name: Format packaging with setup-cfg-fmt
121-
122-
# Check packaging
123-
- repo: https://github.com/regebro/pyroma
124-
rev: '3.2'
125-
hooks:
126-
- id: pyroma
127-
128-
# Fix Python
129-
- repo: https://github.com/asottile/pyupgrade
130-
rev: v2.24.0
131-
hooks:
132-
- id: pyupgrade
133-
name: Fix Python with Pyupgrade
134-
args: ['--py37-plus', '--keep-runtime-typing']
135-
136-
# Check Python
137-
- repo: https://github.com/pre-commit/pre-commit-hooks
138-
rev: v4.3.0
139-
hooks:
140-
- id: check-ast
141-
name: Check Python
142-
143-
- repo: https://github.com/pre-commit/pygrep-hooks
144-
rev: v1.9.0
145-
hooks:
146-
- id: python-check-mock-methods
147-
name: Check for bad mock methods
148-
- id: python-no-log-warn
149-
name: Check for logger.warn
150-
151-
# Format Python
152-
- repo: https://github.com/psf/black
153-
rev: '21.7b0'
154-
hooks:
155-
- id: black
156-
name: Format Python with Black
157-
158-
- repo: https://github.com/asottile/add-trailing-comma
159-
rev: v2.1.0
160-
hooks:
161-
- id: add-trailing-comma
162-
args: [--py36-plus]
163-
164-
- repo: https://github.com/pycqa/isort
165-
rev: '5.9.3'
166-
hooks:
167-
- id: isort
168-
name: Format Python imports with isort
169-
170-
# Lint Python
171-
- repo: https://github.com/pycqa/flake8
172-
rev: '4.0.1'
173-
hooks:
174-
- id: flake8
175-
name: Lint Python with Flake8
176-
exclude: '\bworkshops\b'
177-
178-
- repo: https://github.com/pycqa/pylint
179-
rev: v2.14.5
180-
hooks:
181-
- id: pylint
182-
name: Lint Python with Pylint
183-
exclude: '\bworkshops\b'
184-
185-
# Check Python dependencies
186-
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
187-
rev: v1.3.0
188-
hooks:
189-
- id: python-safety-dependencies-check
190-
name: Run Safety check on dependencies
191-
files: 'requirements*.txt'
192-
193-
# Check RST
194-
- repo: https://github.com/pre-commit/pygrep-hooks
195-
rev: v1.9.0
196-
hooks:
197-
- id: rst-backticks
198-
name: Check RST backticks
199-
- id: rst-directive-colons
200-
name: Check RST directive colons
201-
- id: rst-inline-touching-normal
202-
name: Check RST inline touching normal
203-
204-
# Lint RST
205-
- repo: https://github.com/sphinx-contrib/sphinx-lint
206-
rev: 'v0.6.1'
207-
hooks:
208-
- id: sphinx-lint
209-
name: Lint RST
210-
args: [--enable, all, --disable, line-too-long]
211-
212-
# Check TOML and XML
213-
- repo: https://github.com/pre-commit/pre-commit-hooks
214-
rev: v4.3.0
215-
hooks:
216-
- id: check-toml
217-
name: Check TOML
218-
- id: check-xml
219-
name: Check XML
220-
221-
# Pretty-format YAML
222-
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
223-
rev: v2.4.0
224-
hooks:
225-
- id: pretty-format-yaml
226-
name: Format YAML
227-
exclude: '\bworkshops\b'
228-
args: [--autofix, --indent, '2', --preserve-quotes]
229-
230-
# Check YAML
231-
- repo: https://github.com/pre-commit/pre-commit-hooks
232-
rev: v4.3.0
233-
hooks:
234-
- id: check-yaml
235-
name: Check YAML
236-
237-
# Lint YAML
238-
- repo: https://github.com/adrienverge/yamllint.git
239-
rev: v1.27.1
240-
hooks:
241-
- id: yamllint
242-
name: Lint YAML
243-
types: [yaml]
244-
args: [-s, -f, colored]
245-
246-
# Replace CRLF with LF post-prettify
247-
- repo: https://github.com/Lucas-C/pre-commit-hooks
248-
rev: v1.3.0
249-
hooks:
250-
- id: remove-crlf
251-
name: Replace CRLFs with LF
252-
types: [text]
253-
exclude_types: [batch, svg]
254-
255-
256-
# General checkers
257-
258-
- repo: https://github.com/pre-commit/pygrep-hooks
259-
rev: v1.9.0
260-
hooks:
261-
- id: text-unicode-replacement-char
262-
name: Check for Unicode replacement chars
263-
264-
- repo: https://github.com/pre-commit/pre-commit-hooks
265-
rev: v4.3.0
266-
hooks:
267-
- id: check-added-large-files
268-
name: Check for added large files
269-
args: [--maxkb=1025]
270-
- id: check-case-conflict
271-
name: Check for case conflicts
272-
- id: check-executables-have-shebangs
273-
name: Check that executables have shebangs
274-
exclude: 'pre\-commit\-config\.yaml'
275-
- id: check-shebang-scripts-are-executable
276-
name: Check that shebangs are executable
277-
exclude: 'pre\-commit\-config\.yaml'
278-
- id: check-merge-conflict
279-
name: Check for merge conflicts
280-
281-
282-
# Commit message hooks #
283-
284-
# Check that commit message follows basic rules
285-
- repo: https://github.com/jorisroovers/gitlint
286-
rev: v0.17.0
287-
hooks:
288-
- id: gitlint
289-
name: Check commit message
290-
291-
# Check commit message spelling
292-
- repo: https://github.com/codespell-project/codespell
293-
rev: v2.1.0
294-
hooks:
295-
- id: codespell
296-
name: Check commit message spelling
297-
stages: [commit-msg]
2+
- repo: https://github.com/psf/black-pre-commit-mirror
3+
rev: 23.7.0
4+
hooks:
5+
- id: black
6+
pass_filenames: true
7+
exclude: _vendor|vendored|examples
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
rev: v0.0.281
10+
hooks:
11+
- id: ruff
12+
exclude: _vendor|vendored
13+
- repo: https://github.com/python-jsonschema/check-jsonschema
14+
rev: 0.23.3
15+
hooks:
16+
- id: check-github-workflows
17+
- repo: https://github.com/pre-commit/pre-commit-hooks
18+
rev: v4.4.0
19+
hooks:
20+
- id: check-json
21+
- id: check-yaml
22+
- id: check-toml
23+
- id: check-merge-conflict
24+
- id: end-of-file-fixer
25+
- id: trailing-whitespace
26+
exclude: .*\.md
27+
- id: debug-statements
28+
- id: mixed-line-ending
29+
- repo: https://github.com/asottile/setup-cfg-fmt
30+
rev: v2.4.0
31+
hooks:
32+
- id: setup-cfg-fmt
33+
args: ["--include-version-classifiers", "--max-py-version", "3.11", "--min-py-version", "3.7"]
34+
35+
ci:
36+
autoupdate_schedule: monthly

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ python -m pip install -e .[test]
105105
You can then import and use QtPy as normal.
106106
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.
107107

108+
### Pre-commit hooks
109+
110+
We use [pre-commit](https://pre-commit.com/) to run some checks before each commit. To install it in local environment, run:
111+
112+
```bash
113+
pip install pre-commit
114+
```
115+
116+
or globally with pipx:
117+
118+
```bash
119+
pipx install pre-commit
120+
```
121+
122+
or from conda:
123+
124+
```bash
125+
conda install -c conda-forge pre-commit
126+
```
127+
128+
Then, install the pre-commit hooks with:
129+
130+
```bash
131+
pre-commit install
132+
```
133+
134+
If you do not want to run the hooks locally the `pre-commit.ci` workflow will run them for you on GitHub.
108135

109136

110137
## Deciding Which Branch to Use

0 commit comments

Comments
 (0)