Skip to content

Commit 91f4d95

Browse files
authored
Support Python >=3.10 (#111)
`datetime.UTC` -> `datetime.timezone.utc` and some pytest deps
1 parent 690615d commit 91f4d95

7 files changed

Lines changed: 594 additions & 209 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: ["3.11"]
19+
python-version: ["3.10", "3.11"]
2020
steps:
2121
- name: Checkout code
2222
uses: actions/checkout@v4
@@ -25,14 +25,15 @@ jobs:
2525
- name: Install Go
2626
uses: actions/setup-go@v4
2727
- name: Install Python ${{ matrix.python-version }}
28+
id: python
2829
uses: actions/setup-python@v4
2930
with:
3031
python-version: ${{ matrix.python-version }}
3132
- name: Execute tests
32-
run: make test
33+
run: make test PYTHON=${{ steps.python.outputs.python-path }}
3334
- name: Lint
34-
run: make lint
35+
run: make lint PYTHON=${{ steps.python.outputs.python-path }}
3536
- name: Format
36-
run: make format
37+
run: make format PYTHON=${{ steps.python.outputs.python-path }}
3738
- name: Check generated
38-
run: make checkgenerate
39+
run: make checkgenerate PYTHON=${{ steps.python.outputs.python-path }}

.github/workflows/conformance.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python-version: ["3.11"]
19+
python-version: ["3.10", "3.11"]
2020
steps:
2121
- name: Checkout code
2222
uses: actions/checkout@v4
@@ -25,8 +25,9 @@ jobs:
2525
- name: Install Go
2626
uses: actions/setup-go@v4
2727
- name: Install Python ${{ matrix.python-version }}
28+
id: python
2829
uses: actions/setup-python@v4
2930
with:
3031
python-version: ${{ matrix.python-version }}
3132
- name: Test conformance
32-
run: make conformance
33+
run: make conformance PYTHON=${{ steps.python.outputs.python-path }}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test: $(BIN)/protovalidate-conformance generate install ## Run unit tests
4949

5050
.PHONY: conformance
5151
conformance: $(BIN)/protovalidate-conformance generate install ## Run conformance tests
52-
protovalidate-conformance $(CONFORMANCE_ARGS) pipenv -- run $(PYTHON) -m tests.conformance.runner
52+
protovalidate-conformance $(CONFORMANCE_ARGS) pipenv -- --python $(PYTHON) run python3 -m tests.conformance.runner
5353

5454
.PHONY: lint
5555
lint: install ## Lint code

Pipfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ mypy = "*"
1313
ruff = "*"
1414
types-protobuf = "*"
1515
black = "*"
16+
exceptiongroup = "*"
17+
tomli = "*"
1618

1719
[requires]
18-
python_version = "3.11"
20+
python_version = "3.10"

Pipfile.lock

Lines changed: 572 additions & 194 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protovalidate/internal/constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _validate_cel(
226226
self, ctx: ConstraintContext, field_name: str, activation: dict[str, typing.Any], *, for_key: bool = False
227227
):
228228
activation["rules"] = self._rules_cel
229-
activation["now"] = celtypes.TimestampType(datetime.datetime.now(tz=datetime.UTC))
229+
activation["now"] = celtypes.TimestampType(datetime.datetime.now(tz=datetime.timezone.utc))
230230
for runner, constraint in self._runners:
231231
result = runner.evaluate(activation)
232232
if isinstance(result, celtypes.BoolType):

pyproject.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description = "Protocol Buffer Validation for Python"
88
readme = "README.md"
99
license = { file = "LICENSE" }
1010
keywords = ["validate", "protobuf", "protocol buffer"]
11-
requires-python = ">=3.11"
11+
requires-python = ">=3.10"
1212
classifiers = [
1313
"Programming Language :: Python :: 3",
1414
"License :: OSI Approved :: Apache Software License",
@@ -26,11 +26,11 @@ Issues = "https://github.com/bufbuild/protovalidate-python/issues"
2626
source = "vcs"
2727

2828
[tool.black]
29-
target-version = ["py311"]
29+
target-version = ["py310"]
3030
line-length = 120
3131

3232
[tool.ruff]
33-
target-version = "py311"
33+
target-version = "py310"
3434
line-length = 120
3535
select = [
3636
"A",
@@ -63,7 +63,11 @@ ignore = [
6363
# Allow boolean positional values in function calls, like `dict.get(..., True)`.
6464
"FBT003",
6565
# Ignore complexity
66-
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
66+
"C901",
67+
"PLR0911",
68+
"PLR0912",
69+
"PLR0913",
70+
"PLR0915",
6771
# Ignore magic values - in this library, most are obvious in context.
6872
"PLR2004",
6973
]
@@ -81,4 +85,3 @@ ban-relative-imports = "all"
8185
[tool.ruff.per-file-ignores]
8286
# Tests can use magic values, assertions, and relative imports.
8387
"tests/**/*" = ["PLR2004", "S101", "TID252"]
84-

0 commit comments

Comments
 (0)