Skip to content

Commit

Permalink
CI - Add Python 3.9 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg authored Apr 5, 2021
1 parent 7efb698 commit 4c54f56
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: [ 3.6, 3.7, 3.8 ]
python_version: [ 3.6, 3.7, 3.8, 3.9 ]
steps:
- name: Dump github context
run: echo "$GITHUB_CONTEXT"
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python_version: [ 3.6, 3.7, 3.8 ]
python_version: [ 3.6, 3.7, 3.8, 3.9 ]
steps:
- name: Dump github context
run: echo "$GITHUB_CONTEXT"
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:

- name: Invoke function
run: |
nuctl invoke $FUNCTION_NAME
echo "Hello, from CI" | nuctl invoke $FUNCTION_NAME
- name: Print function container logs
run: |
Expand Down
43 changes: 42 additions & 1 deletion hack/ci_assets/function/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,37 @@

import pkg_resources
import http
import json

import nuclio_sdk


def handler(context: nuclio_sdk.Context, event: nuclio_sdk.Event):
context.logger.debug_with("Received request", event=event.to_json())
context.logger.debug_with(
"Received request",
event=json.dumps(
{
"id": event.id,
"eventType": event.trigger.kind,
"contentType": event.content_type,
"headers": {
ensure_str(header): ensure_str(value)
for header, value in event.headers.items()
},
"timestamp": event.timestamp.isoformat("T") + "Z",
"path": event.path,
"url": event.url,
"method": event.method,
"type": event.type,
"typeVersion": event.type_version,
"version": event.version,
"body": event.body
if isinstance(event.body, dict)
else event.body.decode("utf8"),
},
default=json_default,
),
)
return context.Response(
headers=event.headers,
body={
Expand All @@ -32,3 +57,19 @@ def handler(context: nuclio_sdk.Context, event: nuclio_sdk.Event):

def get_sdk_version():
return pkg_resources.get_distribution("nuclio_sdk").version


def json_default(s):
if type(s) is bytes:
return ensure_str(s)
return s


def ensure_str(s, encoding="utf-8", errors="strict"):

# Optimization: Fast return for the common case.
if type(s) is str:
return s
if isinstance(s, bytes):
return s.decode(encoding, errors)
raise TypeError(f"not expecting type '{type(s)}'")

0 comments on commit 4c54f56

Please sign in to comment.