Skip to content

Commit

Permalink
chore: pre-commit configuration insipred from Flask
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Oct 12, 2024
1 parent f2bbd1b commit 7d3aef9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 73 deletions.
36 changes: 7 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: pyupgrade
args: ["--py37-plus"]
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.13.0
hooks:
- id: reorder-python-imports
args: ["--application-directories", "src"]
additional_dependencies: ["setuptools>60.9"]
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-implicit-str-concat
- flake8-pyproject
- repo: https://github.com/peterdemin/pip-compile-multi
rev: v2.6.4
hooks:
- id: pip-compile-multi-verify
- id: ruff
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: fix-byte-order-marker
- id: trailing-whitespace
- id: end-of-file-fixer
1 change: 0 additions & 1 deletion examples/recaptcha/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from flask_wtf import FlaskForm
from flask_wtf.recaptcha import RecaptchaField


DEBUG = True
SECRET_KEY = "secret"

Expand Down
44 changes: 18 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,22 @@ exclude_lines = [
"except ImportError:",
]

[tool.flake8]
# B = bugbear
# E = pycodestyle errors
# F = flake8 pyflakes
# W = pycodestyle warnings
# B9 = bugbear opinions
# ISC = implicit-str-concat
select = ["B", "E", "F", "W", "B9", "ISC"]
ignore = [
# slice notation whitespace, invalid
"E203",
# line length, handled by bugbear B950
"E501",
# bare except, handled by bugbear B001
"E722",
# bin op line break, invalid
"W503",
# requires 'strict' argument for 'zip'
# that needs python >= 3.10
"B905",
]
# up to 88 allowed by bugbear B950
max-line-length = 80
per-file-ignores = [
# __init__ modules export names
"**/__init__.py: F401, F403",
[tool.ruff]
src = ["src"]
fix = true
show-fixes = true
output-format = "full"

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"E", # pycodestyle error
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle warning
]

[tool.ruff.lint.isort]
force-single-line = true
order-by-type = false
8 changes: 8 additions & 0 deletions src/flask_wtf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
from .recaptcha import RecaptchaWidget

__version__ = "1.2.1"
__all__ = [
"CSRFProtect",
"FlaskForm",
"Form",
"Recaptcha",
"RecaptchaField",
"RecaptchaWidget",
]
5 changes: 2 additions & 3 deletions src/flask_wtf/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ def __call__(self, form, field):
raise ValidationError(
self.message
or field.gettext(
"File must be between {min_size} and {max_size} bytes.".format(
min_size=self.min_size, max_size=self.max_size
)
f"File must be between {self.min_size}"
f" and {self.max_size} bytes."
)
)

Expand Down
2 changes: 2 additions & 0 deletions src/flask_wtf/recaptcha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .fields import RecaptchaField
from .validators import Recaptcha
from .widgets import RecaptchaWidget

__all__ = ["RecaptchaField", "RecaptchaWidget", "Recaptcha"]
26 changes: 12 additions & 14 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_file_allowed(form):

def test_file_allowed_uploadset(app, form):
pytest.importorskip("flask_uploads")
from flask_uploads import UploadSet, configure_uploads
from flask_uploads import configure_uploads
from flask_uploads import UploadSet

app.config["UPLOADS_DEFAULT_DEST"] = "uploads"
txt = UploadSet("txt", extensions=("txt",))
Expand Down Expand Up @@ -114,10 +115,8 @@ def test_file_size_invalid_file_size_fails_validation(
with path.open("rb") as file:
f = form(file=FileStorage(file))
assert not f.validate()
assert f.file.errors[
0
] == "File must be between {min_size} and {max_size} bytes.".format(
min_size=min_size, max_size=max_size
assert (
f.file.errors[0] == f"File must be between {min_size} and {max_size} bytes."
)


Expand Down Expand Up @@ -190,7 +189,8 @@ def test_files_allowed(form):

def test_files_allowed_uploadset(app, form):
pytest.importorskip("flask_uploads")
from flask_uploads import UploadSet, configure_uploads
from flask_uploads import configure_uploads
from flask_uploads import UploadSet

app.config["UPLOADS_DEFAULT_DEST"] = "uploads"
txt = UploadSet("txt", extensions=("txt",))
Expand Down Expand Up @@ -245,10 +245,9 @@ def test_file_size_invalid_file_sizes_fails_validation(
with path.open("rb") as file:
f = form(files=[FileStorage(file)])
assert not f.validate()
assert f.files.errors[
0
] == "File must be between {min_size} and {max_size} bytes.".format(
min_size=min_size, max_size=max_size
assert (
f.files.errors[0]
== f"File must be between {min_size} and {max_size} bytes."
)


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

f = form(files=[FileStorage("1")])
assert not f.validate()
assert f.files.errors[
0
] == "Field must be between {min_num} and {max_num} characters long.".format(
min_num=min_num, max_num=max_num
assert (
f.files.errors[0]
== f"Field must be between {min_num} and {max_num} characters long."
)

f = form(
Expand Down

0 comments on commit 7d3aef9

Please sign in to comment.