Skip to content

Commit

Permalink
chore: modernize pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Jan 27, 2025
1 parent f7be5d0 commit 31a6550
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 40 deletions.
28 changes: 8 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
---
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
exclude: "\\.svg$|\\.map$|\\.min\\.css$|\\.min\\.js$|\\.po$|\\.pot$"
- 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]
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Versions follow [Semantic Versioning](https://semver.org/>) (<major>.<minor>.<pa
### Changed

- Configuration is read from `.pytest-iam.env`
- Configuration is read from enviroment vars prefixed by `PYTEST_IAM_`
- Configuration is read from environment vars prefixed by `PYTEST_IAM_`

## [0.0.11] - 2024-04-22

Expand Down Expand Up @@ -61,7 +61,7 @@ Versions follow [Semantic Versioning](https://semver.org/>) (<major>.<minor>.<pa

### Fixed

- python <=3.8 uncompatible typing
- python <=3.8 incompatible typing

## [0.0.5] - 2023-12-22

Expand Down
2 changes: 1 addition & 1 deletion doc/client-applications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Users & groups
~~~~~~~~~~~~~~

You can use the available :class:`~canaille.core.models.User` and :class:`~canaille.core.models.Group` models to set up their
IAM server for your tests. Optionnally you can put them in pytest fixtures so they are re-usable:
IAM server for your tests. Optionally you can put them in pytest fixtures so they are reusable:


.. code:: python
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
author = "Yaal Coop"

release = metadata.version("pytest_iam")
version = "%s.%s" % tuple(map(int, release.split(".")[:2]))
version = "{}.{}".format(*tuple(map(int, release.split(".")[:2])))
language = "en"
exclude_patterns = []
pygments_style = "sphinx"
Expand Down
2 changes: 1 addition & 1 deletion doc/resource-servers.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Resource servers
================

If you are writing a resource server, you will probably want to test if your application can successfully check if a token is valid, to determine wether resources can be accessed.
If you are writing a resource server, you will probably want to test if your application can successfully check if a token is valid, to determine whether resources can be accessed.
If the access token is a `RFC9068 <https://www.rfc-editor.org/rfc/rfc9068.html>`_ 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.
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = """
Expand Down
18 changes: 6 additions & 12 deletions pytest_iam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand All @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -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_"
Expand Down

0 comments on commit 31a6550

Please sign in to comment.