From f808be91ffcb16fad1584c5eb21fc1961e05e46e Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Mon, 30 Dec 2024 17:30:34 -0500 Subject: [PATCH 1/7] fix: nested types, use dataclass_wizard to deserialize/serialize types --- template/plugin/__init__.py.ejs | 5 +++-- template/plugin/pdk_types.py.ejs | 5 ++--- template/prepare.sh | 10 ++++++++++ template/xtp.toml.ejs | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/template/plugin/__init__.py.ejs b/template/plugin/__init__.py.ejs index ae0dcf9..c7767d6 100644 --- a/template/plugin/__init__.py.ejs +++ b/template/plugin/__init__.py.ejs @@ -2,6 +2,7 @@ from typing import Optional, List # noqa: F401 from datetime import datetime # noqa: F401 +import json import extism # pyright: ignore import plugin @@ -34,7 +35,7 @@ def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPyth <% } -%> @extism.plugin_fn def <%- ex.name %>(): - res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> extism.input(<%- toPythonParamType(ex.input) %>) <% } %>) - extism.output(res) + res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) <% } %>) + extism.output_str(res.to_json(encoder=json.dumps, cls=extism.JSONEncoder)) <% }) %> diff --git a/template/plugin/pdk_types.py.ejs b/template/plugin/pdk_types.py.ejs index e6f24e7..d6cc2af 100644 --- a/template/plugin/pdk_types.py.ejs +++ b/template/plugin/pdk_types.py.ejs @@ -5,8 +5,7 @@ from enum import Enum # noqa: F401 from typing import Optional, List # noqa: F401 from datetime import datetime # noqa: F401 from dataclasses import dataclass # noqa: F401 - -import extism # noqa: F401 # pyright: ignore +from dataclass_wizard import JSONWizard # noqa: F401 <% Object.values(schema.schemas).forEach(schema => { %> <% if (schema.enum) { %> @@ -16,7 +15,7 @@ class <%- pythonTypeName(schema.name) %>(Enum): <% }) %> <% } else { %> @dataclass -class <%- pythonTypeName(schema.name) %>(extism.Json): +class <%- pythonTypeName(schema.name) %>(JSONWizard): <% schema.properties.forEach(p => { -%> <% if (!p.nullable && p.required) {%> <% if (p.description) { -%> diff --git a/template/prepare.sh b/template/prepare.sh index 546e38f..19812fe 100644 --- a/template/prepare.sh +++ b/template/prepare.sh @@ -41,4 +41,14 @@ if ! command_exists extism-py; then exit 1 fi +# fetch dataclass wizard +if [ ! -d dataclass-wizard-0.33.0 ]; then + curl -O https://files.pythonhosted.org/packages/0a/2a/6ae6638cd5ca919b73d393cdb4a4e53c8c3dcacc003a79d9480ecad46798/dataclass-wizard-0.33.0.tar.gz + tar xf dataclass-wizard-0.33.0.tar.gz +fi +# fetch typing extensions +if [ ! -d typing_extensions-4.12.2 ]; then + curl -O https://files.pythonhosted.org/packages/df/db/f35a00659bc03fec321ba8bce9420de607a1d37f8342eee1863174c69557/typing_extensions-4.12.2.tar.gz + tar xf typing_extensions-4.12.2.tar.gz +fi diff --git a/template/xtp.toml.ejs b/template/xtp.toml.ejs index 2ff3cad..8ad153c 100644 --- a/template/xtp.toml.ejs +++ b/template/xtp.toml.ejs @@ -8,7 +8,7 @@ name = "<%= project.name %>" [scripts] # xtp plugin build runs this script to generate the wasm file -build = "PYTHONPATH=./plugin extism-py -o plugin.wasm plugin/__init__.py" +build = "PYTHONPATH=./plugin:./typing_extensions-4.12.2/src:./dataclass-wizard-0.33.0 extism-py -o plugin.wasm plugin/__init__.py" # xtp plugin init runs this script to format the code format = "uv run ruff format plugin/*.py" From da69eecb47711c6aa61e0976ac4b654a7b2014c7 Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Thu, 2 Jan 2025 17:40:24 -0500 Subject: [PATCH 2/7] fix: get imports json serialization working again, reflectJsonObject tests now pass --- bindgen-test.sh | 2 +- template/plugin/__init__.py.ejs | 11 +++++++++-- template/plugin/pdk_imports.py.ejs | 7 ++++++- template/plugin/pdk_types.py.ejs | 23 ++++++++++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/bindgen-test.sh b/bindgen-test.sh index 32257d3..6d73731 100755 --- a/bindgen-test.sh +++ b/bindgen-test.sh @@ -33,6 +33,6 @@ case $1 in echo "building '$PLUGIN_NAME'..." xtp plugin build --path $PLUGIN_NAME echo "testing '$PLUGIN_NAME'..." - xtp plugin test $PLUGIN_NAME/plugin.wasm --with test.wasm --mock-host mock.wasm + EXTISM_ENABLE_WASI_OUTPUT=1 xtp plugin test $PLUGIN_NAME/plugin.wasm --with test.wasm --mock-host mock.wasm ;; esac diff --git a/template/plugin/__init__.py.ejs b/template/plugin/__init__.py.ejs index c7767d6..66efa2f 100644 --- a/template/plugin/__init__.py.ejs +++ b/template/plugin/__init__.py.ejs @@ -22,7 +22,7 @@ from pdk_types import <%- Object.values(schema.schemas).map(schema => pythonType # And it returns an output <%- toPythonParamType(imp.output) %> (<%- formatCommentLine(imp.output.description) %>) <% } -%> @extism.import_fn("extism:host/user", "<%- imp.name %>") -def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonParamType(imp.input) %><%} -%>) <% if (imp.output) { %> -> <%- toPythonParamType(imp.output) %><% } %>: # pyright: ignore [reportReturnType] +def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} -%>) <% if (imp.output) { %> -> str <% } %>: # pyright: ignore [reportReturnType] pass <% }) %> @@ -35,7 +35,14 @@ def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPyth <% } -%> @extism.plugin_fn def <%- ex.name %>(): - res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) <% } %>) +<% if (ex.input) { %> + extism.log(extism.LogLevel.Error, "calling .from_json") + obj = <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) + <% } %> + extism.log(extism.LogLevel.Error, "calling func") + res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> obj <% } %>) + #res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) <% } %>) + extism.log(extism.LogLevel.Error, "returning") extism.output_str(res.to_json(encoder=json.dumps, cls=extism.JSONEncoder)) <% }) %> diff --git a/template/plugin/pdk_imports.py.ejs b/template/plugin/pdk_imports.py.ejs index 59ac0f2..4b1029e 100644 --- a/template/plugin/pdk_imports.py.ejs +++ b/template/plugin/pdk_imports.py.ejs @@ -3,6 +3,7 @@ from typing import Optional, List # noqa: F401 from datetime import datetime # noqa: F401 import extism # noqa: F401 # pyright: ignore +import json <% if (Object.values(schema.schemas).length > 0) { %> from pdk_types import <%- Object.values(schema.schemas).map(schema => pythonTypeName(schema.name)).join(", ") %> # noqa: F401 @@ -18,8 +19,12 @@ from pdk_types import <%- Object.values(schema.schemas).map(schema => pythonType # And it returns an output <%- toPythonParamType(imp.output) %> (<%- formatCommentLine(imp.output.description) %>) <% } -%> @extism.import_fn("extism:host/user", "<%- imp.name %>") -def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonParamType(imp.input) %><%} -%>) <% if (imp.output) { %> -> <%- toPythonParamType(imp.output) %><% } %>: # pyright: ignore [reportReturnType] +def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} -%>) <% if (imp.output) { %> -> str <% } %>: # pyright: ignore [reportReturnType] pass + +def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonParamType(imp.input) %><%} -%>) <% if (imp.output) { %> -> <%- toPythonParamType(imp.output) %><% } %>: # pyright: ignore [reportReturnType] + <% if (imp.output) { %>obj = <%- toPythonParamType(imp.output) %>.from_json(<% } %>_<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input.to_json(encoder=json.dumps, cls=extism.JSONEncoder)<% } %>)<% if (imp.output) { %>)<% } %> + return <% if (imp.output) { %>obj<% } %> <% }) %> diff --git a/template/plugin/pdk_types.py.ejs b/template/plugin/pdk_types.py.ejs index d6cc2af..b383c3d 100644 --- a/template/plugin/pdk_types.py.ejs +++ b/template/plugin/pdk_types.py.ejs @@ -6,6 +6,10 @@ from typing import Optional, List # noqa: F401 from datetime import datetime # noqa: F401 from dataclasses import dataclass # noqa: F401 from dataclass_wizard import JSONWizard # noqa: F401 +from dataclass_wizard import JSONPyWizard +from dataclass_wizard.type_def import JSONObject +from base64 import b64encode, b64decode +import logging <% Object.values(schema.schemas).forEach(schema => { %> <% if (schema.enum) { %> @@ -15,7 +19,7 @@ class <%- pythonTypeName(schema.name) %>(Enum): <% }) %> <% } else { %> @dataclass -class <%- pythonTypeName(schema.name) %>(JSONWizard): +class <%- pythonTypeName(schema.name) %>(JSONWizard, debug=logging.ERROR): <% schema.properties.forEach(p => { -%> <% if (!p.nullable && p.required) {%> <% if (p.description) { -%> @@ -34,6 +38,23 @@ class <%- pythonTypeName(schema.name) %>(JSONWizard): <% } %> <% }) %> + @classmethod + def _pre_from_dict(cls, o: JSONObject) -> JSONObject: +<% schema.properties.forEach(p => { -%> +<% if (p.xtpType.kind === 'buffer') {%> + o['<%- p.name %>'] = b64decode(o['<%- p.name %>']) +<% } -%> +<% }) -%> + return o + + def _pre_dict(self): +<% schema.properties.forEach(p => { -%> +<% if (p.xtpType.kind === 'buffer') {%> + self.<%- p.name %> = b64encode(self.<%- p.name %>).decode("utf-8") +<% } -%> +<% }) -%> + return + <% } %> <% }); %> From cb22b1f3179fcf39359fe03bb0e38e92f7632f01 Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 3 Jan 2025 14:50:01 -0500 Subject: [PATCH 3/7] fix: get all bindgen tests running --- template/plugin/__init__.py.ejs | 29 +++++++++++++++++++++------- template/plugin/pdk_imports.py.ejs | 31 ++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/template/plugin/__init__.py.ejs b/template/plugin/__init__.py.ejs index 66efa2f..2a5eb37 100644 --- a/template/plugin/__init__.py.ejs +++ b/template/plugin/__init__.py.ejs @@ -36,13 +36,28 @@ def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} - @extism.plugin_fn def <%- ex.name %>(): <% if (ex.input) { %> - extism.log(extism.LogLevel.Error, "calling .from_json") +<% if (ex.input.contentType === 'application/json') { %> +<% if (ex.input.xtpType.kind === 'object') { %> obj = <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) - <% } %> - extism.log(extism.LogLevel.Error, "calling func") +<% } else { %> + obj = json.loads(extism.input_str()) +<% } %> +<% } else { %> + obj = extism.input_str() +<% } %> +<% } %> res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> obj <% } %>) - #res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) <% } %>) - extism.log(extism.LogLevel.Error, "returning") - extism.output_str(res.to_json(encoder=json.dumps, cls=extism.JSONEncoder)) - +<% if (ex.output) { %> + extism.output_str( +<% if (ex.output.contentType === 'application/json') { %> +<% if (ex.output.xtpType.kind === 'object') { %> + res.to_json(encoder=json.dumps, cls=extism.JSONEncoder) +<% } else { %> + json.dumps(res) +<% } %> +<% } else { %> + res +<% } %> + ) +<% } %> <% }) %> diff --git a/template/plugin/pdk_imports.py.ejs b/template/plugin/pdk_imports.py.ejs index 4b1029e..989cbcd 100644 --- a/template/plugin/pdk_imports.py.ejs +++ b/template/plugin/pdk_imports.py.ejs @@ -23,8 +23,35 @@ def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} - pass def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonParamType(imp.input) %><%} -%>) <% if (imp.output) { %> -> <%- toPythonParamType(imp.output) %><% } %>: # pyright: ignore [reportReturnType] - <% if (imp.output) { %>obj = <%- toPythonParamType(imp.output) %>.from_json(<% } %>_<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input.to_json(encoder=json.dumps, cls=extism.JSONEncoder)<% } %>)<% if (imp.output) { %>)<% } %> - return <% if (imp.output) { %>obj<% } %> +<% if (imp.output) { %> + return ( +<% if (imp.output.contentType === 'application/json') { %> +<% if (imp.output.xtpType.kind === 'object') { %> + <%- toPythonParamType(imp.output) %>.from_json( +<% } else { %> + json.loads( +<% } -%> +<% } -%> +<% } -%> + _<%- pythonFunctionName(imp.name) %>( +<% if (imp.input) { -%> +<% if (imp.input.contentType === 'application/json') { %> +<% if (imp.input.xtpType.kind === 'object') { %> + input.to_json(encoder=json.dumps, cls=extism.JSONEncoder) +<% } else { %> + json.dumps(input) +<% } -%> +<% } else { %> + input +<% } -%> +<% } -%> + ) +<% if (imp.output) { %> + ) +<% if (imp.output.contentType === 'application/json') { %> + ) +<% } -%> +<% } -%> <% }) %> From 4cf8face8acab07adc877fbe358020a27859d197 Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 3 Jan 2025 14:56:54 -0500 Subject: [PATCH 4/7] chore: remove usage of extism.JSONEncoder, we no longer rely on it --- template/plugin/__init__.py.ejs | 2 +- template/plugin/pdk_imports.py.ejs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/template/plugin/__init__.py.ejs b/template/plugin/__init__.py.ejs index 2a5eb37..70274a2 100644 --- a/template/plugin/__init__.py.ejs +++ b/template/plugin/__init__.py.ejs @@ -51,7 +51,7 @@ def <%- ex.name %>(): extism.output_str( <% if (ex.output.contentType === 'application/json') { %> <% if (ex.output.xtpType.kind === 'object') { %> - res.to_json(encoder=json.dumps, cls=extism.JSONEncoder) + res.to_json() <% } else { %> json.dumps(res) <% } %> diff --git a/template/plugin/pdk_imports.py.ejs b/template/plugin/pdk_imports.py.ejs index 989cbcd..1440cd8 100644 --- a/template/plugin/pdk_imports.py.ejs +++ b/template/plugin/pdk_imports.py.ejs @@ -37,7 +37,7 @@ def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPyth <% if (imp.input) { -%> <% if (imp.input.contentType === 'application/json') { %> <% if (imp.input.xtpType.kind === 'object') { %> - input.to_json(encoder=json.dumps, cls=extism.JSONEncoder) + input.to_json() <% } else { %> json.dumps(input) <% } -%> From 235a5acea1f45835740852bb34122141dc5c8e7a Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 3 Jan 2025 15:56:53 -0500 Subject: [PATCH 5/7] fix: handling buffers as str instead of bytes --- src/index.ts | 14 ++++++++-- template/plugin/__init__.py.ejs | 43 +++++++++++++++--------------- template/plugin/pdk_imports.py.ejs | 2 +- template/plugin/pdk_types.py.ejs | 4 +-- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/index.ts b/src/index.ts index 19c6376..98c7d0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,8 @@ import { EnumType, ArrayType, XtpNormalizedType, - XtpTyped + XtpTyped, + Parameter } from "@dylibso/xtp-bindgen" function pythonTypeName(s: string): string { @@ -78,6 +79,14 @@ function toPythonParamType(property: XtpTyped, required?: boolean): string { return t; } +function toPythonHostParamType(param: Parameter): string { + if (param.contentType === 'application/x-binary') { + return 'bytes' + } else { + return 'str' + } +} + export function render() { const tmpl = Host.inputString(); const ctx = { @@ -86,7 +95,8 @@ export function render() { toPythonType, toPythonParamType, pythonTypeName, - pythonFunctionName + pythonFunctionName, + toPythonHostParamType }; const output = ejs.render(tmpl, ctx); diff --git a/template/plugin/__init__.py.ejs b/template/plugin/__init__.py.ejs index 70274a2..a3daf91 100644 --- a/template/plugin/__init__.py.ejs +++ b/template/plugin/__init__.py.ejs @@ -22,7 +22,7 @@ from pdk_types import <%- Object.values(schema.schemas).map(schema => pythonType # And it returns an output <%- toPythonParamType(imp.output) %> (<%- formatCommentLine(imp.output.description) %>) <% } -%> @extism.import_fn("extism:host/user", "<%- imp.name %>") -def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} -%>) <% if (imp.output) { %> -> str <% } %>: # pyright: ignore [reportReturnType] +def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonHostParamType(imp.input) %> <%} -%>) <% if (imp.output) { %> -> <%- toPythonHostParamType(imp.output) %> <% } %>: # pyright: ignore [reportReturnType] pass <% }) %> @@ -35,29 +35,28 @@ def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} - <% } -%> @extism.plugin_fn def <%- ex.name %>(): -<% if (ex.input) { %> -<% if (ex.input.contentType === 'application/json') { %> -<% if (ex.input.xtpType.kind === 'object') { %> - obj = <%- toPythonParamType(ex.input) %>.from_json(extism.input_str()) -<% } else { %> - obj = json.loads(extism.input_str()) -<% } %> -<% } else { %> - obj = extism.input_str() -<% } %> -<% } %> - res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> obj <% } %>) -<% if (ex.output) { %> - extism.output_str( -<% if (ex.output.contentType === 'application/json') { %> -<% if (ex.output.xtpType.kind === 'object') { %> +<% if (ex.input) { -%> + input = <% if (ex.input.contentType === 'application/x-binary') { %> extism.input_bytes() <% } else { %> extism.input_str() <% } %> +<% if (ex.input.contentType === 'application/json') { -%> +<% if (ex.input.xtpType.kind === 'object') { -%> + input = <%- toPythonParamType(ex.input) %>.from_json(input) +<% } else { -%> + input = json.loads(input) +<% } -%> +<% } -%> +<% } -%> + res = plugin.<%- pythonFunctionName(ex.name) %>(<% if (ex.input) { %> input <% } %>) +<% if (ex.output) { -%> +<% if (ex.output.contentType === 'application/x-binary') { %> extism.output_bytes( <% } else { %> extism.output_str( <% } %> +<% if (ex.output.contentType === 'application/json') { -%> +<% if (ex.output.xtpType.kind === 'object') { -%> res.to_json() -<% } else { %> +<% } else { -%> json.dumps(res) <% } %> -<% } else { %> +<% } else { -%> res -<% } %> +<% } -%> ) -<% } %> -<% }) %> +<% } -%> +<% }) -%> diff --git a/template/plugin/pdk_imports.py.ejs b/template/plugin/pdk_imports.py.ejs index 1440cd8..8b35130 100644 --- a/template/plugin/pdk_imports.py.ejs +++ b/template/plugin/pdk_imports.py.ejs @@ -19,7 +19,7 @@ from pdk_types import <%- Object.values(schema.schemas).map(schema => pythonType # And it returns an output <%- toPythonParamType(imp.output) %> (<%- formatCommentLine(imp.output.description) %>) <% } -%> @extism.import_fn("extism:host/user", "<%- imp.name %>") -def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: str <%} -%>) <% if (imp.output) { %> -> str <% } %>: # pyright: ignore [reportReturnType] +def _<%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonHostParamType(imp.input) %> <%} -%>) <% if (imp.output) { %> -> <%- toPythonHostParamType(imp.output) %> <% } %>: # pyright: ignore [reportReturnType] pass def <%- pythonFunctionName(imp.name) %>(<% if (imp.input) { -%>input: <%- toPythonParamType(imp.input) %><%} -%>) <% if (imp.output) { %> -> <%- toPythonParamType(imp.output) %><% } %>: # pyright: ignore [reportReturnType] diff --git a/template/plugin/pdk_types.py.ejs b/template/plugin/pdk_types.py.ejs index b383c3d..edea53e 100644 --- a/template/plugin/pdk_types.py.ejs +++ b/template/plugin/pdk_types.py.ejs @@ -6,10 +6,8 @@ from typing import Optional, List # noqa: F401 from datetime import datetime # noqa: F401 from dataclasses import dataclass # noqa: F401 from dataclass_wizard import JSONWizard # noqa: F401 -from dataclass_wizard import JSONPyWizard from dataclass_wizard.type_def import JSONObject from base64 import b64encode, b64decode -import logging <% Object.values(schema.schemas).forEach(schema => { %> <% if (schema.enum) { %> @@ -19,7 +17,7 @@ class <%- pythonTypeName(schema.name) %>(Enum): <% }) %> <% } else { %> @dataclass -class <%- pythonTypeName(schema.name) %>(JSONWizard, debug=logging.ERROR): +class <%- pythonTypeName(schema.name) %>(JSONWizard): <% schema.properties.forEach(p => { -%> <% if (!p.nullable && p.required) {%> <% if (p.description) { -%> From a545a0e80b71e0a2ee1b0e033cfd33e50fd5e4bf Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 3 Jan 2025 17:18:38 -0500 Subject: [PATCH 6/7] build: use uv to fetch deps instead of curl --- template/prepare.sh | 12 ------------ template/pyproject.toml.ejs | 7 +++++-- template/xtp.toml.ejs | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/template/prepare.sh b/template/prepare.sh index 19812fe..8411ac7 100644 --- a/template/prepare.sh +++ b/template/prepare.sh @@ -40,15 +40,3 @@ if ! command_exists extism-py; then sleep 2 exit 1 fi - -# fetch dataclass wizard -if [ ! -d dataclass-wizard-0.33.0 ]; then - curl -O https://files.pythonhosted.org/packages/0a/2a/6ae6638cd5ca919b73d393cdb4a4e53c8c3dcacc003a79d9480ecad46798/dataclass-wizard-0.33.0.tar.gz - tar xf dataclass-wizard-0.33.0.tar.gz -fi - -# fetch typing extensions -if [ ! -d typing_extensions-4.12.2 ]; then - curl -O https://files.pythonhosted.org/packages/df/db/f35a00659bc03fec321ba8bce9420de607a1d37f8342eee1863174c69557/typing_extensions-4.12.2.tar.gz - tar xf typing_extensions-4.12.2.tar.gz -fi diff --git a/template/pyproject.toml.ejs b/template/pyproject.toml.ejs index 158682a..209800c 100644 --- a/template/pyproject.toml.ejs +++ b/template/pyproject.toml.ejs @@ -3,8 +3,11 @@ name = "<%= project.name %>" version = "0.1.0" description = "Add your description here" readme = "README.md" -requires-python = ">=3.12" -dependencies = [] +requires-python = ">=3.13,<3.14" +dependencies = [ + "dataclass-wizard>=0.33.0,<0.34.0", + "typing_extensions>=4.12.2,<5.0.0", +] [tool.uv] dev-dependencies = [ diff --git a/template/xtp.toml.ejs b/template/xtp.toml.ejs index 8ad153c..5b6ed23 100644 --- a/template/xtp.toml.ejs +++ b/template/xtp.toml.ejs @@ -8,7 +8,7 @@ name = "<%= project.name %>" [scripts] # xtp plugin build runs this script to generate the wasm file -build = "PYTHONPATH=./plugin:./typing_extensions-4.12.2/src:./dataclass-wizard-0.33.0 extism-py -o plugin.wasm plugin/__init__.py" +build = "PYTHONPATH=./plugin:./.venv/lib/python3.13/site-packages extism-py -o plugin.wasm plugin/__init__.py" # xtp plugin init runs this script to format the code format = "uv run ruff format plugin/*.py" From 69b119f00a4b3a2396e64b9b62164417e427a49f Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 3 Jan 2025 17:25:05 -0500 Subject: [PATCH 7/7] build: only specify direct dependencies --- template/pyproject.toml.ejs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/template/pyproject.toml.ejs b/template/pyproject.toml.ejs index 209800c..68d8d17 100644 --- a/template/pyproject.toml.ejs +++ b/template/pyproject.toml.ejs @@ -5,8 +5,7 @@ description = "Add your description here" readme = "README.md" requires-python = ">=3.13,<3.14" dependencies = [ - "dataclass-wizard>=0.33.0,<0.34.0", - "typing_extensions>=4.12.2,<5.0.0", + "dataclass-wizard>=0.33.0,<0.34.0" ] [tool.uv]