Skip to content

Commit edffbe4

Browse files
committed
feat: py312
1 parent 5fc4410 commit edffbe4

File tree

8 files changed

+141
-57
lines changed

8 files changed

+141
-57
lines changed

.git-commits.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
3+
convention:
4+
commitTypes:
5+
- feat
6+
- fix
7+
- perf
8+
- refactor
9+
- style
10+
- test
11+
- build
12+
- ops
13+
- docs
14+
- merge
15+
commitScopes: []
16+
releaseTagGlobPattern: v[0-9]*.[0-9]*.[0-9]*
17+
18+
changelog:
19+
commitTypes:
20+
- feat
21+
- fix
22+
- perf
23+
- merge
24+
includeInvalidCommits: true
25+
commitScopes: []
26+
commitIgnoreRegexPattern: "^WIP "
27+
headlines:
28+
feat: Features
29+
fix: Bug Fixes
30+
perf: Performance Improvements
31+
merge: Merges
32+
breakingChange: BREAKING CHANGES
33+
commitUrl: https://github.com/klen/asgi-babel/commit/%commit%
34+
commitRangeUrl: https://github.com/klen/asgi-babel/compare/%from%...%to%?diff=split
35+
issueRegexPattern: "#[0-9]+"
36+
issueUrl: https://github.com/klen/asgi-babel/issues/%issue%

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
- uses: actions/setup-python@main
2222
with:
23-
python-version: '3.11'
23+
python-version: '3.12'
2424

2525
- name: Build package
2626
run: |

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
python-version: ['3.8', '3.9', '3.10', '3.11']
20+
python-version: ['3.9', '3.10', '3.11', '3.12']
2121

2222
steps:
2323
- name: Checkout changes
@@ -33,7 +33,7 @@ jobs:
3333
run: python -m pip install .[tests]
3434

3535
- name: Check code
36-
run: ruff asgi_babel
36+
run: ruff check asgi_babel
3737

3838
- name: Test with pytest
3939
run: pytest --mypy tests

.pre-commit-config.yaml

+66-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,73 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3+
4+
fail_fast: true
5+
default_install_hook_types: [commit-msg, pre-commit, pre-push]
6+
37
repos:
4-
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
6-
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
- id: check-added-large-files
11-
12-
- repo: https://github.com/charliermarsh/ruff-pre-commit
13-
rev: v0.0.253
8+
9+
- repo: https://github.com/qoomon/git-conventional-commits
10+
rev: 'v2.6.7'
1411
hooks:
15-
- id: ruff
16-
name: Check code
17-
args: [--fix, --exit-non-zero-on-fix]
12+
- id: conventional-commits
13+
args: ["-c", ".git-commits.yaml"]
14+
stages: ["commit-msg"]
15+
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v4.6.0
18+
hooks:
19+
- id: check-case-conflict
20+
stages: ["pre-commit"]
21+
- id: check-merge-conflict
22+
stages: ["pre-commit"]
23+
- id: check-added-large-files
24+
stages: ["pre-commit"]
25+
args: ['--maxkb=5000']
26+
- id: check-ast
27+
stages: ["pre-commit"]
28+
- id: check-executables-have-shebangs
29+
stages: ["pre-commit"]
30+
- id: check-symlinks
31+
stages: ["pre-commit"]
32+
- id: check-toml
33+
stages: ["pre-commit"]
34+
- id: check-yaml
35+
stages: ["pre-commit"]
36+
- id: debug-statements
37+
stages: ["pre-commit"]
38+
- id: end-of-file-fixer
39+
stages: ["pre-commit"]
40+
- id: trailing-whitespace
41+
stages: ["pre-commit"]
42+
43+
- repo: https://github.com/psf/black
44+
rev: 24.4.2
45+
hooks:
46+
- id: black
47+
stages: ["pre-commit"]
1848

1949
- repo: local
2050
hooks:
21-
- id: check-types
22-
name: Check types
23-
entry: mypy
24-
language: system
25-
pass_filenames: false
26-
- id: check-code
27-
name: Refactor code
28-
entry: refurb asgi_babel
29-
language: system
30-
pass_filenames: false
31-
- id: run-tests
32-
name: Run tests
33-
entry: pytest tests
34-
language: system
35-
pass_filenames: false
51+
- id: ruff
52+
name: ruff
53+
entry: ruff check asgi_babel
54+
language: system
55+
pass_filenames: false
56+
files: \.py$
57+
stages: ["pre-commit"]
58+
59+
- id: mypy
60+
name: mypy
61+
entry: mypy
62+
language: system
63+
pass_filenames: false
64+
files: \.py$
65+
stages: ["pre-push"]
66+
67+
- id: pytest
68+
name: pytest
69+
entry: pytest
70+
language: system
71+
pass_filenames: false
72+
files: \.py$
73+
stages: ["pre-push"]

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ VIRTUAL_ENV ?= env
22

33
all: $(VIRTUAL_ENV)
44

5-
$(VIRTUAL_ENV): pyproject.toml
5+
$(VIRTUAL_ENV): pyproject.toml .pre-commit-config.yaml
66
@[ -d $(VIRTUAL_ENV) ] || python -m venv $(VIRTUAL_ENV)
77
@$(VIRTUAL_ENV)/bin/pip install -e .[tests,dev,example]
8-
@$(VIRTUAL_ENV)/bin/pre-commit install --hook-type pre-push
8+
@$(VIRTUAL_ENV)/bin/pre-commit install
99
@touch $(VIRTUAL_ENV)
1010

1111
VERSION ?= minor

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ASGI-Babel
2828
Requirements
2929
=============
3030

31-
- python >= 3.8
31+
- python >= 3.9
3232

3333
.. _installation:
3434

asgi_babel/__init__.py

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Support cookie-encrypted sessions for ASGI applications."""
2+
23
from __future__ import annotations
34

45
import re
56
from contextvars import ContextVar
67
from dataclasses import dataclass, field
7-
from typing import TYPE_CHECKING, Awaitable, Callable, Dict, List, Optional, Tuple, Union
8+
from typing import TYPE_CHECKING, Awaitable, Callable, Optional, Union
89

910
from asgi_tools import Request
1011
from asgi_tools.middleware import BaseMiddeware
@@ -28,6 +29,7 @@
2829
current_locale = ContextVar[Optional[Locale]]("locale", default=None)
2930
BABEL = None
3031

32+
3133
class BabelMiddlewareError(RuntimeError):
3234
"""Base class for BabelMiddleware errors."""
3335

@@ -50,21 +52,27 @@ class BabelMiddleware(BaseMiddeware):
5052
app: TASGIApp
5153
default_locale: str = "en"
5254
domain: str = "messages"
53-
locales_dirs: List[str] = field(default_factory=lambda: ["locales"])
55+
locales_dirs: list[str] = field(default_factory=lambda: ["locales"])
5456
locale_selector: Callable[[Request], Awaitable[Optional[str]]] = field(
55-
repr=False, default=select_locale_by_request,
57+
repr=False,
58+
default=select_locale_by_request,
5659
)
5760

58-
translations: Dict[Tuple[str, str], support.Translations] = field(
59-
init=False, repr=False, default_factory=lambda: {},
61+
translations: dict[tuple[str, str], support.Translations] = field(
62+
init=False,
63+
repr=False,
64+
default_factory=dict,
6065
)
6166

6267
def __post_init__(self):
63-
global BABEL # noqa:
68+
global BABEL # noqa:PLW0603
6469
BABEL = self
6570

6671
async def __process__(
67-
self, scope: TASGIScope, receive: TASGIReceive, send: TASGISend,
72+
self,
73+
scope: TASGIScope,
74+
receive: TASGIReceive,
75+
send: TASGISend,
6876
):
6977
"""Load/save the sessions."""
7078
if isinstance(scope, Request):
@@ -80,7 +88,8 @@ async def __process__(
8088

8189

8290
def get_translations(
83-
domain: Optional[str] = None, locale: Optional[Locale] = None,
91+
domain: Optional[str] = None,
92+
locale: Optional[Locale] = None,
8493
) -> Union[support.Translations, support.NullTranslations]:
8594
"""Load and cache translations."""
8695
if BABEL is None:
@@ -112,7 +121,11 @@ def gettext(string: str, domain: Optional[str] = None, **variables):
112121

113122

114123
def ngettext(
115-
singular: str, plural: str, num: int, domain: Optional[str] = None, **variables,
124+
singular: str,
125+
plural: str,
126+
num: int,
127+
domain: Optional[str] = None,
128+
**variables,
116129
):
117130
"""Translate a string wity the current locale.
118131
@@ -145,7 +158,7 @@ def npgettext(
145158
return t.unpgettext(context, singular, plural, num) % variables
146159

147160

148-
def parse_accept_header(header: str) -> List[Tuple[float, str]]:
161+
def parse_accept_header(header: str) -> list[tuple[float, str]]:
149162
"""Parse accept headers."""
150163
result = []
151164
for match in accept_re.finditer(header):

pyproject.toml

+10-13
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = "asgi-babel"
33
version = "0.9.3"
44
description = "Internationalization (i18n) support for ASGI applications"
55
readme = "README.rst"
6-
requires-python = ">=3.8"
7-
license = {"text" = "MIT License"}
6+
requires-python = ">=3.9"
7+
license = { "text" = "MIT License" }
88
authors = [{ name = "Kirill Klenov", email = "horneds@gmail.com" }]
99
keywords = ["locale", "i18n", "l10n", "babel", "gettext", "translation", "asyncio", "trio", "asgi"]
1010
classifiers = [
@@ -14,18 +14,15 @@ classifiers = [
1414
"License :: OSI Approved :: MIT License",
1515
"Programming Language :: Python",
1616
"Programming Language :: Python :: 3",
17-
"Programming Language :: Python :: 3.8",
1817
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
2121
"Topic :: Internet :: WWW/HTTP",
2222
"Framework :: AsyncIO",
2323
"Framework :: Trio",
2424
]
25-
dependencies = [
26-
"asgi-tools >= 0.73.0",
27-
"babel",
28-
]
25+
dependencies = ["asgi-tools >= 0.73.0", "babel"]
2926

3027
[project.urls]
3128
homepage = "https://github.com/klen/asgi-babel"
@@ -39,9 +36,7 @@ tests = [
3936
"ruff",
4037
]
4138
example = ["uvicorn"]
42-
dev = [
43-
"bump2version", "refurb; python_version >= '3.9'",
44-
"tox", "pre-commit"]
39+
dev = ["bump2version", "refurb; python_version >= '3.9'", "tox", "pre-commit"]
4540

4641
[tool.setuptools]
4742
packages = ['asgi_babel']
@@ -59,7 +54,7 @@ ignore_missing_imports = true
5954
[tool.tox]
6055
legacy_tox_ini = """
6156
[tox]
62-
envlist = py38,py39,py310,py311,pypy39
57+
envlist = py39,py310,py311,py312,pypy39
6358
6459
[testenv]
6560
deps = -e .[tests]
@@ -76,10 +71,12 @@ commands =
7671
[tool.ruff]
7772
fix = true
7873
line-length = 100
79-
target-version = "py38"
74+
target-version = "py39"
8075
exclude = [".venv", "docs", "examples"]
76+
77+
[tool.ruff.lint]
8178
select = ["ALL"]
8279
ignore = ["D", "UP", "ANN", "DJ", "EM", "RSE", "SLF", "S101", "PLR2004"]
8380

84-
[tool.ruff.isort]
81+
[tool.ruff.lint.isort]
8582
required-imports = ["from __future__ import annotations"]

0 commit comments

Comments
 (0)