Skip to content
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
2 changes: 1 addition & 1 deletion packages/polywrap-client/polywrap_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def load_wrapper(
)
if result.is_err():
return cast(Err, result)
if result.is_ok() and result.ok is None:
if result.is_ok() and result.ok() is None:
return Err.from_str(
dedent(
f"""
Expand Down
2 changes: 1 addition & 1 deletion packages/polywrap-plugin/polywrap_plugin/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
TResult = TypeVar("TResult")


class PluginModule(Generic[TConfig, TResult], ABC):
class PluginModule(Generic[TConfig], ABC):
env: Dict[str, Any]
config: TConfig

Expand Down
14 changes: 7 additions & 7 deletions packages/polywrap-plugin/polywrap_plugin/package.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from typing import Generic, Optional
from typing import Generic, Optional, TypeVar

from polywrap_core import GetManifestOptions, IWrapPackage, Wrapper
from polywrap_manifest import AnyWrapManifest
from polywrap_result import Ok, Result

from .module import PluginModule, TConfig, TResult
from .module import PluginModule
from .wrapper import PluginWrapper

TConfig = TypeVar("TConfig")

class PluginPackage(Generic[TConfig, TResult], IWrapPackage):
module: PluginModule[TConfig, TResult]

class PluginPackage(Generic[TConfig], IWrapPackage):
module: PluginModule[TConfig]
manifest: AnyWrapManifest

def __init__(
self, module: PluginModule[TConfig, TResult], manifest: AnyWrapManifest
):
def __init__(self, module: PluginModule[TConfig], manifest: AnyWrapManifest):
self.module = module
self.manifest = manifest

Expand Down
21 changes: 13 additions & 8 deletions packages/polywrap-plugin/polywrap_plugin/wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Generic, Union, cast
from typing import Any, Dict, Generic, TypeVar, Union, cast

from polywrap_core import (
GetFileOptions,
Expand All @@ -11,14 +11,18 @@
from polywrap_msgpack import msgpack_decode
from polywrap_result import Err, Ok, Result

from .module import PluginModule, TConfig, TResult
from .module import PluginModule


class PluginWrapper(Wrapper, Generic[TConfig, TResult]):
module: PluginModule[TConfig, TResult]
TConfig = TypeVar("TConfig")
TResult = TypeVar("TResult")


class PluginWrapper(Wrapper, Generic[TConfig]):
module: PluginModule[TConfig]

def __init__(
self, module: PluginModule[TConfig, TResult], manifest: AnyWrapManifest
self, module: PluginModule[TConfig], manifest: AnyWrapManifest
) -> None:
self.module = module
self.manifest = manifest
Expand All @@ -34,12 +38,13 @@ async def invoke(
msgpack_decode(args) if isinstance(args, bytes) else args
)

result: Result[TResult] = await self.module.__wrap_invoke__(
options.method, decoded_args, invoker
result = cast(
Result[TResult],
await self.module.__wrap_invoke__(options.method, decoded_args, invoker),
)

if result.is_err():
return cast(Err, result.err)
return cast(Err, result)
return Ok(InvocableResult(result=result.unwrap(), encoded=False))

async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]:
Expand Down
2 changes: 1 addition & 1 deletion packages/polywrap-plugin/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_implementations(self, uri: Uri) -> Result[Union[List[Uri], None]]:

@fixture
def greeting_module():
class GreetingModule(PluginModule[None, str]):
class GreetingModule(PluginModule[None]):
def __init__(self, config: None):
super().__init__(config)

Expand Down
7 changes: 4 additions & 3 deletions packages/polywrap-plugin/tests/test_plugin_module.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import cast
import pytest
from polywrap_result import Ok
from polywrap_result import Ok, Result
from polywrap_core import Invoker
from polywrap_plugin import PluginModule

@pytest.mark.asyncio
async def test_plugin_module(greeting_module: PluginModule[None, str], invoker: Invoker):
result = await greeting_module.__wrap_invoke__("greeting", { "name": "Joe" }, invoker)
async def test_plugin_module(greeting_module: PluginModule[None], invoker: Invoker):
result = cast(Result[str], await greeting_module.__wrap_invoke__("greeting", { "name": "Joe" }, invoker))
assert result, Ok("Greetings from: Joe")
5 changes: 3 additions & 2 deletions packages/polywrap-plugin/tests/test_plugin_package.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import cast

import pytest
from polywrap_core import InvokeOptions, Uri, AnyWrapManifest, Invoker
from polywrap_core import InvokeOptions, Uri, Invoker
from polywrap_manifest import AnyWrapManifest
from polywrap_plugin import PluginPackage, PluginModule
from polywrap_result import Ok

@pytest.mark.asyncio
async def test_plugin_package_invoke(greeting_module: PluginModule[None, str], invoker: Invoker):
async def test_plugin_package_invoke(greeting_module: PluginModule[None], invoker: Invoker):
manifest = cast(AnyWrapManifest, {})
plugin_package = PluginPackage(greeting_module, manifest)
wrapper = (await plugin_package.create_wrapper()).unwrap()
Expand Down
2 changes: 1 addition & 1 deletion packages/polywrap-plugin/tests/test_plugin_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from polywrap_plugin import PluginWrapper, PluginModule

@pytest.mark.asyncio
async def test_plugin_wrapper_invoke(greeting_module: PluginModule[None, str], invoker: Invoker):
async def test_plugin_wrapper_invoke(greeting_module: PluginModule[None], invoker: Invoker):
manifest = cast(AnyWrapManifest, {})

wrapper = PluginWrapper(greeting_module, manifest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def try_resolve_uri_with_resolvers(
result = await resolver.try_resolve_uri(uri, client, sub_context)

if result.is_ok():
result.unwrap()
return result

if not result.is_ok():
step = IUriResolutionStep(
Expand Down