Skip to content

Commit 07049e3

Browse files
authored
Merge pull request #604 from azmeuk/flask-pre-commit
pre-commit configuration insipred from Flask
2 parents f2bbd1b + 49a1380 commit 07049e3

File tree

8 files changed

+53
-77
lines changed

8 files changed

+53
-77
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,14 @@
1-
ci:
2-
autoupdate_schedule: monthly
31
repos:
4-
- repo: https://github.com/asottile/pyupgrade
5-
rev: v3.17.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.6.9
64
hooks:
7-
- id: pyupgrade
8-
args: ["--py37-plus"]
9-
- repo: https://github.com/asottile/reorder-python-imports
10-
rev: v3.13.0
11-
hooks:
12-
- id: reorder-python-imports
13-
args: ["--application-directories", "src"]
14-
additional_dependencies: ["setuptools>60.9"]
15-
- repo: https://github.com/psf/black
16-
rev: 24.8.0
17-
hooks:
18-
- id: black
19-
- repo: https://github.com/PyCQA/flake8
20-
rev: 7.1.1
21-
hooks:
22-
- id: flake8
23-
additional_dependencies:
24-
- flake8-bugbear
25-
- flake8-implicit-str-concat
26-
- flake8-pyproject
27-
- repo: https://github.com/peterdemin/pip-compile-multi
28-
rev: v2.6.4
29-
hooks:
30-
- id: pip-compile-multi-verify
5+
- id: ruff
6+
- id: ruff-format
317
- repo: https://github.com/pre-commit/pre-commit-hooks
32-
rev: v4.6.0
8+
rev: v5.0.0
339
hooks:
10+
- id: check-merge-conflict
11+
- id: debug-statements
3412
- id: fix-byte-order-marker
3513
- id: trailing-whitespace
3614
- id: end-of-file-fixer

.readthedocs.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
version: 2
2+
build:
3+
os: ubuntu-22.04
4+
tools:
5+
python: '3.12'
26
python:
37
install:
48
- requirements: requirements/docs.txt
@@ -7,7 +11,3 @@ python:
711
sphinx:
812
builder: dirhtml
913
fail_on_warning: true
10-
build:
11-
os: "ubuntu-22.04"
12-
tools:
13-
python: "3.11"

examples/recaptcha/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from flask_wtf import FlaskForm
1111
from flask_wtf.recaptcha import RecaptchaField
1212

13-
1413
DEBUG = True
1514
SECRET_KEY = "secret"
1615

pyproject.toml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,22 @@ exclude_lines = [
7575
"except ImportError:",
7676
]
7777

78-
[tool.flake8]
79-
# B = bugbear
80-
# E = pycodestyle errors
81-
# F = flake8 pyflakes
82-
# W = pycodestyle warnings
83-
# B9 = bugbear opinions
84-
# ISC = implicit-str-concat
85-
select = ["B", "E", "F", "W", "B9", "ISC"]
86-
ignore = [
87-
# slice notation whitespace, invalid
88-
"E203",
89-
# line length, handled by bugbear B950
90-
"E501",
91-
# bare except, handled by bugbear B001
92-
"E722",
93-
# bin op line break, invalid
94-
"W503",
95-
# requires 'strict' argument for 'zip'
96-
# that needs python >= 3.10
97-
"B905",
98-
]
99-
# up to 88 allowed by bugbear B950
100-
max-line-length = 80
101-
per-file-ignores = [
102-
# __init__ modules export names
103-
"**/__init__.py: F401, F403",
78+
[tool.ruff]
79+
src = ["src"]
80+
fix = true
81+
show-fixes = true
82+
output-format = "full"
83+
84+
[tool.ruff.lint]
85+
select = [
86+
"B", # flake8-bugbear
87+
"E", # pycodestyle error
88+
"F", # pyflakes
89+
"I", # isort
90+
"UP", # pyupgrade
91+
"W", # pycodestyle warning
10492
]
93+
94+
[tool.ruff.lint.isort]
95+
force-single-line = true
96+
order-by-type = false

src/flask_wtf/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@
66
from .recaptcha import RecaptchaWidget
77

88
__version__ = "1.2.1"
9+
__all__ = [
10+
"CSRFProtect",
11+
"FlaskForm",
12+
"Form",
13+
"Recaptcha",
14+
"RecaptchaField",
15+
"RecaptchaWidget",
16+
]

src/flask_wtf/file.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ def __call__(self, form, field):
137137
raise ValidationError(
138138
self.message
139139
or field.gettext(
140-
"File must be between {min_size} and {max_size} bytes.".format(
141-
min_size=self.min_size, max_size=self.max_size
142-
)
140+
f"File must be between {self.min_size}"
141+
f" and {self.max_size} bytes."
143142
)
144143
)
145144

src/flask_wtf/recaptcha/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
from .fields import RecaptchaField
22
from .validators import Recaptcha
33
from .widgets import RecaptchaWidget
4+
5+
__all__ = ["RecaptchaField", "RecaptchaWidget", "Recaptcha"]

tests/test_file.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def test_file_allowed(form):
6767

6868
def test_file_allowed_uploadset(app, form):
6969
pytest.importorskip("flask_uploads")
70-
from flask_uploads import UploadSet, configure_uploads
70+
from flask_uploads import configure_uploads
71+
from flask_uploads import UploadSet
7172

7273
app.config["UPLOADS_DEFAULT_DEST"] = "uploads"
7374
txt = UploadSet("txt", extensions=("txt",))
@@ -114,10 +115,8 @@ def test_file_size_invalid_file_size_fails_validation(
114115
with path.open("rb") as file:
115116
f = form(file=FileStorage(file))
116117
assert not f.validate()
117-
assert f.file.errors[
118-
0
119-
] == "File must be between {min_size} and {max_size} bytes.".format(
120-
min_size=min_size, max_size=max_size
118+
assert (
119+
f.file.errors[0] == f"File must be between {min_size} and {max_size} bytes."
121120
)
122121

123122

@@ -190,7 +189,8 @@ def test_files_allowed(form):
190189

191190
def test_files_allowed_uploadset(app, form):
192191
pytest.importorskip("flask_uploads")
193-
from flask_uploads import UploadSet, configure_uploads
192+
from flask_uploads import configure_uploads
193+
from flask_uploads import UploadSet
194194

195195
app.config["UPLOADS_DEFAULT_DEST"] = "uploads"
196196
txt = UploadSet("txt", extensions=("txt",))
@@ -245,10 +245,9 @@ def test_file_size_invalid_file_sizes_fails_validation(
245245
with path.open("rb") as file:
246246
f = form(files=[FileStorage(file)])
247247
assert not f.validate()
248-
assert f.files.errors[
249-
0
250-
] == "File must be between {min_size} and {max_size} bytes.".format(
251-
min_size=min_size, max_size=max_size
248+
assert (
249+
f.files.errors[0]
250+
== f"File must be between {min_size} and {max_size} bytes."
252251
)
253252

254253

@@ -257,10 +256,9 @@ def test_files_length(form, min_num=2, max_num=3):
257256

258257
f = form(files=[FileStorage("1")])
259258
assert not f.validate()
260-
assert f.files.errors[
261-
0
262-
] == "Field must be between {min_num} and {max_num} characters long.".format(
263-
min_num=min_num, max_num=max_num
259+
assert (
260+
f.files.errors[0]
261+
== f"Field must be between {min_num} and {max_num} characters long."
264262
)
265263

266264
f = form(

0 commit comments

Comments
 (0)