Skip to content
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

fix: python wrap.info plugin binding issue #1734

Merged
merged 3 commits into from
May 10, 2023
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
9 changes: 6 additions & 3 deletions packages/schema/bind/src/bindings/python/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const sort = (obj: Record<string, unknown>) =>
export const generateBinding: GenerateBindingFn = (
options: BindOptions
): BindOutput => {
const escapedAbi = JSON.stringify(
sort((options.abi as unknown) as Record<string, unknown>)
).replace(/\n/g, "\\n");
const formattedAbi = JSON.stringify(JSON.parse(escapedAbi), null, 2);

// Apply Abi transforms
const abi = applyTransforms(options.abi);

Expand All @@ -55,9 +60,7 @@ export const generateBinding: GenerateBindingFn = (
name: options.projectName,
type: "plugin",
version: latestWrapManifestVersion,
abi: Buffer.from(
JSON.stringify(sort((options.abi as unknown) as Record<string, unknown>))
).toString("base64"),
abi: formattedAbi,
};

output.entries = renderTemplates(templatePath(""), { ...abi, manifest }, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from __future__ import annotations

import json
from base64 import b64decode

from polywrap_manifest import WrapManifest

{{#manifest}}
abi = json.loads(b64decode("{{abi}}").decode("utf-8"))
abi = json.loads("""
{{abi}}
""")

manifest = WrapManifest.parse_obj({
"name": "{{name}}",
Expand Down
2,428 changes: 2,426 additions & 2 deletions packages/test-cases/cases/bind/sanity/output/plugin-py/wrap_info.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,52 @@
from __future__ import annotations

import json
from base64 import b64decode

from polywrap_manifest import WrapManifest

abi = json.loads(b64decode("eyJtb2R1bGVUeXBlIjp7ImtpbmQiOjEyOCwibWV0aG9kcyI6W3siYXJndW1lbnRzIjpbeyJraW5kIjozNCwibmFtZSI6ImRhdGEiLCJyZXF1aXJlZCI6dHJ1ZSwic2NhbGFyIjp7ImtpbmQiOjQsIm5hbWUiOiJkYXRhIiwicmVxdWlyZWQiOnRydWUsInR5cGUiOiJTdHJpbmcifSwidHlwZSI6IlN0cmluZyJ9XSwia2luZCI6NjQsIm5hbWUiOiJzYW1wbGVNZXRob2QiLCJyZXF1aXJlZCI6dHJ1ZSwicmV0dXJuIjp7ImtpbmQiOjM0LCJuYW1lIjoic2FtcGxlTWV0aG9kIiwicmVxdWlyZWQiOnRydWUsInNjYWxhciI6eyJraW5kIjo0LCJuYW1lIjoic2FtcGxlTWV0aG9kIiwicmVxdWlyZWQiOnRydWUsInR5cGUiOiJTdHJpbmcifSwidHlwZSI6IlN0cmluZyJ9LCJ0eXBlIjoiTWV0aG9kIn1dLCJ0eXBlIjoiTW9kdWxlIn0sInZlcnNpb24iOiIwLjEifQ==").decode("utf-8"))
abi = json.loads("""
{
"moduleType": {
"kind": 128,
"methods": [
{
"arguments": [
{
"kind": 34,
"name": "data",
"required": true,
"scalar": {
"kind": 4,
"name": "data",
"required": true,
"type": "String"
},
"type": "String"
}
],
"kind": 64,
"name": "sampleMethod",
"required": true,
"return": {
"kind": 34,
"name": "sampleMethod",
"required": true,
"scalar": {
"kind": 4,
"name": "sampleMethod",
"required": true,
"type": "String"
},
"type": "String"
},
"type": "Method"
}
],
"type": "Module"
},
"version": "0.1"
}
""")

manifest = WrapManifest.parse_obj({
"name": "Sample",
Expand Down