From 31a655033eeb7710da1f2c124ee069df1d2ab6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Mon, 27 Jan 2025 15:59:41 +0100 Subject: [PATCH] chore: modernize pre-commit --- .pre-commit-config.yaml | 28 ++++++++-------------------- CHANGELOG.md | 4 ++-- doc/client-applications.rst | 2 +- doc/conf.py | 2 +- doc/resource-servers.rst | 2 +- poetry.lock | 16 +++++++++++++++- pyproject.toml | 32 ++++++++++++++++++++++++++++++-- pytest_iam/__init__.py | 18 ++++++------------ 8 files changed, 64 insertions(+), 40 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 79a743b..0e8b8b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ --- repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.4.1' + rev: 'v0.9.3' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: fix-byte-order-marker - id: trailing-whitespace @@ -15,22 +15,10 @@ repos: - id: end-of-file-fixer exclude: "\\.svg$|\\.map$|\\.min\\.css$|\\.min\\.js$|\\.po$|\\.pot$" - id: check-toml - - repo: https://github.com/pycqa/isort - rev: "5.13.2" + - repo: https://github.com/codespell-project/codespell + rev: v2.4.0 hooks: - - id: isort - name: isort (python) - args: ["--force-single-line-imports", "--profile", "black"] - - repo: https://github.com/PyCQA/docformatter - rev: v1.7.5 - hooks: - - id: docformatter - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 - hooks: - - id: pyupgrade - args: ["--py39-plus"] - - repo: https://github.com/rtts/djhtml - rev: 3.0.6 - hooks: - - id: djhtml + - id: codespell + additional_dependencies: + - tomli + args: [--write-changes] diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7d203..26785a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ Versions follow [Semantic Versioning](https://semver.org/>) (..) (..`_ JWT, then your application will need to check the signature against the identity server JWKs. If the access token is not a JWT then your application will need to perform a request against the identity server token introspection endpoint. diff --git a/poetry.lock b/poetry.lock index 4041419..52f604f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1371,6 +1371,20 @@ files = [ {file = "tomli-2.2.1.tar.gz", hash = "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff"}, ] +[[package]] +name = "types-requests" +version = "2.32.0.20241016" +description = "Typing stubs for requests" +optional = false +python-versions = ">=3.8" +files = [ + {file = "types-requests-2.32.0.20241016.tar.gz", hash = "sha256:0d9cad2f27515d0e3e3da7134a1b6f28fb97129d86b867f24d9c726452634d95"}, + {file = "types_requests-2.32.0.20241016-py3-none-any.whl", hash = "sha256:4195d62d6d3e043a4eaaf08ff8a62184584d2e8684e9d2aa178c7915a7da3747"}, +] + +[package.dependencies] +urllib3 = ">=2" + [[package]] name = "typing-extensions" version = "4.12.2" @@ -1455,4 +1469,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "e7835d636bf4d869bd2794bdf4f86704ead8358456f2e3aa3b2dfe2833c66a31" +content-hash = "8d9464d9a65a4fb00d6316d141c22680a6a8a6a0f5ded35d4f5bcb7b4b9718d5" diff --git a/pyproject.toml b/pyproject.toml index d7976a5..4e61bf9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ iam = "pytest_iam" authlib = "^1.2.1" pytest-cov = "^6.0.0" requests = "^2.31.0" +types-requests = "*" [tool.poetry.group.doc] optional = true @@ -53,8 +54,35 @@ shibuya = "^2024.7.13" sphinx = "^7.0.0" sphinx-issues = "^4.0.0" -[tool.ruff] -ignore = ["E501", "E722"] +[tool.ruff.lint] +select = [ + "B", # flake8-bugbear + "D", # pydocstyle + "E", # pycodestyle + "F", # pyflakes + "I", # isort + "UP", # pyupgrade +] +ignore = [ + "E501", # line-too-long + "E722", # bare-except + "D100", # public module + "D101", # public class + "D102", # public method + "D103", # public function + "D104", # public package + "D105", # magic method + "D106", # nested class + "D107", # public init + "D203", # no-blank-line-before-class + "D213", # multi-line-summary-second-line +] + +[tool.ruff.lint.isort] +force-single-line = true + +[tool.ruff.format] +docstring-code-format = true [tool.tox] legacy_tox_ini = """ diff --git a/pytest_iam/__init__.py b/pytest_iam/__init__.py index 0bb2676..cb8de5e 100644 --- a/pytest_iam/__init__.py +++ b/pytest_iam/__init__.py @@ -54,7 +54,7 @@ def url(self) -> str: return f"http://localhost:{self.port}/" def random_user(self, **kwargs) -> User: - """Generates a :class:`~canaille.core.models.User` with random values. + """Generate a :class:`~canaille.core.models.User` with random values. Any parameter will be used instead of a random value. """ @@ -66,7 +66,7 @@ def random_user(self, **kwargs) -> User: return user def random_group(self, **kwargs) -> Group: - """Generates a :class:`~canaille.core.models.Group` with random values. + """Generate a :class:`~canaille.core.models.Group` with random values. Any parameter will be used instead of a random value. """ @@ -78,8 +78,7 @@ def random_group(self, **kwargs) -> Group: return group def random_token(self, subject, client, **kwargs) -> Token: - """Generates a test :class:`~canaille.oidc.basemodels.Token` with - random values. + """Generate a test :class:`~canaille.oidc.basemodels.Token` with random values. Any parameter will be used instead of a random value. """ @@ -103,7 +102,7 @@ def random_token(self, subject, client, **kwargs) -> Token: return token def login(self, user): - """Opens a session for the user in the IAM session. + """Open a session for the user in the IAM session. This allows to skip the connection screen. """ @@ -114,7 +113,6 @@ def consent(self, user, client=None): :param client: If :const:`None`, all existing clients are consented. """ - with self.app.app_context(): clients = [client] if client else self.backend.query(models.Client) @@ -141,9 +139,7 @@ def consent(self, user, client=None): @pytest.fixture(scope="session") def iam_configuration(tmp_path_factory) -> dict[str, Any]: - """Fixture for editing the configuration of - :meth:`~pytest_iam.iam_server`.""" - + """Fixture for editing the configuration of :meth:`~pytest_iam.iam_server`.""" private_key, public_key = generate_keypair() return { "TESTING": True, @@ -185,9 +181,7 @@ def iam_configuration(tmp_path_factory) -> dict[str, Any]: @pytest.fixture(scope="session") def iam_server(iam_configuration) -> Server: - """Fixture that creates a Canaille server listening a random port in a - thread.""" - + """Fixture that creates a Canaille server listening a random port in a thread.""" port = portpicker.pick_unused_port() app = create_app( config=iam_configuration, env_file=".pytest-iam.env", env_prefix="PYTEST_IAM_"