Skip to content

Commit 8c2615d

Browse files
committed
feat: add docs for polywrap-client
1 parent a5066d8 commit 8c2615d

10 files changed

Lines changed: 103 additions & 8 deletions

File tree

docs/poetry.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ polywrap-core = { path = "../packages/polywrap-core", develop = true }
1717
polywrap-wasm = { path = "../packages/polywrap-wasm", develop = true }
1818
polywrap-plugin = { path = "../packages/polywrap-plugin", develop = true }
1919
polywrap-uri-resolvers = { path = "../packages/polywrap-uri-resolvers", develop = true }
20+
polywrap-client = { path = "../packages/polywrap-client", develop = true }
2021

2122
[tool.poetry.group.dev.dependencies]
2223
sphinx = "^6.1.3"

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Welcome to polywrap-client's documentation!
1616
polywrap-wasm/modules.rst
1717
polywrap-plugin/modules.rst
1818
polywrap-uri-resolvers/modules.rst
19+
polywrap-client/modules.rst
1920

2021

2122

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ..conf import *
2+
3+
import polywrap_client
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
polywrap_client
2+
===============
3+
4+
.. toctree::
5+
:maxdepth: 4
6+
7+
polywrap_client
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
polywrap\_client.client module
2+
==============================
3+
4+
.. automodule:: polywrap_client.client
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
polywrap\_client package
2+
========================
3+
4+
Submodules
5+
----------
6+
7+
.. toctree::
8+
:maxdepth: 4
9+
10+
polywrap_client.client
11+
12+
Module contents
13+
---------------
14+
15+
.. automodule:: polywrap_client
16+
:members:
17+
:undoc-members:
18+
:show-inheritance:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
"""This package contains the Polywrap client implementation."""
12
from .client import *

packages/polywrap-client/polywrap_client/client.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""This module contains the Polywrap client implementation."""
12
from __future__ import annotations
23

34
import json
@@ -13,12 +14,12 @@
1314
GetManifestOptions,
1415
InvokerOptions,
1516
IUriResolutionContext,
16-
UriPackage,
17-
UriResolver,
18-
UriWrapper,
1917
TryResolveUriOptions,
2018
Uri,
19+
UriPackage,
2120
UriPackageOrWrapper,
21+
UriResolver,
22+
UriWrapper,
2223
Wrapper,
2324
)
2425
from polywrap_manifest import AnyWrapManifest
@@ -28,49 +29,78 @@
2829

2930
@dataclass(slots=True, kw_only=True)
3031
class PolywrapClientConfig(ClientConfig):
31-
pass
32+
"""Defines the config type for the Polywrap client.
33+
34+
Attributes:
35+
envs (Dict[Uri, Env]): Dictionary of environments \
36+
where key is URI and value is env.
37+
interfaces (Dict[Uri, List[Uri]]): Dictionary of interfaces \
38+
and their implementations where key is interface URI \
39+
and value is list of implementation URIs.
40+
resolver (UriResolver): URI resolver.
41+
"""
3242

3343

3444
class PolywrapClient(Client):
45+
"""Defines the Polywrap client.
46+
47+
Attributes:
48+
_config (PolywrapClientConfig): The client configuration.
49+
"""
50+
3551
_config: PolywrapClientConfig
3652

3753
def __init__(self, config: PolywrapClientConfig):
54+
"""Initialize a new PolywrapClient instance.
55+
56+
Args:
57+
config (PolywrapClientConfig): The polywrap client config.
58+
"""
3859
self._config = config
3960

4061
def get_config(self):
62+
"""Get the client configuration."""
4163
return self._config
4264

4365
def get_uri_resolver(self) -> UriResolver:
66+
"""Get the URI resolver."""
4467
return self._config.resolver
4568

4669
def get_envs(self) -> Dict[Uri, Env]:
70+
"""Get the dictionary of environment variables."""
4771
envs: Dict[Uri, Env] = self._config.envs
4872
return envs
4973

5074
def get_interfaces(self) -> Dict[Uri, List[Uri]]:
75+
"""Get the interfaces."""
5176
interfaces: Dict[Uri, List[Uri]] = self._config.interfaces
5277
return interfaces
5378

5479
def get_implementations(self, uri: Uri) -> Union[List[Uri], None]:
80+
"""Get the implementations for the given interface URI."""
5581
interfaces: Dict[Uri, List[Uri]] = self.get_interfaces()
5682
return interfaces.get(uri)
5783

5884
def get_env_by_uri(self, uri: Uri) -> Union[Env, None]:
85+
"""Get the environment variables for the given URI."""
5986
return self._config.envs.get(uri)
6087

6188
async def get_file(self, uri: Uri, options: GetFileOptions) -> Union[bytes, str]:
89+
"""Get the file from the given wrapper URI."""
6290
loaded_wrapper = await self.load_wrapper(uri)
6391
return await loaded_wrapper.get_file(options)
6492

6593
async def get_manifest(
6694
self, uri: Uri, options: Optional[GetManifestOptions] = None
6795
) -> AnyWrapManifest:
96+
"""Get the manifest from the given wrapper URI."""
6897
loaded_wrapper = await self.load_wrapper(uri)
6998
return loaded_wrapper.get_manifest()
7099

71100
async def try_resolve_uri(
72101
self, options: TryResolveUriOptions[UriPackageOrWrapper]
73102
) -> UriPackageOrWrapper:
103+
"""Try to resolve the given URI."""
74104
uri = options.uri
75105
uri_resolver = self._config.resolver
76106
resolution_context = options.resolution_context or UriResolutionContext()
@@ -82,6 +112,7 @@ async def load_wrapper(
82112
uri: Uri,
83113
resolution_context: Optional[IUriResolutionContext[UriPackageOrWrapper]] = None,
84114
) -> Wrapper[UriPackageOrWrapper]:
115+
"""Load the wrapper for the given URI."""
85116
resolution_context = resolution_context or UriResolutionContext()
86117

87118
uri_package_or_wrapper = await self.try_resolve_uri(
@@ -101,13 +132,19 @@ async def load_wrapper(
101132
f"""
102133
Error resolving URI "{uri.uri}"
103134
URI not found
104-
Resolution Stack: {json.dumps(build_clean_uri_history(resolution_context.get_history()), indent=2)}
135+
Resolution Stack: {
136+
json.dumps(
137+
build_clean_uri_history(
138+
resolution_context.get_history()
139+
), indent=2
140+
)
141+
}
105142
"""
106143
)
107144
)
108145

109-
110146
async def invoke(self, options: InvokerOptions[UriPackageOrWrapper]) -> Any:
147+
"""Invoke the given wrapper URI."""
111148
resolution_context = options.resolution_context or UriResolutionContext()
112149
wrapper = await self.load_wrapper(
113150
options.uri, resolution_context=resolution_context

packages/polywrap-core/polywrap_core/types/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ClientConfig:
1919
interfaces (Dict[Uri, List[Uri]]): Dictionary of interfaces \
2020
and their implementations where key is interface URI \
2121
and value is list of implementation URIs.
22-
resolver (IUriResolver): URI resolver.
22+
resolver (UriResolver): URI resolver.
2323
"""
2424

2525
envs: Dict[Uri, Env] = field(default_factory=dict)

0 commit comments

Comments
 (0)