Skip to content

Commit ed4f37d

Browse files
authored
Merge pull request #1734 from polywrap/nk/fix-py-wrap-info
fix: python wrap.info plugin binding issue
2 parents be21f45 + 1f8123c commit ed4f37d

4 files changed

Lines changed: 2478 additions & 9 deletions

File tree

packages/schema/bind/src/bindings/python/plugin/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const sort = (obj: Record<string, unknown>) =>
4040
export const generateBinding: GenerateBindingFn = (
4141
options: BindOptions
4242
): BindOutput => {
43+
const escapedAbi = JSON.stringify(
44+
sort((options.abi as unknown) as Record<string, unknown>)
45+
).replace(/\n/g, "\\n");
46+
const formattedAbi = JSON.stringify(JSON.parse(escapedAbi), null, 2);
47+
4348
// Apply Abi transforms
4449
const abi = applyTransforms(options.abi);
4550

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

6366
output.entries = renderTemplates(templatePath(""), { ...abi, manifest }, {});

packages/schema/bind/src/bindings/python/plugin/templates/wrap_info-py.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from __future__ import annotations
44

55
import json
6-
from base64 import b64decode
76

87
from polywrap_manifest import WrapManifest
98

109
{{#manifest}}
11-
abi = json.loads(b64decode("{{abi}}").decode("utf-8"))
10+
abi = json.loads("""
11+
{{abi}}
12+
""")
1213

1314
manifest = WrapManifest.parse_obj({
1415
"name": "{{name}}",

packages/test-cases/cases/bind/sanity/output/plugin-py/wrap_info.py

Lines changed: 2426 additions & 2 deletions
Large diffs are not rendered by default.

packages/test-cases/cases/cli/codegen/plugin/008-python/expected/wrap/wrap_info.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,52 @@
33
from __future__ import annotations
44

55
import json
6-
from base64 import b64decode
76

87
from polywrap_manifest import WrapManifest
98

10-
abi = json.loads(b64decode("eyJtb2R1bGVUeXBlIjp7ImtpbmQiOjEyOCwibWV0aG9kcyI6W3siYXJndW1lbnRzIjpbeyJraW5kIjozNCwibmFtZSI6ImRhdGEiLCJyZXF1aXJlZCI6dHJ1ZSwic2NhbGFyIjp7ImtpbmQiOjQsIm5hbWUiOiJkYXRhIiwicmVxdWlyZWQiOnRydWUsInR5cGUiOiJTdHJpbmcifSwidHlwZSI6IlN0cmluZyJ9XSwia2luZCI6NjQsIm5hbWUiOiJzYW1wbGVNZXRob2QiLCJyZXF1aXJlZCI6dHJ1ZSwicmV0dXJuIjp7ImtpbmQiOjM0LCJuYW1lIjoic2FtcGxlTWV0aG9kIiwicmVxdWlyZWQiOnRydWUsInNjYWxhciI6eyJraW5kIjo0LCJuYW1lIjoic2FtcGxlTWV0aG9kIiwicmVxdWlyZWQiOnRydWUsInR5cGUiOiJTdHJpbmcifSwidHlwZSI6IlN0cmluZyJ9LCJ0eXBlIjoiTWV0aG9kIn1dLCJ0eXBlIjoiTW9kdWxlIn0sInZlcnNpb24iOiIwLjEifQ==").decode("utf-8"))
9+
abi = json.loads("""
10+
{
11+
"moduleType": {
12+
"kind": 128,
13+
"methods": [
14+
{
15+
"arguments": [
16+
{
17+
"kind": 34,
18+
"name": "data",
19+
"required": true,
20+
"scalar": {
21+
"kind": 4,
22+
"name": "data",
23+
"required": true,
24+
"type": "String"
25+
},
26+
"type": "String"
27+
}
28+
],
29+
"kind": 64,
30+
"name": "sampleMethod",
31+
"required": true,
32+
"return": {
33+
"kind": 34,
34+
"name": "sampleMethod",
35+
"required": true,
36+
"scalar": {
37+
"kind": 4,
38+
"name": "sampleMethod",
39+
"required": true,
40+
"type": "String"
41+
},
42+
"type": "String"
43+
},
44+
"type": "Method"
45+
}
46+
],
47+
"type": "Module"
48+
},
49+
"version": "0.1"
50+
}
51+
""")
1152

1253
manifest = WrapManifest.parse_obj({
1354
"name": "Sample",

0 commit comments

Comments
 (0)