Skip to content

Commit a1bed5a

Browse files
authored
Merge pull request #1786 from Niraj-Kamdar/nk/py-plugin-refactor
fix: python-plugin bindings
2 parents 2dcc331 + 0b2543b commit a1bed5a

8 files changed

Lines changed: 51 additions & 62 deletions

File tree

packages/cli/src/__tests__/e2e/p2/build.wasm.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const HELP = `Usage: polywrap build|b [options]
1313
Build Polywrap Projects (type: interface, wasm)
1414
1515
Options:
16-
-m, --manifest-file <path> Path to the Polywrap Build manifest file
16+
-m, --manifest-file <path> Path to the Polywrap manifest file
1717
(default: polywrap.yaml | polywrap.yml)
1818
-o, --output-dir <path> Output directory for build results
1919
(default: ./build)

packages/js/cli/src/__tests__/commands.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,13 @@ const testData: CommandTestCaseData<CommandTypings> = {
225225
}],
226226
docs: {
227227
init: [{
228-
cwd: fs.mkdtempSync(path.join(os.tmpdir(), "docs-init")),
229-
before: async (test) => {
230-
if(!test.cwd)
231-
throw Error("This shouldn't happen");
232-
},
233-
after: (_, stdout, __, exitCode) => {
228+
cwd: path.join(GetPathToCliTestFiles(), "build-cmd/wasm/assemblyscript/001-sanity"),
229+
after: (test, stdout, __, exitCode) => {
234230
expect(stdout).toContain("Written docs manifest to");
235231
expect(exitCode).toBe(0);
232+
if (test.cwd) {
233+
fs.rmSync(path.join(test.cwd, "polywrap.docs.yaml"));
234+
}
236235
}
237236
}]
238237
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from typing import TypeVar, Generic, TypedDict, Optional
77

88
from .types import *
99

10-
from polywrap_core import InvokerClient, UriPackageOrWrapper
10+
from polywrap_core import InvokerClient
1111
from polywrap_plugin import PluginModule
1212
from polywrap_msgpack import GenericMap
1313

@@ -39,10 +39,10 @@ class Module(Generic[TConfig], PluginModule[TConfig]):
3939
{{#moduleType}}
4040
{{#methods}}
4141
@abstractmethod
42-
async def {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(
42+
def {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(
4343
self,
4444
args: Args{{#toUpper}}{{name}}{{/toUpper}},
45-
client: InvokerClient[UriPackageOrWrapper],
45+
client: InvokerClient,
4646
{{^env}}env: None{{/env}}{{#env}}env: {{^required}}Optional[{{/required}}Env{{^required}}] = None{{/required}}{{/env}}
4747
) -> {{#return}}{{#toPython}}{{toGraphQLType}}{{/toPython}}{{/return}}:
4848
pass

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from __future__ import annotations
55
from typing import TypedDict, Optional
66
from enum import IntEnum
77

8-
from polywrap_core import InvokerClient, Uri, UriPackageOrWrapper
8+
from polywrap_core import InvokerClient, Uri
99
from polywrap_msgpack import GenericMap
1010

1111

@@ -100,16 +100,14 @@ class {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}(IntEn
100100
class {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}:
101101
{{#methods}}
102102
@staticmethod
103-
async def {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(
103+
def {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(
104104
args: {{#toUpper}}{{parent.type}}{{/toUpper}}Args{{#toUpper}}{{name}}{{/toUpper}},
105-
client: InvokerClient[UriPackageOrWrapper]
105+
client: InvokerClient
106106
) -> {{#return}}{{#toPython}}{{toGraphQLType}}{{/toPython}}{{/return}}:
107107
return client.invoke(
108-
InvokeOptions(
109-
uri=Uri.from_str("{{parent.uri}}"),
110-
method="{{name}}",
111-
args=args,
112-
)
108+
uri=Uri.from_str("{{parent.uri}}"),
109+
method="{{name}}",
110+
args=args,
113111
)
114112
{{^last}}
115113

@@ -127,17 +125,15 @@ class {{#detectKeyword}}{{#toUpper}}{{type}}{{/toUpper}}{{/detectKeyword}}:
127125
self.uri = uri
128126

129127
{{#methods}}
130-
async def {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(
128+
def {{#detectKeyword}}{{#toLower}}{{name}}{{/toLower}}{{/detectKeyword}}(
131129
self,
132130
args: {{#toUpper}}{{parent.type}}{{/toUpper}}Args{{#toUpper}}{{name}}{{/toUpper}},
133-
client: InvokerClient[UriPackageOrWrapper]
131+
client: InvokerClient
134132
) -> {{#return}}{{#toPython}}{{toGraphQLType}}{{/toPython}}{{/return}}:
135133
return client.invoke(
136-
InvokeOptions(
137-
uri=self.uri,
138-
method="{{name}}",
139-
args=args,
140-
)
134+
uri=self.uri,
135+
method="{{name}}",
136+
args=args,
141137
)
142138
{{^last}}
143139

@@ -160,7 +156,7 @@ class {{#detectKeyword}}{{#toUpper}}{{namespace}}{{/toUpper}}{{/detectKeyword}}:
160156
{{#getImplementations}}
161157
{{#enabled}}
162158
def get_implementations(
163-
client: InvokerClient[UriPackageOrWrapper]
159+
client: InvokerClient
164160
) -> list[str]:
165161
impls = client.getImplementations(self.uri)
166162
return [impl.uri for impl in impls]

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .types import *
99

10-
from polywrap_core import InvokerClient, UriPackageOrWrapper
10+
from polywrap_core import InvokerClient
1111
from polywrap_plugin import PluginModule
1212
from polywrap_msgpack import GenericMap
1313

@@ -58,37 +58,37 @@ def __new__(cls, *args, **kwargs):
5858
return instance
5959

6060
@abstractmethod
61-
async def module_method(
61+
def module_method(
6262
self,
6363
args: ArgsModuleMethod,
64-
client: InvokerClient[UriPackageOrWrapper],
64+
client: InvokerClient,
6565
env: None
6666
) -> int:
6767
pass
6868

6969
@abstractmethod
70-
async def object_method(
70+
def object_method(
7171
self,
7272
args: ArgsObjectMethod,
73-
client: InvokerClient[UriPackageOrWrapper],
73+
client: InvokerClient,
7474
env: Env
7575
) -> Optional["AnotherType"]:
7676
pass
7777

7878
@abstractmethod
79-
async def optional_env_method(
79+
def optional_env_method(
8080
self,
8181
args: ArgsOptionalEnvMethod,
82-
client: InvokerClient[UriPackageOrWrapper],
82+
client: InvokerClient,
8383
env: Optional[Env] = None
8484
) -> Optional["AnotherType"]:
8585
pass
8686

8787
@abstractmethod
88-
async def r_if(
88+
def r_if(
8989
self,
9090
args: ArgsIf,
91-
client: InvokerClient[UriPackageOrWrapper],
91+
client: InvokerClient,
9292
env: None
9393
) -> "Else":
9494
pass

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TypedDict, Optional
66
from enum import IntEnum
77

8-
from polywrap_core import InvokerClient, Uri, UriPackageOrWrapper
8+
from polywrap_core import InvokerClient, Uri
99
from polywrap_msgpack import GenericMap
1010

1111

@@ -194,43 +194,37 @@ class TestImportModule:
194194
def __init__(self, uri: Uri):
195195
self.uri = uri
196196

197-
async def imported_method(
197+
def imported_method(
198198
self,
199199
args: TestImportModuleArgsImportedMethod,
200-
client: InvokerClient[UriPackageOrWrapper]
200+
client: InvokerClient
201201
) -> Optional["TestImportObject"]:
202202
return client.invoke(
203-
InvokeOptions(
204-
uri=self.uri,
205-
method="importedMethod",
206-
args=args,
207-
)
203+
uri=self.uri,
204+
method="importedMethod",
205+
args=args,
208206
)
209207

210-
async def another_method(
208+
def another_method(
211209
self,
212210
args: TestImportModuleArgsAnotherMethod,
213-
client: InvokerClient[UriPackageOrWrapper]
211+
client: InvokerClient
214212
) -> int:
215213
return client.invoke(
216-
InvokeOptions(
217-
uri=self.uri,
218-
method="anotherMethod",
219-
args=args,
220-
)
214+
uri=self.uri,
215+
method="anotherMethod",
216+
args=args,
221217
)
222218

223-
async def returns_array_of_enums(
219+
def returns_array_of_enums(
224220
self,
225221
args: TestImportModuleArgsReturnsArrayOfEnums,
226-
client: InvokerClient[UriPackageOrWrapper]
222+
client: InvokerClient
227223
) -> list[Optional["TestImportEnumReturn"]]:
228224
return client.invoke(
229-
InvokeOptions(
230-
uri=self.uri,
231-
method="returnsArrayOfEnums",
232-
args=args,
233-
)
225+
uri=self.uri,
226+
method="returnsArrayOfEnums",
227+
args=args,
234228
)
235229

236230
### Imported Modules END ###
@@ -242,7 +236,7 @@ class TestImport:
242236
URI: Uri = Uri.from_str("testimport.uri.eth")
243237

244238
def get_implementations(
245-
client: InvokerClient[UriPackageOrWrapper]
239+
client: InvokerClient
246240
) -> list[str]:
247241
impls = client.getImplementations(self.uri)
248242
return [impl.uri for impl in impls]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .types import *
99

10-
from polywrap_core import InvokerClient, UriPackageOrWrapper
10+
from polywrap_core import InvokerClient
1111
from polywrap_plugin import PluginModule
1212
from polywrap_msgpack import GenericMap
1313

@@ -27,10 +27,10 @@ def __new__(cls, *args, **kwargs):
2727
return instance
2828

2929
@abstractmethod
30-
async def sample_method(
30+
def sample_method(
3131
self,
3232
args: ArgsSampleMethod,
33-
client: InvokerClient[UriPackageOrWrapper],
33+
client: InvokerClient,
3434
env: None
3535
) -> str:
3636
pass

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TypedDict, Optional
66
from enum import IntEnum
77

8-
from polywrap_core import InvokerClient, Uri, UriPackageOrWrapper
8+
from polywrap_core import InvokerClient, Uri
99
from polywrap_msgpack import GenericMap
1010

1111

0 commit comments

Comments
 (0)