Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions templates/http-py-p2/content/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*.wasm
.spin
19 changes: 19 additions & 0 deletions templates/http-py-p2/content/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# A HTTP python component using componentize-py

This template uses the latest v3 version of the Spin Python SDK ([3.4.1](https://pypi.org/project/spin-sdk/3.4.1/))
for compatibility with Spin 3.x (and hosts that use this major version). The 'p2' corresponds to the wasip2 or
WASI Preview 2 set of WASI APIs, as used by Spin 3.x.

## Installing the requirements

To build the component, [`componentize-py`](https://pypi.org/project/componentize-py/) and [`spin-sdk`](https://pypi.org/project/spin-sdk/) are required. To install them, run:

```bash
pip3 install -r requirements.txt
```

## Building and Running

```
spin up --build
```
9 changes: 9 additions & 0 deletions templates/http-py-p2/content/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from spin_sdk.http import IncomingHandler, Request, Response

class IncomingHandler(IncomingHandler):
def handle_request(self, request: Request) -> Response:
return Response(
200,
{"content-type": "text/plain"},
bytes("Hello from Python!", "utf-8")
)
2 changes: 2 additions & 0 deletions templates/http-py-p2/content/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spin-sdk == 3.4.1
componentize-py == 0.17.2
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this (and the other files) from the http-py template that exists in source control prior to the v4 overhaul. It builds successfully, as expected. However, when I attempt to bump componentize-py to the latest 0.23.0 version, I see this on spin build:

$ spin up --build
Building component test with `componentize-py -w spin-http componentize app -o app.wasm`
Traceback (most recent call last):
  File "/Users/vdice/code/github.com/spinframework/spin-python-sdk/.http-py-p2/.venv/bin/componentize-py", line 6, in <module>
    sys.exit(script())
             ~~~~~~^^
AssertionError: Traceback (most recent call last):
  File "/0/app.py", line 1, in <module>
    from spin_sdk.http import IncomingHandler, Request, Response
  File "/1/spin_sdk/http/__init__.py", line 5, in <module>
    from spin_sdk.http import poll_loop
  File "/1/spin_sdk/http/poll_loop.py", line 14, in <module>
    from spin_sdk.wit.types import Ok, Err
ModuleNotFoundError: No module named 'spin_sdk.wit.types'


Caused by:
    ModuleNotFoundError: No module named 'spin_sdk.wit.types'

@dicej any ideas?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend leaving the componentize-py version as it was. Per Rust's semver rules, breaking changes are allowed when the x changes in a 0.x.y version bump, so older apps/templates aren't necessarily compatible with newer componentize-py versions and vice-versa.

17 changes: 17 additions & 0 deletions templates/http-py-p2/content/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spin_manifest_version = 2

[application]
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
version = "0.1.0"

[[trigger.http]]
route = "{{http-path}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "app.wasm"
[component.{{project-name | kebab_case}}.build]
command = "componentize-py -w spin-http componentize app -o app.wasm"
watch = ["*.py", "requirements.txt"]
10 changes: 10 additions & 0 deletions templates/http-py-p2/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[trigger.http]]
route = "{{http-path}}"
component = "{{project-name | kebab_case}}"

[component.{{project-name | kebab_case}}]
source = "{{ output-path }}/app.wasm"
[component.{{project-name | kebab_case}}.build]
command = "componentize-py -w spin-http componentize app -o app.wasm"
workdir = "{{ output-path }}"
watch = ["*.py", "requirements.txt"]
13 changes: 13 additions & 0 deletions templates/http-py-p2/metadata/spin-template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
manifest_version = "1"
id = "http-py-p2"
description = "HTTP request handler using Python compatible with Spin 3.x hosts"
tags = ["http", "python", "py"]

[add_component]
skip_files = ["spin.toml"]
[add_component.snippets]
component = "component.txt"

[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-path = { type = "string", prompt = "HTTP path", default = "/...", pattern = "^/\\S*$" }
Loading