Skip to content

Commit 042bc13

Browse files
committed
python sdk cloudevents 2.*
1 parent c45e172 commit 042bc13

9 files changed

Lines changed: 7226 additions & 7225 deletions

File tree

e2e/testdata/templates-userdeps/python/http/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "function"
33
version = "0.1.0"
4-
requires-python = ">=3.9"
4+
requires-python = ">=3.10"
55
license = "MIT"
66

77
[build-system]

e2e/testdata/templates/python/http/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "function"
33
description = ""
44
version = "0.1.0"
5-
requires-python = ">=3.9"
5+
requires-python = ">=3.10"
66
readme = "README.md"
77
license = "MIT"
88
dependencies = [

generate/zz_filesystem_generated.go

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

templates/python/cloudevents/function/func.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Function
22
import logging
3-
from cloudevents.http import CloudEvent
3+
from cloudevents.core.v1.event import CloudEvent
44

55

66
def new():
@@ -33,16 +33,16 @@ async def handle(self, scope, receive, send):
3333
request = scope["event"]
3434

3535
# 2) Create a new CloudEvent as response with "OK" as data
36-
response = CloudEvent({
37-
"type": "function.response",
38-
"source": "function",
39-
"id": f"response-{request.get('id', 'unknown')}"
40-
})
36+
response = CloudEvent(
37+
attributes={
38+
"type": "function.response",
39+
"source": "function",
40+
"id": f"response-{request.get_id() or 'unknown'}"
41+
},
42+
data={"message": "OK"}
43+
)
4144

42-
# 3) Set the response's data field to {"message": "OK"}
43-
response.data = {"message": "OK"}
44-
45-
# 4) Send the response CloudEvent
45+
# 3) Send the response CloudEvent
4646
# The 'send' method is already decorated with CloudEvent middleware
4747
await send(response)
4848

templates/python/cloudevents/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
name = "function"
33
description = ""
44
version = "0.1.0"
5-
requires-python = ">=3.9"
5+
requires-python = ">=3.10"
66
readme = "README.md"
77
license = "MIT"
88
dependencies = [
99
"httpx",
10-
"cloudevents>=1.11,<2",
10+
"cloudevents>=2,<3",
1111
"pytest",
1212
"pytest-asyncio"
1313
]

templates/python/cloudevents/tests/test_func.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import json
1111
import asyncio
1212
import pytest
13-
from cloudevents.http import CloudEvent
13+
from cloudevents.core.v1.event import CloudEvent
1414
from function import new
1515

1616

@@ -25,7 +25,7 @@ async def test_func():
2525
"source": "https://example.com/event-producer",
2626
}
2727
data = {"message": "test message"}
28-
event = CloudEvent(attributes, data)
28+
event = CloudEvent(attributes=attributes, data=data)
2929

3030
invoked = False # Flag indicating send method was invoked
3131

@@ -40,7 +40,7 @@ async def send(e):
4040

4141
# Ensure it returns {"message": "OK"} as data
4242
expected = {"message": "OK"}
43-
assert e.data == expected, f"Expected data {expected}, got {e.data}"
43+
assert e.get_data() == expected, f"Expected data {expected}, got {e.get_data()}"
4444

4545
# Invoke the Function
4646
scope = {"event": event} # Add the CloudEvent to the scope

templates/python/http/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "function"
33
description = ""
44
version = "0.1.0"
5-
requires-python = ">=3.9"
5+
requires-python = ">=3.10"
66
readme = "README.md"
77
license = "MIT"
88
dependencies = [

templates/python/scaffolding/instanced-cloudevents/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
name = "service"
33
description = "an autogenerated service which runs a Function"
44
version = "0.1.0"
5-
requires-python = ">=3.9"
5+
requires-python = ">=3.10"
66
readme = "README.md"
77
license = "MIT"
88
dependencies = [
9-
"func-python==0.7.0",
9+
"func-python==0.8.0",
1010
"function @ {root:uri}/f"
1111
]
1212
authors = [

templates/python/scaffolding/instanced-http/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
name = "service"
33
description = "an autogenerated service which runs a Function"
44
version = "0.1.0"
5-
requires-python = ">=3.9"
5+
requires-python = ">=3.10"
66
readme = "README.md"
77
license = "MIT"
88
dependencies = [
9-
"func-python==0.7.0",
9+
"func-python==0.8.0",
1010
"function @ {root:uri}/f"
1111
]
1212
authors = [

0 commit comments

Comments
 (0)