From 2abba4986743bf680d3d9851253990ae009a73fa Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 15:35:21 +0200 Subject: [PATCH 1/8] chore: add missing changelog items Signed-off-by: Yurii Serhiichuk --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 458a1dd..d0faf91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Kafka `conversion` marshaller and unmarshaller typings ([#240]) +- Improved public API type annotations and fixed unit test type errors ([#248]) ## [1.11.0] @@ -293,3 +294,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#235]: https://github.com/cloudevents/sdk-python/pull/235 [#236]: https://github.com/cloudevents/sdk-python/pull/236 [#240]: https://github.com/cloudevents/sdk-python/pull/240 +[#248]: https://github.com/cloudevents/sdk-python/pull/248 From 39d0fbdf225de11513b0c8115227f1ec2e1c1108 Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 15:37:26 +0200 Subject: [PATCH 2/8] chore: drop Python 3.8 support Signed-off-by: Yurii Serhiichuk --- .github/workflows/main.yml | 2 +- .github/workflows/pypi-release.yml | 6 +++--- cloudevents/__init__.py | 2 +- requirements/constraints.txt | 10 ---------- requirements/mypy-constraints.txt | 9 --------- setup.py | 3 ++- tox.ini | 5 +---- 7 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 requirements/constraints.txt delete mode 100644 requirements/mypy-constraints.txt diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5eb4b8..e984dff 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: test: strategy: matrix: - python: ['3.8', '3.9', '3.10', '3.11'] + python: ['3.9', '3.10', '3.11', '3.12', '3.13'] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 2b1dbf0..52f9395 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -10,7 +10,7 @@ on: jobs: build_dist: name: Build source distribution - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: @@ -27,7 +27,7 @@ jobs: - name: Check metadata run: pipx run twine check dist/* publish: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest if: github.event_name == 'push' needs: [ build_dist ] steps: @@ -35,7 +35,7 @@ jobs: with: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" cache: 'pip' diff --git a/cloudevents/__init__.py b/cloudevents/__init__.py index d332910..e97372b 100644 --- a/cloudevents/__init__.py +++ b/cloudevents/__init__.py @@ -12,4 +12,4 @@ # License for the specific language governing permissions and limitations # under the License. -__version__ = "1.11.1" +__version__ = "1.12.0" diff --git a/requirements/constraints.txt b/requirements/constraints.txt deleted file mode 100644 index 648d97e..0000000 --- a/requirements/constraints.txt +++ /dev/null @@ -1,10 +0,0 @@ -# This is a requirements constraint file, see: -# https://pip.pypa.io/en/stable/user_guide/#constraints-files - -# sanic stopped supporting 3.8 in 24.12: -# https://sanic.dev/en/release-notes/changelog.html#version-24120- -sanic<24.12.0 ; python_version == '3.8' - -# pydantic stopped supporting 3.8 in 2.11.0: -# https://github.com/pydantic/pydantic/releases/tag/v2.11.0 -pydantic<2.11.0 ; python_version == '3.8' diff --git a/requirements/mypy-constraints.txt b/requirements/mypy-constraints.txt deleted file mode 100644 index 82c5f95..0000000 --- a/requirements/mypy-constraints.txt +++ /dev/null @@ -1,9 +0,0 @@ -# This is a requirements constraint file, see: -# https://pip.pypa.io/en/stable/user_guide/#constraints-files - -# Because we run mypy in python 3.8 compatibility mode, dependencies must be -# versions that support 3.8. - -# pydantic stopped supporting 3.8 in 2.11.0: -# https://github.com/pydantic/pydantic/releases/tag/v2.11.0 -pydantic<2.11.0 diff --git a/setup.py b/setup.py index a4e4bef..f424997 100644 --- a/setup.py +++ b/setup.py @@ -65,10 +65,11 @@ def get_version(rel_path): "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Typing :: Typed", ], keywords="CloudEvents Eventing Serverless", diff --git a/tox.ini b/tox.ini index 88f0bd1..9779cc8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{38,39,310,311,312},lint,mypy,mypy-samples-{image,json} +envlist = py{39,310,311,312,313},lint,mypy,mypy-samples-{image,json} skipsdist = True [testenv] @@ -8,7 +8,6 @@ deps = -r{toxinidir}/requirements/test.txt -r{toxinidir}/requirements/publish.txt setenv = - PIP_CONSTRAINT={toxinidir}/requirements/constraints.txt PYTESTARGS = -v -s --tb=long --cov=cloudevents --cov-report term-missing --cov-fail-under=95 commands = pytest {env:PYTESTARGS} {posargs} @@ -34,8 +33,6 @@ commands = [testenv:mypy] basepython = python3.11 -setenv = - PIP_CONSTRAINT={toxinidir}/requirements/mypy-constraints.txt deps = -r{toxinidir}/requirements/mypy.txt # mypy needs test dependencies to check test modules From 2b369b7c994be691bef6bf56f21c81f4ecea7890 Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 15:47:21 +0200 Subject: [PATCH 3/8] chore: add a changelog item on Python 3.8 removal Signed-off-by: Yurii Serhiichuk --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0faf91..4702388 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.12.0] + +### Changed + +- Dropped Python3.8 support while it has reached EOL. ([]) + ## [1.11.1] ### Fixed From ffd96952340f19713c90f7ca16840340a556d7d1 Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 15:48:41 +0200 Subject: [PATCH 4/8] chore: remove mypy-constrains reference as we don't need it anymore Signed-off-by: Yurii Serhiichuk --- tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tox.ini b/tox.ini index 9779cc8..bfd8fde 100644 --- a/tox.ini +++ b/tox.ini @@ -42,7 +42,6 @@ commands = mypy cloudevents [testenv:mypy-samples-{image,json}] basepython = python3.11 setenv = - PIP_CONSTRAINT={toxinidir}/requirements/mypy-constraints.txt mypy-samples-image: SAMPLE_DIR={toxinidir}/samples/http-image-cloudevents mypy-samples-json: SAMPLE_DIR={toxinidir}/samples/http-json-cloudevents deps = From 8b9fd969be92f4f3c838b2e1c2f9d3471d8871e8 Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 15:53:35 +0200 Subject: [PATCH 5/8] chore: Update pre-commit check versions. Signed-off-by: Yurii Serhiichuk --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75ad2ef..32fde35 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,22 +1,22 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-toml - repo: https://github.com/pycqa/isort - rev: 5.13.2 + rev: 6.0.1 hooks: - id: isort args: [ "--profile", "black", "--filter-files" ] - repo: https://github.com/psf/black - rev: 24.4.2 + rev: 25.1.0 hooks: - id: black language_version: python3.11 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.0 + rev: v1.16.0 hooks: - id: mypy files: ^(cloudevents/) From 98a7a81ca8b85ee93cb1cb270207d29d670f587c Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 15:55:19 +0200 Subject: [PATCH 6/8] chore: fix isort pre-commit Signed-off-by: Yurii Serhiichuk --- cloudevents/conversion.py | 3 ++- cloudevents/http/event.py | 3 ++- cloudevents/http/event_type.py | 3 +-- cloudevents/http/http_methods.py | 3 +-- cloudevents/http/json_methods.py | 3 +-- cloudevents/http/util.py | 3 +-- cloudevents/kafka/conversion.py | 5 +++-- cloudevents/pydantic/v1/event.py | 3 ++- cloudevents/pydantic/v2/event.py | 6 +++--- cloudevents/tests/test_backwards_compatability.py | 1 - cloudevents/tests/test_base_events.py | 3 +-- cloudevents/tests/test_converters.py | 1 - cloudevents/tests/test_data_encaps_refs.py | 1 - cloudevents/tests/test_deprecated_functions.py | 1 - cloudevents/tests/test_event_extensions.py | 1 - cloudevents/tests/test_event_from_request_converter.py | 1 - cloudevents/tests/test_event_pipeline.py | 1 - cloudevents/tests/test_event_to_request_converter.py | 1 - cloudevents/tests/test_http_cloudevent.py | 3 +-- cloudevents/tests/test_http_conversions.py | 1 - cloudevents/tests/test_http_events.py | 5 ++--- cloudevents/tests/test_kafka_conversions.py | 4 ++-- cloudevents/tests/test_marshaller.py | 3 +-- cloudevents/tests/test_options.py | 1 - cloudevents/tests/test_pydantic_cloudevent.py | 5 ++--- cloudevents/tests/test_pydantic_conversions.py | 5 ++--- cloudevents/tests/test_pydantic_events.py | 9 ++++----- cloudevents/tests/test_with_sanic.py | 3 +-- samples/http-image-cloudevents/client.py | 1 - samples/http-image-cloudevents/image_sample_server.py | 3 +-- samples/http-image-cloudevents/image_sample_test.py | 5 ++--- samples/http-json-cloudevents/client.py | 1 - samples/http-json-cloudevents/json_sample_server.py | 3 +-- samples/http-json-cloudevents/json_sample_test.py | 3 +-- 34 files changed, 37 insertions(+), 61 deletions(-) diff --git a/cloudevents/conversion.py b/cloudevents/conversion.py index 6b83cfe..731c114 100644 --- a/cloudevents/conversion.py +++ b/cloudevents/conversion.py @@ -16,12 +16,13 @@ import json import typing -from cloudevents import exceptions as cloud_exceptions from cloudevents.abstract import AnyCloudEvent from cloudevents.sdk import converters, marshaller, types from cloudevents.sdk.converters import is_binary from cloudevents.sdk.event import v1, v03 +from cloudevents import exceptions as cloud_exceptions + def _best_effort_serialize_to_json( # type: ignore[no-untyped-def] value: typing.Any, *args, **kwargs diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index f3c0063..4a21a8b 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -17,9 +17,10 @@ import uuid import cloudevents.exceptions as cloud_exceptions -from cloudevents import abstract from cloudevents.sdk.event import v1, v03 +from cloudevents import abstract + _required_by_version = { "1.0": v1.Event._ce_required_fields, "0.3": v03.Event._ce_required_fields, diff --git a/cloudevents/http/event_type.py b/cloudevents/http/event_type.py index 52259e1..d3c56fe 100644 --- a/cloudevents/http/event_type.py +++ b/cloudevents/http/event_type.py @@ -13,10 +13,9 @@ # under the License. import typing -from deprecation import deprecated - from cloudevents.sdk.converters import is_binary as _moved_is_binary from cloudevents.sdk.converters import is_structured as _moved_is_structured +from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/http_methods.py b/cloudevents/http/http_methods.py index 091c51b..6356616 100644 --- a/cloudevents/http/http_methods.py +++ b/cloudevents/http/http_methods.py @@ -14,14 +14,13 @@ import typing -from deprecation import deprecated - from cloudevents.abstract import AnyCloudEvent from cloudevents.conversion import to_binary as _moved_to_binary from cloudevents.conversion import to_structured as _moved_to_structured from cloudevents.http.conversion import from_http as _moved_from_http from cloudevents.http.event import CloudEvent from cloudevents.sdk import types +from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/json_methods.py b/cloudevents/http/json_methods.py index 58e322c..8899361 100644 --- a/cloudevents/http/json_methods.py +++ b/cloudevents/http/json_methods.py @@ -14,13 +14,12 @@ import typing -from deprecation import deprecated - from cloudevents.abstract import AnyCloudEvent from cloudevents.conversion import to_json as _moved_to_json from cloudevents.http import CloudEvent from cloudevents.http.conversion import from_json as _moved_from_json from cloudevents.sdk import types +from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/util.py b/cloudevents/http/util.py index f44395e..56fbc34 100644 --- a/cloudevents/http/util.py +++ b/cloudevents/http/util.py @@ -13,11 +13,10 @@ # under the License. import typing -from deprecation import deprecated - from cloudevents.conversion import ( _best_effort_serialize_to_json as _moved_default_marshaller, ) +from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/kafka/conversion.py b/cloudevents/kafka/conversion.py index bdf2aca..b028bac 100644 --- a/cloudevents/kafka/conversion.py +++ b/cloudevents/kafka/conversion.py @@ -15,12 +15,13 @@ import json import typing -from cloudevents import exceptions as cloud_exceptions -from cloudevents import http from cloudevents.abstract import AnyCloudEvent from cloudevents.kafka.exceptions import KeyMapperError from cloudevents.sdk import types +from cloudevents import exceptions as cloud_exceptions +from cloudevents import http + JSON_MARSHALLER: types.MarshallerType = json.dumps JSON_UNMARSHALLER: types.UnmarshallerType = json.loads IDENTITY_MARSHALLER = IDENTITY_UNMARSHALLER = lambda x: x diff --git a/cloudevents/pydantic/v1/event.py b/cloudevents/pydantic/v1/event.py index 98c6136..18f95fd 100644 --- a/cloudevents/pydantic/v1/event.py +++ b/cloudevents/pydantic/v1/event.py @@ -32,10 +32,11 @@ "Install it using pip install cloudevents[pydantic]" ) -from cloudevents import abstract, conversion, http from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.sdk.event import attribute +from cloudevents import abstract, conversion, http + def _ce_json_dumps( # type: ignore[no-untyped-def] obj: typing.Dict[str, typing.Any], diff --git a/cloudevents/pydantic/v2/event.py b/cloudevents/pydantic/v2/event.py index 34a9b65..8afead7 100644 --- a/cloudevents/pydantic/v2/event.py +++ b/cloudevents/pydantic/v2/event.py @@ -17,10 +17,9 @@ import typing from typing import Any -from pydantic.deprecated import parse as _deprecated_parse - from cloudevents.exceptions import PydanticFeatureNotInstalled from cloudevents.pydantic.fields_docs import FIELD_DESCRIPTIONS +from pydantic.deprecated import parse as _deprecated_parse try: from pydantic import BaseModel, ConfigDict, Field, model_serializer @@ -30,10 +29,11 @@ "Install it using pip install cloudevents[pydantic]" ) -from cloudevents import abstract, conversion from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.sdk.event import attribute +from cloudevents import abstract, conversion + class CloudEvent(abstract.CloudEvent, BaseModel): # type: ignore """ diff --git a/cloudevents/tests/test_backwards_compatability.py b/cloudevents/tests/test_backwards_compatability.py index 0a20f4c..4b3fecc 100644 --- a/cloudevents/tests/test_backwards_compatability.py +++ b/cloudevents/tests/test_backwards_compatability.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. import pytest - from cloudevents.conversion import _best_effort_serialize_to_json from cloudevents.http import CloudEvent diff --git a/cloudevents/tests/test_base_events.py b/cloudevents/tests/test_base_events.py index 8eb83d4..49a9894 100644 --- a/cloudevents/tests/test_base_events.py +++ b/cloudevents/tests/test_base_events.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import pytest - import cloudevents.exceptions as cloud_exceptions +import pytest from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_converters.py b/cloudevents/tests/test_converters.py index 50d783b..155d55b 100644 --- a/cloudevents/tests/test_converters.py +++ b/cloudevents/tests/test_converters.py @@ -13,7 +13,6 @@ # under the License. import pytest - from cloudevents.sdk import exceptions from cloudevents.sdk.converters import base, binary diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py index 02405a9..c745c5b 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -16,7 +16,6 @@ from uuid import uuid4 import pytest - from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1, v03 from cloudevents.tests import data diff --git a/cloudevents/tests/test_deprecated_functions.py b/cloudevents/tests/test_deprecated_functions.py index a99f624..c4deecd 100644 --- a/cloudevents/tests/test_deprecated_functions.py +++ b/cloudevents/tests/test_deprecated_functions.py @@ -13,7 +13,6 @@ # under the License. import pytest - from cloudevents.http import ( CloudEvent, to_binary, diff --git a/cloudevents/tests/test_event_extensions.py b/cloudevents/tests/test_event_extensions.py index eea8edf..d50dc3a 100644 --- a/cloudevents/tests/test_event_extensions.py +++ b/cloudevents/tests/test_event_extensions.py @@ -15,7 +15,6 @@ import json import pytest - from cloudevents.http import CloudEvent, from_http, to_binary, to_structured test_data = json.dumps({"data-key": "val"}) diff --git a/cloudevents/tests/test_event_from_request_converter.py b/cloudevents/tests/test_event_from_request_converter.py index 362b1ca..78d44ba 100644 --- a/cloudevents/tests/test_event_from_request_converter.py +++ b/cloudevents/tests/test_event_from_request_converter.py @@ -15,7 +15,6 @@ import json import pytest - from cloudevents.sdk import marshaller from cloudevents.sdk.converters import binary, structured from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_event_pipeline.py b/cloudevents/tests/test_event_pipeline.py index dae3dc2..2b08b0c 100644 --- a/cloudevents/tests/test_event_pipeline.py +++ b/cloudevents/tests/test_event_pipeline.py @@ -15,7 +15,6 @@ import json import pytest - from cloudevents.sdk import converters, marshaller from cloudevents.sdk.converters import structured from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_event_to_request_converter.py b/cloudevents/tests/test_event_to_request_converter.py index fd25be5..c101912 100644 --- a/cloudevents/tests/test_event_to_request_converter.py +++ b/cloudevents/tests/test_event_to_request_converter.py @@ -15,7 +15,6 @@ import json import pytest - from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1, v03 from cloudevents.tests import data diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index 6ad1537..113a8bb 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import pytest - import cloudevents.exceptions as cloud_exceptions +import pytest from cloudevents.conversion import _json_or_string from cloudevents.http import CloudEvent diff --git a/cloudevents/tests/test_http_conversions.py b/cloudevents/tests/test_http_conversions.py index 3b9c671..e7072e9 100644 --- a/cloudevents/tests/test_http_conversions.py +++ b/cloudevents/tests/test_http_conversions.py @@ -17,7 +17,6 @@ import json import pytest - from cloudevents.conversion import to_dict, to_json from cloudevents.http import CloudEvent, from_dict, from_json from cloudevents.sdk.event.attribute import SpecVersion diff --git a/cloudevents/tests/test_http_events.py b/cloudevents/tests/test_http_events.py index 3d4c8d5..5045dc5 100644 --- a/cloudevents/tests/test_http_events.py +++ b/cloudevents/tests/test_http_events.py @@ -18,16 +18,15 @@ import json import typing -import pytest -from sanic import Sanic, response - import cloudevents.exceptions as cloud_exceptions +import pytest from cloudevents.http import CloudEvent, from_http, to_binary, to_structured from cloudevents.http.event_type import is_binary as deprecated_is_binary from cloudevents.http.event_type import is_structured as deprecated_is_structured from cloudevents.sdk import converters from cloudevents.sdk.converters.binary import is_binary from cloudevents.sdk.converters.structured import is_structured +from sanic import Sanic, response invalid_test_headers = [ { diff --git a/cloudevents/tests/test_kafka_conversions.py b/cloudevents/tests/test_kafka_conversions.py index 584a05e..715aee8 100644 --- a/cloudevents/tests/test_kafka_conversions.py +++ b/cloudevents/tests/test_kafka_conversions.py @@ -17,8 +17,6 @@ import json import pytest - -from cloudevents import exceptions as cloud_exceptions from cloudevents.abstract.event import AnyCloudEvent from cloudevents.http import CloudEvent from cloudevents.kafka.conversion import ( @@ -31,6 +29,8 @@ from cloudevents.kafka.exceptions import KeyMapperError from cloudevents.sdk import types +from cloudevents import exceptions as cloud_exceptions + def simple_serialize(data: dict) -> bytes: return bytes(json.dumps(data).encode("utf-8")) diff --git a/cloudevents/tests/test_marshaller.py b/cloudevents/tests/test_marshaller.py index 6561418..2c9026e 100644 --- a/cloudevents/tests/test_marshaller.py +++ b/cloudevents/tests/test_marshaller.py @@ -14,9 +14,8 @@ import json -import pytest - import cloudevents.exceptions as cloud_exceptions +import pytest from cloudevents.http import CloudEvent, from_http, to_binary, to_structured from cloudevents.sdk import exceptions, marshaller from cloudevents.sdk.converters import binary, structured diff --git a/cloudevents/tests/test_options.py b/cloudevents/tests/test_options.py index aba812b..4815c56 100644 --- a/cloudevents/tests/test_options.py +++ b/cloudevents/tests/test_options.py @@ -13,7 +13,6 @@ # under the License. import pytest - from cloudevents.sdk.event.opt import Option diff --git a/cloudevents/tests/test_pydantic_cloudevent.py b/cloudevents/tests/test_pydantic_cloudevent.py index 87ac550..329cf93 100644 --- a/cloudevents/tests/test_pydantic_cloudevent.py +++ b/cloudevents/tests/test_pydantic_cloudevent.py @@ -15,14 +15,13 @@ from json import loads import pytest -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError - from cloudevents.conversion import _json_or_string from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk.event.attribute import SpecVersion +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError _DUMMY_SOURCE = "dummy:source" _DUMMY_TYPE = "tests.cloudevents.override" diff --git a/cloudevents/tests/test_pydantic_conversions.py b/cloudevents/tests/test_pydantic_conversions.py index 801b76b..44ff7ac 100644 --- a/cloudevents/tests/test_pydantic_conversions.py +++ b/cloudevents/tests/test_pydantic_conversions.py @@ -17,9 +17,6 @@ import json import pytest -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError - from cloudevents.conversion import to_json from cloudevents.pydantic.v1.conversion import from_dict as pydantic_v1_from_dict from cloudevents.pydantic.v1.conversion import from_json as pydantic_v1_from_json @@ -28,6 +25,8 @@ from cloudevents.pydantic.v2.conversion import from_json as pydantic_v2_from_json from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk.event.attribute import SpecVersion +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError test_data = json.dumps({"data-key": "val"}) test_attributes = { diff --git a/cloudevents/tests/test_pydantic_events.py b/cloudevents/tests/test_pydantic_events.py index 30ad1fe..98416cb 100644 --- a/cloudevents/tests/test_pydantic_events.py +++ b/cloudevents/tests/test_pydantic_events.py @@ -18,12 +18,8 @@ import json import typing -import pytest -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError -from sanic import Sanic, response - import cloudevents.exceptions as cloud_exceptions +import pytest from cloudevents.conversion import to_binary, to_structured from cloudevents.pydantic.v1.conversion import from_http as pydantic_v1_from_http from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent @@ -32,6 +28,9 @@ from cloudevents.sdk import converters, types from cloudevents.sdk.converters.binary import is_binary from cloudevents.sdk.converters.structured import is_structured +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError +from sanic import Sanic, response if typing.TYPE_CHECKING: from typing_extensions import TypeAlias diff --git a/cloudevents/tests/test_with_sanic.py b/cloudevents/tests/test_with_sanic.py index 026f55b..c433782 100644 --- a/cloudevents/tests/test_with_sanic.py +++ b/cloudevents/tests/test_with_sanic.py @@ -12,11 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -from sanic import Sanic, response - from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1 from cloudevents.tests import data as test_data +from sanic import Sanic, response m = marshaller.NewDefaultHTTPMarshaller() app = Sanic("test_with_sanic") diff --git a/samples/http-image-cloudevents/client.py b/samples/http-image-cloudevents/client.py index ee00394..d928de5 100644 --- a/samples/http-image-cloudevents/client.py +++ b/samples/http-image-cloudevents/client.py @@ -15,7 +15,6 @@ import sys import requests - from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent diff --git a/samples/http-image-cloudevents/image_sample_server.py b/samples/http-image-cloudevents/image_sample_server.py index da30302..fc1a637 100644 --- a/samples/http-image-cloudevents/image_sample_server.py +++ b/samples/http-image-cloudevents/image_sample_server.py @@ -14,11 +14,10 @@ import io +from cloudevents.http import from_http from flask import Flask, request from PIL import Image -from cloudevents.http import from_http - app = Flask(__name__) diff --git a/samples/http-image-cloudevents/image_sample_test.py b/samples/http-image-cloudevents/image_sample_test.py index 5fe6ec9..3460874 100644 --- a/samples/http-image-cloudevents/image_sample_test.py +++ b/samples/http-image-cloudevents/image_sample_test.py @@ -18,11 +18,10 @@ import pytest from client import image_bytes -from image_sample_server import app -from PIL import Image - from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent, from_http +from image_sample_server import app +from PIL import Image image_fileobj = io.BytesIO(image_bytes) image_expected_shape = (1880, 363) diff --git a/samples/http-json-cloudevents/client.py b/samples/http-json-cloudevents/client.py index 5ecc379..b1822a4 100644 --- a/samples/http-json-cloudevents/client.py +++ b/samples/http-json-cloudevents/client.py @@ -15,7 +15,6 @@ import sys import requests - from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent diff --git a/samples/http-json-cloudevents/json_sample_server.py b/samples/http-json-cloudevents/json_sample_server.py index c3a399e..ae0d912 100644 --- a/samples/http-json-cloudevents/json_sample_server.py +++ b/samples/http-json-cloudevents/json_sample_server.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -from flask import Flask, request - from cloudevents.http import from_http +from flask import Flask, request app = Flask(__name__) diff --git a/samples/http-json-cloudevents/json_sample_test.py b/samples/http-json-cloudevents/json_sample_test.py index 1d92874..bb94331 100644 --- a/samples/http-json-cloudevents/json_sample_test.py +++ b/samples/http-json-cloudevents/json_sample_test.py @@ -13,10 +13,9 @@ # under the License. import pytest -from json_sample_server import app - from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent +from json_sample_server import app @pytest.fixture From 971dbb4c40920c100ee0688d8c584e92271f2c9e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 31 May 2025 13:55:48 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cloudevents/conversion.py | 3 +-- cloudevents/http/event.py | 3 +-- cloudevents/http/event_type.py | 3 ++- cloudevents/http/http_methods.py | 3 ++- cloudevents/http/json_methods.py | 3 ++- cloudevents/http/util.py | 3 ++- cloudevents/kafka/conversion.py | 5 ++--- cloudevents/pydantic/v1/event.py | 3 +-- cloudevents/pydantic/v2/event.py | 6 +++--- cloudevents/tests/test_backwards_compatability.py | 1 + cloudevents/tests/test_base_events.py | 3 ++- cloudevents/tests/test_converters.py | 1 + cloudevents/tests/test_data_encaps_refs.py | 1 + cloudevents/tests/test_deprecated_functions.py | 1 + cloudevents/tests/test_event_extensions.py | 1 + cloudevents/tests/test_event_from_request_converter.py | 1 + cloudevents/tests/test_event_pipeline.py | 1 + cloudevents/tests/test_event_to_request_converter.py | 1 + cloudevents/tests/test_http_cloudevent.py | 3 ++- cloudevents/tests/test_http_conversions.py | 1 + cloudevents/tests/test_http_events.py | 5 +++-- cloudevents/tests/test_kafka_conversions.py | 4 ++-- cloudevents/tests/test_marshaller.py | 3 ++- cloudevents/tests/test_options.py | 1 + cloudevents/tests/test_pydantic_cloudevent.py | 5 +++-- cloudevents/tests/test_pydantic_conversions.py | 5 +++-- cloudevents/tests/test_pydantic_events.py | 9 +++++---- cloudevents/tests/test_with_sanic.py | 3 ++- samples/http-image-cloudevents/client.py | 1 + samples/http-image-cloudevents/image_sample_server.py | 3 ++- samples/http-image-cloudevents/image_sample_test.py | 5 +++-- samples/http-json-cloudevents/client.py | 1 + samples/http-json-cloudevents/json_sample_server.py | 3 ++- samples/http-json-cloudevents/json_sample_test.py | 3 ++- 34 files changed, 61 insertions(+), 37 deletions(-) diff --git a/cloudevents/conversion.py b/cloudevents/conversion.py index 731c114..6b83cfe 100644 --- a/cloudevents/conversion.py +++ b/cloudevents/conversion.py @@ -16,13 +16,12 @@ import json import typing +from cloudevents import exceptions as cloud_exceptions from cloudevents.abstract import AnyCloudEvent from cloudevents.sdk import converters, marshaller, types from cloudevents.sdk.converters import is_binary from cloudevents.sdk.event import v1, v03 -from cloudevents import exceptions as cloud_exceptions - def _best_effort_serialize_to_json( # type: ignore[no-untyped-def] value: typing.Any, *args, **kwargs diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index 4a21a8b..f3c0063 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -17,9 +17,8 @@ import uuid import cloudevents.exceptions as cloud_exceptions -from cloudevents.sdk.event import v1, v03 - from cloudevents import abstract +from cloudevents.sdk.event import v1, v03 _required_by_version = { "1.0": v1.Event._ce_required_fields, diff --git a/cloudevents/http/event_type.py b/cloudevents/http/event_type.py index d3c56fe..52259e1 100644 --- a/cloudevents/http/event_type.py +++ b/cloudevents/http/event_type.py @@ -13,9 +13,10 @@ # under the License. import typing +from deprecation import deprecated + from cloudevents.sdk.converters import is_binary as _moved_is_binary from cloudevents.sdk.converters import is_structured as _moved_is_structured -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/http_methods.py b/cloudevents/http/http_methods.py index 6356616..091c51b 100644 --- a/cloudevents/http/http_methods.py +++ b/cloudevents/http/http_methods.py @@ -14,13 +14,14 @@ import typing +from deprecation import deprecated + from cloudevents.abstract import AnyCloudEvent from cloudevents.conversion import to_binary as _moved_to_binary from cloudevents.conversion import to_structured as _moved_to_structured from cloudevents.http.conversion import from_http as _moved_from_http from cloudevents.http.event import CloudEvent from cloudevents.sdk import types -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/json_methods.py b/cloudevents/http/json_methods.py index 8899361..58e322c 100644 --- a/cloudevents/http/json_methods.py +++ b/cloudevents/http/json_methods.py @@ -14,12 +14,13 @@ import typing +from deprecation import deprecated + from cloudevents.abstract import AnyCloudEvent from cloudevents.conversion import to_json as _moved_to_json from cloudevents.http import CloudEvent from cloudevents.http.conversion import from_json as _moved_from_json from cloudevents.sdk import types -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/http/util.py b/cloudevents/http/util.py index 56fbc34..f44395e 100644 --- a/cloudevents/http/util.py +++ b/cloudevents/http/util.py @@ -13,10 +13,11 @@ # under the License. import typing +from deprecation import deprecated + from cloudevents.conversion import ( _best_effort_serialize_to_json as _moved_default_marshaller, ) -from deprecation import deprecated # THIS MODULE IS DEPRECATED, YOU SHOULD NOT ADD NEW FUNCTIONALLY HERE diff --git a/cloudevents/kafka/conversion.py b/cloudevents/kafka/conversion.py index b028bac..bdf2aca 100644 --- a/cloudevents/kafka/conversion.py +++ b/cloudevents/kafka/conversion.py @@ -15,13 +15,12 @@ import json import typing +from cloudevents import exceptions as cloud_exceptions +from cloudevents import http from cloudevents.abstract import AnyCloudEvent from cloudevents.kafka.exceptions import KeyMapperError from cloudevents.sdk import types -from cloudevents import exceptions as cloud_exceptions -from cloudevents import http - JSON_MARSHALLER: types.MarshallerType = json.dumps JSON_UNMARSHALLER: types.UnmarshallerType = json.loads IDENTITY_MARSHALLER = IDENTITY_UNMARSHALLER = lambda x: x diff --git a/cloudevents/pydantic/v1/event.py b/cloudevents/pydantic/v1/event.py index 18f95fd..98c6136 100644 --- a/cloudevents/pydantic/v1/event.py +++ b/cloudevents/pydantic/v1/event.py @@ -32,11 +32,10 @@ "Install it using pip install cloudevents[pydantic]" ) +from cloudevents import abstract, conversion, http from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.sdk.event import attribute -from cloudevents import abstract, conversion, http - def _ce_json_dumps( # type: ignore[no-untyped-def] obj: typing.Dict[str, typing.Any], diff --git a/cloudevents/pydantic/v2/event.py b/cloudevents/pydantic/v2/event.py index 8afead7..34a9b65 100644 --- a/cloudevents/pydantic/v2/event.py +++ b/cloudevents/pydantic/v2/event.py @@ -17,9 +17,10 @@ import typing from typing import Any +from pydantic.deprecated import parse as _deprecated_parse + from cloudevents.exceptions import PydanticFeatureNotInstalled from cloudevents.pydantic.fields_docs import FIELD_DESCRIPTIONS -from pydantic.deprecated import parse as _deprecated_parse try: from pydantic import BaseModel, ConfigDict, Field, model_serializer @@ -29,11 +30,10 @@ "Install it using pip install cloudevents[pydantic]" ) +from cloudevents import abstract, conversion from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.sdk.event import attribute -from cloudevents import abstract, conversion - class CloudEvent(abstract.CloudEvent, BaseModel): # type: ignore """ diff --git a/cloudevents/tests/test_backwards_compatability.py b/cloudevents/tests/test_backwards_compatability.py index 4b3fecc..0a20f4c 100644 --- a/cloudevents/tests/test_backwards_compatability.py +++ b/cloudevents/tests/test_backwards_compatability.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. import pytest + from cloudevents.conversion import _best_effort_serialize_to_json from cloudevents.http import CloudEvent diff --git a/cloudevents/tests/test_base_events.py b/cloudevents/tests/test_base_events.py index 49a9894..8eb83d4 100644 --- a/cloudevents/tests/test_base_events.py +++ b/cloudevents/tests/test_base_events.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import cloudevents.exceptions as cloud_exceptions import pytest + +import cloudevents.exceptions as cloud_exceptions from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_converters.py b/cloudevents/tests/test_converters.py index 155d55b..50d783b 100644 --- a/cloudevents/tests/test_converters.py +++ b/cloudevents/tests/test_converters.py @@ -13,6 +13,7 @@ # under the License. import pytest + from cloudevents.sdk import exceptions from cloudevents.sdk.converters import base, binary diff --git a/cloudevents/tests/test_data_encaps_refs.py b/cloudevents/tests/test_data_encaps_refs.py index c745c5b..02405a9 100644 --- a/cloudevents/tests/test_data_encaps_refs.py +++ b/cloudevents/tests/test_data_encaps_refs.py @@ -16,6 +16,7 @@ from uuid import uuid4 import pytest + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1, v03 from cloudevents.tests import data diff --git a/cloudevents/tests/test_deprecated_functions.py b/cloudevents/tests/test_deprecated_functions.py index c4deecd..a99f624 100644 --- a/cloudevents/tests/test_deprecated_functions.py +++ b/cloudevents/tests/test_deprecated_functions.py @@ -13,6 +13,7 @@ # under the License. import pytest + from cloudevents.http import ( CloudEvent, to_binary, diff --git a/cloudevents/tests/test_event_extensions.py b/cloudevents/tests/test_event_extensions.py index d50dc3a..eea8edf 100644 --- a/cloudevents/tests/test_event_extensions.py +++ b/cloudevents/tests/test_event_extensions.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.http import CloudEvent, from_http, to_binary, to_structured test_data = json.dumps({"data-key": "val"}) diff --git a/cloudevents/tests/test_event_from_request_converter.py b/cloudevents/tests/test_event_from_request_converter.py index 78d44ba..362b1ca 100644 --- a/cloudevents/tests/test_event_from_request_converter.py +++ b/cloudevents/tests/test_event_from_request_converter.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.sdk import marshaller from cloudevents.sdk.converters import binary, structured from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_event_pipeline.py b/cloudevents/tests/test_event_pipeline.py index 2b08b0c..dae3dc2 100644 --- a/cloudevents/tests/test_event_pipeline.py +++ b/cloudevents/tests/test_event_pipeline.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.converters import structured from cloudevents.sdk.event import v1, v03 diff --git a/cloudevents/tests/test_event_to_request_converter.py b/cloudevents/tests/test_event_to_request_converter.py index c101912..fd25be5 100644 --- a/cloudevents/tests/test_event_to_request_converter.py +++ b/cloudevents/tests/test_event_to_request_converter.py @@ -15,6 +15,7 @@ import json import pytest + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1, v03 from cloudevents.tests import data diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index 113a8bb..6ad1537 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import cloudevents.exceptions as cloud_exceptions import pytest + +import cloudevents.exceptions as cloud_exceptions from cloudevents.conversion import _json_or_string from cloudevents.http import CloudEvent diff --git a/cloudevents/tests/test_http_conversions.py b/cloudevents/tests/test_http_conversions.py index e7072e9..3b9c671 100644 --- a/cloudevents/tests/test_http_conversions.py +++ b/cloudevents/tests/test_http_conversions.py @@ -17,6 +17,7 @@ import json import pytest + from cloudevents.conversion import to_dict, to_json from cloudevents.http import CloudEvent, from_dict, from_json from cloudevents.sdk.event.attribute import SpecVersion diff --git a/cloudevents/tests/test_http_events.py b/cloudevents/tests/test_http_events.py index 5045dc5..3d4c8d5 100644 --- a/cloudevents/tests/test_http_events.py +++ b/cloudevents/tests/test_http_events.py @@ -18,15 +18,16 @@ import json import typing -import cloudevents.exceptions as cloud_exceptions import pytest +from sanic import Sanic, response + +import cloudevents.exceptions as cloud_exceptions from cloudevents.http import CloudEvent, from_http, to_binary, to_structured from cloudevents.http.event_type import is_binary as deprecated_is_binary from cloudevents.http.event_type import is_structured as deprecated_is_structured from cloudevents.sdk import converters from cloudevents.sdk.converters.binary import is_binary from cloudevents.sdk.converters.structured import is_structured -from sanic import Sanic, response invalid_test_headers = [ { diff --git a/cloudevents/tests/test_kafka_conversions.py b/cloudevents/tests/test_kafka_conversions.py index 715aee8..584a05e 100644 --- a/cloudevents/tests/test_kafka_conversions.py +++ b/cloudevents/tests/test_kafka_conversions.py @@ -17,6 +17,8 @@ import json import pytest + +from cloudevents import exceptions as cloud_exceptions from cloudevents.abstract.event import AnyCloudEvent from cloudevents.http import CloudEvent from cloudevents.kafka.conversion import ( @@ -29,8 +31,6 @@ from cloudevents.kafka.exceptions import KeyMapperError from cloudevents.sdk import types -from cloudevents import exceptions as cloud_exceptions - def simple_serialize(data: dict) -> bytes: return bytes(json.dumps(data).encode("utf-8")) diff --git a/cloudevents/tests/test_marshaller.py b/cloudevents/tests/test_marshaller.py index 2c9026e..6561418 100644 --- a/cloudevents/tests/test_marshaller.py +++ b/cloudevents/tests/test_marshaller.py @@ -14,8 +14,9 @@ import json -import cloudevents.exceptions as cloud_exceptions import pytest + +import cloudevents.exceptions as cloud_exceptions from cloudevents.http import CloudEvent, from_http, to_binary, to_structured from cloudevents.sdk import exceptions, marshaller from cloudevents.sdk.converters import binary, structured diff --git a/cloudevents/tests/test_options.py b/cloudevents/tests/test_options.py index 4815c56..aba812b 100644 --- a/cloudevents/tests/test_options.py +++ b/cloudevents/tests/test_options.py @@ -13,6 +13,7 @@ # under the License. import pytest + from cloudevents.sdk.event.opt import Option diff --git a/cloudevents/tests/test_pydantic_cloudevent.py b/cloudevents/tests/test_pydantic_cloudevent.py index 329cf93..87ac550 100644 --- a/cloudevents/tests/test_pydantic_cloudevent.py +++ b/cloudevents/tests/test_pydantic_cloudevent.py @@ -15,13 +15,14 @@ from json import loads import pytest +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError + from cloudevents.conversion import _json_or_string from cloudevents.exceptions import IncompatibleArgumentsError from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk.event.attribute import SpecVersion -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError _DUMMY_SOURCE = "dummy:source" _DUMMY_TYPE = "tests.cloudevents.override" diff --git a/cloudevents/tests/test_pydantic_conversions.py b/cloudevents/tests/test_pydantic_conversions.py index 44ff7ac..801b76b 100644 --- a/cloudevents/tests/test_pydantic_conversions.py +++ b/cloudevents/tests/test_pydantic_conversions.py @@ -17,6 +17,9 @@ import json import pytest +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError + from cloudevents.conversion import to_json from cloudevents.pydantic.v1.conversion import from_dict as pydantic_v1_from_dict from cloudevents.pydantic.v1.conversion import from_json as pydantic_v1_from_json @@ -25,8 +28,6 @@ from cloudevents.pydantic.v2.conversion import from_json as pydantic_v2_from_json from cloudevents.pydantic.v2.event import CloudEvent as PydanticV2CloudEvent from cloudevents.sdk.event.attribute import SpecVersion -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError test_data = json.dumps({"data-key": "val"}) test_attributes = { diff --git a/cloudevents/tests/test_pydantic_events.py b/cloudevents/tests/test_pydantic_events.py index 98416cb..30ad1fe 100644 --- a/cloudevents/tests/test_pydantic_events.py +++ b/cloudevents/tests/test_pydantic_events.py @@ -18,8 +18,12 @@ import json import typing -import cloudevents.exceptions as cloud_exceptions import pytest +from pydantic import ValidationError as PydanticV2ValidationError +from pydantic.v1 import ValidationError as PydanticV1ValidationError +from sanic import Sanic, response + +import cloudevents.exceptions as cloud_exceptions from cloudevents.conversion import to_binary, to_structured from cloudevents.pydantic.v1.conversion import from_http as pydantic_v1_from_http from cloudevents.pydantic.v1.event import CloudEvent as PydanticV1CloudEvent @@ -28,9 +32,6 @@ from cloudevents.sdk import converters, types from cloudevents.sdk.converters.binary import is_binary from cloudevents.sdk.converters.structured import is_structured -from pydantic import ValidationError as PydanticV2ValidationError -from pydantic.v1 import ValidationError as PydanticV1ValidationError -from sanic import Sanic, response if typing.TYPE_CHECKING: from typing_extensions import TypeAlias diff --git a/cloudevents/tests/test_with_sanic.py b/cloudevents/tests/test_with_sanic.py index c433782..026f55b 100644 --- a/cloudevents/tests/test_with_sanic.py +++ b/cloudevents/tests/test_with_sanic.py @@ -12,10 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +from sanic import Sanic, response + from cloudevents.sdk import converters, marshaller from cloudevents.sdk.event import v1 from cloudevents.tests import data as test_data -from sanic import Sanic, response m = marshaller.NewDefaultHTTPMarshaller() app = Sanic("test_with_sanic") diff --git a/samples/http-image-cloudevents/client.py b/samples/http-image-cloudevents/client.py index d928de5..ee00394 100644 --- a/samples/http-image-cloudevents/client.py +++ b/samples/http-image-cloudevents/client.py @@ -15,6 +15,7 @@ import sys import requests + from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent diff --git a/samples/http-image-cloudevents/image_sample_server.py b/samples/http-image-cloudevents/image_sample_server.py index fc1a637..da30302 100644 --- a/samples/http-image-cloudevents/image_sample_server.py +++ b/samples/http-image-cloudevents/image_sample_server.py @@ -14,10 +14,11 @@ import io -from cloudevents.http import from_http from flask import Flask, request from PIL import Image +from cloudevents.http import from_http + app = Flask(__name__) diff --git a/samples/http-image-cloudevents/image_sample_test.py b/samples/http-image-cloudevents/image_sample_test.py index 3460874..5fe6ec9 100644 --- a/samples/http-image-cloudevents/image_sample_test.py +++ b/samples/http-image-cloudevents/image_sample_test.py @@ -18,11 +18,12 @@ import pytest from client import image_bytes -from cloudevents.conversion import to_binary, to_structured -from cloudevents.http import CloudEvent, from_http from image_sample_server import app from PIL import Image +from cloudevents.conversion import to_binary, to_structured +from cloudevents.http import CloudEvent, from_http + image_fileobj = io.BytesIO(image_bytes) image_expected_shape = (1880, 363) diff --git a/samples/http-json-cloudevents/client.py b/samples/http-json-cloudevents/client.py index b1822a4..5ecc379 100644 --- a/samples/http-json-cloudevents/client.py +++ b/samples/http-json-cloudevents/client.py @@ -15,6 +15,7 @@ import sys import requests + from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent diff --git a/samples/http-json-cloudevents/json_sample_server.py b/samples/http-json-cloudevents/json_sample_server.py index ae0d912..c3a399e 100644 --- a/samples/http-json-cloudevents/json_sample_server.py +++ b/samples/http-json-cloudevents/json_sample_server.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -from cloudevents.http import from_http from flask import Flask, request +from cloudevents.http import from_http + app = Flask(__name__) diff --git a/samples/http-json-cloudevents/json_sample_test.py b/samples/http-json-cloudevents/json_sample_test.py index bb94331..1d92874 100644 --- a/samples/http-json-cloudevents/json_sample_test.py +++ b/samples/http-json-cloudevents/json_sample_test.py @@ -13,9 +13,10 @@ # under the License. import pytest +from json_sample_server import app + from cloudevents.conversion import to_binary, to_structured from cloudevents.http import CloudEvent -from json_sample_server import app @pytest.fixture From 705e7cce837f12f81091db80f7139160a8c261c8 Mon Sep 17 00:00:00 2001 From: Yurii Serhiichuk Date: Sat, 31 May 2025 16:02:04 +0200 Subject: [PATCH 8/8] chore: Use Python 3.12 as base version Signed-off-by: Yurii Serhiichuk --- .github/workflows/main.yml | 2 +- .github/workflows/pypi-release.yml | 2 +- tox.ini | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e984dff..52e7c9a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' cache: 'pip' cache-dependency-path: 'requirements/*.txt' - name: Install dev dependencies diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 52f9395..eeebb88 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -37,7 +37,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" cache: 'pip' - name: Install build dependencies run: pip install -U setuptools wheel build diff --git a/tox.ini b/tox.ini index bfd8fde..d5f1d98 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,7 @@ setenv = commands = pytest {env:PYTESTARGS} {posargs} [testenv:reformat] -basepython = python3.11 +basepython = python3.12 deps = black isort @@ -21,7 +21,7 @@ commands = isort cloudevents samples [testenv:lint] -basepython = python3.11 +basepython = python3.12 deps = black isort @@ -32,7 +32,7 @@ commands = flake8 cloudevents samples --ignore W503,E731 --extend-ignore E203 --max-line-length 88 [testenv:mypy] -basepython = python3.11 +basepython = python3.12 deps = -r{toxinidir}/requirements/mypy.txt # mypy needs test dependencies to check test modules @@ -40,7 +40,7 @@ deps = commands = mypy cloudevents [testenv:mypy-samples-{image,json}] -basepython = python3.11 +basepython = python3.12 setenv = mypy-samples-image: SAMPLE_DIR={toxinidir}/samples/http-image-cloudevents mypy-samples-json: SAMPLE_DIR={toxinidir}/samples/http-json-cloudevents