11"""This module contains the PluginWrapper class."""
22# pylint: disable=invalid-name
3- from typing import Generic , TypeVar , Union
3+ # pylint: disable=too-many-arguments
4+ from typing import Any , Generic , Optional , TypeVar , Union
45
56from polywrap_core import (
6- GetFileOptions ,
77 InvocableResult ,
8- InvokeOptions ,
9- Invoker ,
10- UriPackageOrWrapper ,
8+ InvokerClient ,
9+ Uri ,
10+ UriResolutionContext ,
1111 Wrapper ,
1212)
1313from polywrap_manifest import AnyWrapManifest
1414
15- from .module import PluginModule
15+ from .module import InvokeOptions , PluginModule
16+ from .resolution_context_override_client import ResolutionContextOverrideClient
1617
1718TConfig = TypeVar ("TConfig" )
1819TResult = TypeVar ("TResult" )
1920
2021
21- class PluginWrapper (Generic [ TConfig ], Wrapper [ UriPackageOrWrapper ]):
22+ class PluginWrapper (Wrapper , Generic [ TConfig ]):
2223 """PluginWrapper implements the Wrapper interface for plugin wrappers.
2324
2425 Attributes:
@@ -41,31 +42,53 @@ def __init__(
4142 self .module = module
4243 self .manifest = manifest
4344
44- async def invoke (
45+ def invoke (
4546 self ,
46- options : InvokeOptions [UriPackageOrWrapper ],
47- invoker : Invoker [UriPackageOrWrapper ],
47+ uri : Uri ,
48+ method : str ,
49+ args : Optional [Any ] = None ,
50+ env : Optional [Any ] = None ,
51+ resolution_context : Optional [UriResolutionContext ] = None ,
52+ client : Optional [InvokerClient ] = None ,
4853 ) -> InvocableResult :
49- """Invoke a method on the plugin .
54+ """Invoke the Wrapper based on the provided InvokeOptions .
5055
5156 Args:
52- options (InvokeOptions): options to use when invoking the plugin.
53- invoker (Invoker): the invoker to use when invoking the plugin.
57+ uri (Uri): Uri of the wrapper
58+ method (str): Method to be executed
59+ args (Optional[Any]) : Arguments for the method, structured as a dictionary
60+ env (Optional[Any]): Override the client's config for all invokes within this invoke.
61+ resolution_context (Optional[UriResolutionContext]): A URI resolution context
62+ client (Optional[Invoker]): The invoker instance requesting this invocation.\
63+ This invoker will be used for any subinvocation that may occur.
5464
5565 Returns:
56- Result[ InvocableResult]: the result of the invocation.
66+ InvocableResult: Result of the invocation.
5767 """
58- result = await self .module .__wrap_invoke__ (options , invoker )
68+ options = InvokeOptions (
69+ uri = uri ,
70+ method = method ,
71+ args = args ,
72+ env = env ,
73+ resolution_context = resolution_context ,
74+ client = ResolutionContextOverrideClient (client , resolution_context )
75+ if client
76+ else None ,
77+ )
78+ result = self .module .__wrap_invoke__ (options )
5979 return InvocableResult (result = result , encoded = False )
6080
61- async def get_file (self , options : GetFileOptions ) -> Union [str , bytes ]:
62- """Get a file from the plugin.
81+ def get_file (
82+ self , path : str , encoding : Optional [str ] = "utf-8"
83+ ) -> Union [str , bytes ]:
84+ """Get a file from the wrapper.
6385
6486 Args:
65- options (GetFileOptions): options to use when getting the file.
87+ path (str): Path to the file.
88+ encoding (Optional[str]): Encoding of the file.
6689
6790 Returns:
68- Result[ Union[str, bytes]]: the file contents or an error.
91+ Union[str, bytes]: The file contents
6992 """
7093 raise NotImplementedError ("client.get_file(..) is not implemented for plugins" )
7194
@@ -76,3 +99,6 @@ def get_manifest(self) -> AnyWrapManifest:
7699 Result[AnyWrapManifest]: the manifest of the plugin.
77100 """
78101 return self .manifest
102+
103+
104+ __all__ = ["PluginWrapper" ]
0 commit comments