-
Notifications
You must be signed in to change notification settings - Fork 15
feat(templates): add http-py-p2 #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| __pycache__ | ||
| *.wasm | ||
| .spin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| spin-sdk == 3.4.1 | ||
| componentize-py == 0.17.2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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*$" } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-pyto the latest 0.23.0 version, I see this onspin build:@dicej any ideas?
There was a problem hiding this comment.
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-pyversion as it was. Per Rust's semver rules, breaking changes are allowed when thexchanges in a0.x.yversion bump, so older apps/templates aren't necessarily compatible with newercomponentize-pyversions and vice-versa.