diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f16d1ffa..1cddf087 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 44df8af7..865c6859 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,4 +1,8 @@ version: 2 +build: + os: ubuntu-22.04 + tools: + python: '3.12' python: install: - requirements: requirements/docs.txt @@ -7,7 +11,3 @@ python: sphinx: builder: dirhtml fail_on_warning: true -build: - os: "ubuntu-22.04" - tools: - python: "3.11" diff --git a/examples/recaptcha/app.py b/examples/recaptcha/app.py index 150cc511..fa34d870 100644 --- a/examples/recaptcha/app.py +++ b/examples/recaptcha/app.py @@ -10,7 +10,6 @@ from flask_wtf import FlaskForm from flask_wtf.recaptcha import RecaptchaField - DEBUG = True SECRET_KEY = "secret" diff --git a/pyproject.toml b/pyproject.toml index 3b2a1567..154a6efc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/src/flask_wtf/__init__.py b/src/flask_wtf/__init__.py index be2649e2..c7814ab7 100644 --- a/src/flask_wtf/__init__.py +++ b/src/flask_wtf/__init__.py @@ -6,3 +6,11 @@ from .recaptcha import RecaptchaWidget __version__ = "1.2.1" +__all__ = [ + "CSRFProtect", + "FlaskForm", + "Form", + "Recaptcha", + "RecaptchaField", + "RecaptchaWidget", +] diff --git a/src/flask_wtf/file.py b/src/flask_wtf/file.py index a720dff8..98c45770 100644 --- a/src/flask_wtf/file.py +++ b/src/flask_wtf/file.py @@ -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." ) ) diff --git a/src/flask_wtf/recaptcha/__init__.py b/src/flask_wtf/recaptcha/__init__.py index 3100d37e..c414a9fb 100644 --- a/src/flask_wtf/recaptcha/__init__.py +++ b/src/flask_wtf/recaptcha/__init__.py @@ -1,3 +1,5 @@ from .fields import RecaptchaField from .validators import Recaptcha from .widgets import RecaptchaWidget + +__all__ = ["RecaptchaField", "RecaptchaWidget", "Recaptcha"] diff --git a/tests/test_file.py b/tests/test_file.py index 66d261be..87654d42 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -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",)) @@ -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." ) @@ -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",)) @@ -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." ) @@ -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(