From aed347a8788d2cb9e4d5dbbeb14c399884c52c79 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Fri, 9 Dec 2022 14:37:25 +0400 Subject: [PATCH 1/8] WIP: uri-resolvers --- packages/polywrap-client/pyproject.toml | 3 +- .../types/uri_package_wrapper.py | 6 +- .../polywrap_core/uri_resolution/__init__.py | 2 +- .../uri_resolution/uri_resolution_context.py | 6 +- .../uri_resolution/uri_resolution_result.py | 35 ------ .../utils/get_env_from_uri_history.py | 2 +- packages/polywrap-core/pyproject.toml | 3 +- packages/polywrap-manifest/pyproject.toml | 3 +- packages/polywrap-msgpack/pyproject.toml | 3 +- packages/polywrap-plugin/pyproject.toml | 3 +- packages/polywrap-result/pyproject.toml | 3 +- .../polywrap_uri_resolvers/__init__.py | 10 +- .../polywrap_uri_resolvers/abc/__init__.py | 4 +- .../abc/uri_resolver_aggregator.py | 3 +- .../aggregator/__init__.py | 2 - .../aggregator/uri_resolver_aggregator.py | 19 ---- .../polywrap_uri_resolvers/builder.py | 32 ------ .../polywrap_uri_resolvers/cache/__init__.py | 3 + .../cache/cache_resolver.py | 100 ++++++++++++++++++ .../cache/wrapper_cache.py | 17 +++ .../cache/wrapper_cache_interface.py | 13 +++ .../polywrap_uri_resolvers/errors/__init__.py | 1 + .../errors/infinite_loop_error.py | 14 +++ .../extendable_uri_resolver.py | 48 --------- .../helpers/__init__.py | 3 +- .../helpers/get_uri_resolution_path.py | 27 +++++ .../helpers/infinite_loop_error.py | 7 -- .../helpers/resolver_like_to_resolver.py | 25 +++++ .../helpers/resolver_with_loop_guard.py | 0 .../helpers/uri_resolver_like.py | 5 - .../polywrap_uri_resolvers/legacy/__init__.py | 3 +- .../legacy/base_resolver.py | 2 +- .../{ => legacy}/fs_resolver.py | 12 +-- .../package_resolver.py | 11 +- .../recursive_resolver.py | 43 +++++--- .../redirect_resolver.py | 27 +++++ .../polywrap_uri_resolvers/static_resolver.py | 61 +++++------ .../polywrap_uri_resolvers/types/__init__.py | 6 ++ .../types/static_resolver_like.py | 7 ++ .../types/uri_package.py | 6 +- .../types/uri_redirect.py | 9 ++ .../types/uri_resolver_like.py | 19 ++++ .../types/uri_wrapper.py | 3 +- .../uri_resolver_aggregator.py | 25 +++++ .../uri_resolver_wrapper.py | 31 ------ .../wrapper_resolver.py | 11 +- .../polywrap-uri-resolvers/pyproject.toml | 3 +- packages/polywrap-wasm/pyproject.toml | 3 +- python-monorepo.code-workspace | 6 +- 49 files changed, 412 insertions(+), 278 deletions(-) delete mode 100644 packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_result.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/__init__.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/uri_resolver_aggregator.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/builder.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/extendable_uri_resolver.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/infinite_loop_error.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/uri_resolver_like.py rename packages/polywrap-uri-resolvers/polywrap_uri_resolvers/{ => legacy}/fs_resolver.py (85%) create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py rename packages/{polywrap-core/polywrap_core => polywrap-uri-resolvers/polywrap_uri_resolvers}/types/uri_package.py (57%) create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_redirect.py create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py rename packages/{polywrap-core/polywrap_core => polywrap-uri-resolvers/polywrap_uri_resolvers}/types/uri_wrapper.py (71%) create mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py delete mode 100644 packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_wrapper.py diff --git a/packages/polywrap-client/pyproject.toml b/packages/polywrap-client/pyproject.toml index 9731cd74..c8664759 100644 --- a/packages/polywrap-client/pyproject.toml +++ b/packages/polywrap-client/pyproject.toml @@ -42,7 +42,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-core/polywrap_core/types/uri_package_wrapper.py b/packages/polywrap-core/polywrap_core/types/uri_package_wrapper.py index 9b9ebbc3..5129cd98 100644 --- a/packages/polywrap-core/polywrap_core/types/uri_package_wrapper.py +++ b/packages/polywrap-core/polywrap_core/types/uri_package_wrapper.py @@ -3,7 +3,7 @@ from typing import Union from .uri import Uri -from .uri_package import UriPackage -from .uri_wrapper import UriWrapper +from .wrap_package import IWrapPackage +from .wrapper import Wrapper -UriPackageOrWrapper = Union[Uri, UriWrapper, UriPackage] +UriPackageOrWrapper = Union[Uri, Wrapper, IWrapPackage] diff --git a/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py b/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py index 37e14258..05625f16 100644 --- a/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py +++ b/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py @@ -1,2 +1,2 @@ from .uri_resolution_context import * -from .uri_resolution_result import * + diff --git a/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py b/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py index e3655c86..749e3231 100644 --- a/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py +++ b/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py @@ -1,6 +1,10 @@ from typing import List, Optional, Set -from ..types import IUriResolutionContext, IUriResolutionStep, Uri +from ..types import ( + IUriResolutionContext, + IUriResolutionStep, + Uri, +) class UriResolutionContext(IUriResolutionContext): diff --git a/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_result.py b/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_result.py deleted file mode 100644 index 3d4c815b..00000000 --- a/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_result.py +++ /dev/null @@ -1,35 +0,0 @@ -from typing import List, Optional - -from polywrap_result import Err, Ok, Result - -from ..types import ( - IUriResolutionStep, - IWrapPackage, - Uri, - UriPackage, - UriPackageOrWrapper, - UriWrapper, - Wrapper, -) - - -class UriResolutionResult: - result: Result[UriPackageOrWrapper] - history: Optional[List[IUriResolutionStep]] - - @staticmethod - def ok( - uri: Uri, - package: Optional[IWrapPackage] = None, - wrapper: Optional[Wrapper] = None, - ) -> Result[UriPackageOrWrapper]: - if wrapper: - return Ok(UriWrapper(uri=uri, wrapper=wrapper)) - elif package: - return Ok(UriPackage(uri=uri, package=package)) - else: - return Ok(uri) - - @staticmethod - def err(error: Exception) -> Result[UriPackageOrWrapper]: - return Err(error) diff --git a/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py b/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py index 6c9ef177..2ed445cb 100644 --- a/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py +++ b/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py @@ -1,6 +1,6 @@ from typing import List, Union, Dict, Any -from ..types import Client, Env, Uri +from ..types import Client, Uri def get_env_from_uri_history( diff --git a/packages/polywrap-core/pyproject.toml b/packages/polywrap-core/pyproject.toml index 6e63649d..00723c17 100644 --- a/packages/polywrap-core/pyproject.toml +++ b/packages/polywrap-core/pyproject.toml @@ -35,7 +35,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-manifest/pyproject.toml b/packages/polywrap-manifest/pyproject.toml index 086a7283..6794a425 100644 --- a/packages/polywrap-manifest/pyproject.toml +++ b/packages/polywrap-manifest/pyproject.toml @@ -36,7 +36,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-msgpack/pyproject.toml b/packages/polywrap-msgpack/pyproject.toml index 32a3c0d8..1fefb68c 100644 --- a/packages/polywrap-msgpack/pyproject.toml +++ b/packages/polywrap-msgpack/pyproject.toml @@ -32,7 +32,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-plugin/pyproject.toml b/packages/polywrap-plugin/pyproject.toml index a22e2a40..bfea3e4d 100644 --- a/packages/polywrap-plugin/pyproject.toml +++ b/packages/polywrap-plugin/pyproject.toml @@ -35,7 +35,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-result/pyproject.toml b/packages/polywrap-result/pyproject.toml index ae3a5156..ceb43d04 100644 --- a/packages/polywrap-result/pyproject.toml +++ b/packages/polywrap-result/pyproject.toml @@ -31,7 +31,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py index 2fa3dd46..a9fd2819 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py @@ -1,10 +1,12 @@ from .abc import * -from .aggregator import * from .helpers import * from .legacy import * -from .fs_resolver import * +from .legacy.fs_resolver import * from .legacy.redirect_resolver import * from .static_resolver import * from .recursive_resolver import * -from .uri_resolver_wrapper import * -from .builder import * +from .remove.uri_resolver_wrapper import * +from .remove.builder import * + + +# TODO: ❯ recursive, static, uri aggregator, cache resolver, uri extentions \ No newline at end of file diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py index afccbff7..b5594fa0 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py @@ -1 +1,3 @@ -from .resolver_with_history import * \ No newline at end of file +from .resolver_with_history import * +from .uri_resolver_aggregator import * +from ..cache.wrapper_cache import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py index 484caa49..83cf7ac8 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py @@ -1,9 +1,10 @@ from abc import ABC, abstractmethod from typing import List, cast -from polywrap_core import UriResolutionResult, IUriResolutionStep, IUriResolver, Uri, IUriResolutionContext, Client, UriPackageOrWrapper +from polywrap_core import IUriResolutionStep, IUriResolver, Uri, IUriResolutionContext, Client, UriPackageOrWrapper from polywrap_result import Result, Err + class IUriResolverAggregator(IUriResolver, ABC): @abstractmethod async def get_uri_resolvers(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[List[IUriResolver]]: diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/__init__.py deleted file mode 100644 index 02713d3b..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from ..abc.uri_resolver_aggregator import * -from .uri_resolver_aggregator import * \ No newline at end of file diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/uri_resolver_aggregator.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/uri_resolver_aggregator.py deleted file mode 100644 index 3a3adf9b..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/aggregator/uri_resolver_aggregator.py +++ /dev/null @@ -1,19 +0,0 @@ -from typing import List, Optional - -from polywrap_core import IUriResolver, Uri, IUriResolutionContext, Client -from polywrap_result import Result, Ok - -from ..abc.uri_resolver_aggregator import IUriResolverAggregator - -class UriResolverAggregator(IUriResolverAggregator): - resolvers: List[IUriResolver] - name: Optional[str] - - def __init__(self, resolvers: List[IUriResolver]): - self.resolvers = resolvers - - def get_step_description(self) -> str: - return self.name or "UriResolverAggregator" - - async def get_uri_resolvers(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[List[IUriResolver]]: - return Ok(self.resolvers) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/builder.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/builder.py deleted file mode 100644 index 4f523ad6..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/builder.py +++ /dev/null @@ -1,32 +0,0 @@ -from typing import Optional, List, cast - -from .helpers import UriResolverLike -from .aggregator import UriResolverAggregator -from .package_resolver import PackageResolver -from .wrapper_resolver import WrapperResolver - -from polywrap_core import IUriResolver, UriPackage, UriWrapper - - -# TODO: Recheck if this should return result or not -def build_resolver( - uri_resolver_like: UriResolverLike, name: Optional[str] -) -> IUriResolver: - if isinstance(uri_resolver_like, list): - resolvers: List[IUriResolver] = list( - map( - lambda r: build_resolver(r, name), - uri_resolver_like, - ) - ) - return UriResolverAggregator(resolvers) - elif isinstance(uri_resolver_like, UriPackage): - return PackageResolver( - uri=uri_resolver_like.uri, wrap_package=uri_resolver_like.package - ) - elif isinstance(uri_resolver_like, UriWrapper): - return WrapperResolver( - uri=uri_resolver_like.uri, wrapper=uri_resolver_like.wrapper - ) - else: - raise ValueError("Unknown resolver-like value") diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py new file mode 100644 index 00000000..f9ee37a2 --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py @@ -0,0 +1,3 @@ +from .wrapper_cache_interface import * +from .wrapper_cache import * +from .cache_resolver import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py new file mode 100644 index 00000000..26a7385e --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py @@ -0,0 +1,100 @@ +from typing import Any, List, Optional +from polywrap_core import ( + IUriResolver, + Uri, + Client, + IUriResolutionContext, + IUriResolutionStep, + IWrapPackage, + Wrapper, + UriPackageOrWrapper, +) +from polywrap_manifest import DeserializeManifestOptions +from polywrap_result import Result, Ok +from .wrapper_cache_interface import IWrapperCache + + +class CacheResolverOptions: + deserialize_manifest_options: DeserializeManifestOptions + end_on_redirect: Optional[bool] + + +class PackageToWrapperCacheResolver: + __slots__ = ("name", "resolver_to_cache", "cache", "options") + + name: str + resolver_to_cache: IUriResolver + cache: IWrapperCache + options: CacheResolverOptions + + def __init__( + self, + resolver_to_cache: IUriResolver, + cache: IWrapperCache, + options: CacheResolverOptions, + ): + self.resolver_to_cache = resolver_to_cache + self.cache = cache + self.options = options + + def get_options(self) -> Any: + return self.options + + async def try_resolve_uri( + self, + uri: Uri, + client: Client, + resolution_context: IUriResolutionContext, + ) -> Result[UriPackageOrWrapper]: + if wrapper := self.cache.get(uri): + result = Ok(wrapper) + resolution_context.track_step( + IUriResolutionStep( + source_uri=uri, + result=result, + description="PackageToWrapperCacheResolver (Cache)", + ) + ) + return result + + sub_context = resolution_context.create_sub_history_context() + + result = await self.resolver_to_cache.try_resolve_uri( + uri, + client, + sub_context, + ) + + if result.is_ok(): + uri_package_or_wrapper = result.unwrap() + if isinstance(uri_package_or_wrapper, IWrapPackage): + wrap_package = uri_package_or_wrapper + resolution_path = sub_context.get_resolution_path() + + wrapper_result = await wrap_package.create_wrapper() + + if wrapper_result.is_err(): + return wrapper_result + + wrapper = wrapper_result.unwrap() + + for uri in resolution_path: + self.cache.set(uri, wrapper) + + result = Ok(wrapper) + elif isinstance(uri_package_or_wrapper, Wrapper): + wrapper = uri_package_or_wrapper + resolution_path: List[Uri] = sub_context.get_resolution_path() + + for uri in resolution_path: + self.cache.set(uri, wrapper) + + resolution_context.track_step( + IUriResolutionStep( + source_uri=uri, + result=result, + sub_history=sub_context.get_history(), + description="PackageToWrapperCacheResolver", + ) + ) + return result diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py new file mode 100644 index 00000000..1d8418de --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py @@ -0,0 +1,17 @@ +from typing import Dict, Union +from polywrap_core import Uri, Wrapper + +from .wrapper_cache_interface import IWrapperCache + + +class WrapperCache(IWrapperCache): + map: Dict[Uri, Wrapper] + + def __init__(self): + self.map = {} + + def get(self, uri: Uri) -> Union[Wrapper, None]: + return self.map.get(uri) + + def set(self, uri: Uri, wrapper: Wrapper) -> None: + self.map[uri] = wrapper diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py new file mode 100644 index 00000000..e80b9e9a --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py @@ -0,0 +1,13 @@ +from abc import ABC, abstractmethod +from typing import Union +from polywrap_core import Uri, Wrapper + + +class IWrapperCache(ABC): + @abstractmethod + def get(self, uri: Uri) -> Union[Wrapper, None]: + pass + + @abstractmethod + def set(self, uri: Uri, wrapper: Wrapper) -> None: + pass diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py new file mode 100644 index 00000000..01289f4c --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py @@ -0,0 +1 @@ +from .infinite_loop_error import * \ No newline at end of file diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py new file mode 100644 index 00000000..1b912273 --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py @@ -0,0 +1,14 @@ +from typing import List +from polywrap_core import Uri, IUriResolutionStep +from dataclasses import asdict +import json + +from ..helpers.get_uri_resolution_path import get_uri_resolution_path + + +class InfiniteLoopError(Exception): + def __init__(self, uri: Uri, history: List[IUriResolutionStep]): + super().__init__( + f"An infinite loop was detected while resolving the URI: {uri.uri}\n" + f"History: {json.dumps(asdict(get_uri_resolution_path(history)), indent=2)}" + ) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/extendable_uri_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/extendable_uri_resolver.py deleted file mode 100644 index 8b57816c..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/extendable_uri_resolver.py +++ /dev/null @@ -1,48 +0,0 @@ -from typing import List, cast -from aggregator import IUriResolverAggregator -from polywrap_core import ( - Uri, - Client, - IUriResolutionContext, - IUriResolver, - UriPackageOrWrapper, -) -from polywrap_result import Result, Err, Ok -from polywrap_uri_resolvers import UriResolverWrapper - - -class ExtendableUriResolver(IUriResolverAggregator): - name: str - - def __init__(self, name: str): - self.name = name - - async def get_uri_resolvers( - self, uri: Uri, client: Client, resolution_context: IUriResolutionContext - ) -> Result[List[IUriResolver]]: - result = client.get_implementations(uri) - - if result.is_err(): - return cast(Err, result) - - uri_resolver_impls: List[Uri] = result.unwrap() or [] - - resolvers: List[IUriResolver] = [ - UriResolverWrapper(impl) - for impl in uri_resolver_impls - if not resolution_context.is_resolving(impl) - ] - - return Ok(resolvers) - - async def try_resolve_uri( - self, uri: Uri, client: Client, resolution_context: IUriResolutionContext - ) -> Result[UriPackageOrWrapper]: - result = await self.get_uri_resolvers(uri, client, resolution_context) - - if result.is_err(): - return cast(Err, result) - - resolvers = result.unwrap() - - return await self.try_resolve_uri_with_resolvers(uri, client, resolvers, resolution_context) if resolvers else Ok(uri) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py index 971e2f60..cac650ff 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py @@ -1,2 +1 @@ -from .uri_resolver_like import * -from .infinite_loop_error import * \ No newline at end of file +from .resolver_like_to_resolver import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py new file mode 100644 index 00000000..24e28296 --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py @@ -0,0 +1,27 @@ +from typing import List + +from polywrap_core import IUriResolutionStep, Uri, IWrapPackage, Wrapper + + +def get_uri_resolution_path( + history: List[IUriResolutionStep], +) -> List[IUriResolutionStep]: + # Get all non-empty items from the resolution history + + def add_uri_resolution_path_for_sub_history(step: IUriResolutionStep) -> IUriResolutionStep: + if step.sub_history and len(step.sub_history): + step.sub_history = get_uri_resolution_path(step.sub_history) + return step + + return [ + add_uri_resolution_path_for_sub_history(step) + for step in filter( + lambda step: step.result.is_err() + or ( + isinstance(step.result.unwrap(), Uri) + and step.result.unwrap() != step.source_uri + ) + or isinstance(step.result.unwrap(), (IWrapPackage, Wrapper)), + history, + ) + ] diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/infinite_loop_error.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/infinite_loop_error.py deleted file mode 100644 index 9d37bcc7..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/infinite_loop_error.py +++ /dev/null @@ -1,7 +0,0 @@ -from typing import List -from polywrap_core import Uri, IUriResolutionStep - -class InfiniteLoopError(Exception): - def __init__(self, uri: Uri, history: List[IUriResolutionStep]): - # TODO: Add history with get_resolution_stack - super().__init__(f"An infinite loop was detected while resolving the URI: {uri.uri}") \ No newline at end of file diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py new file mode 100644 index 00000000..f5cfa5dc --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py @@ -0,0 +1,25 @@ +from typing import List, Optional, cast + +from ..types import UriResolverLike, UriRedirect, UriPackage, UriWrapper +from ..uri_resolver_aggregator import UriResolverAggregator +from ..redirect_resolver import RedirectResolver +from ..package_resolver import PackageResolver +from ..wrapper_resolver import WrapperResolver +from ..static_resolver import StaticResolver + +from polywrap_core import IUriResolver + + +def resolver_like_to_resolver(resolver_like: UriResolverLike, resolver_name: Optional[str] = None) -> IUriResolver: + if isinstance(resolver_like, list): + return UriResolverAggregator([resolver_like_to_resolver(x, resolver_name) for x in cast(List[UriResolverLike], resolver_like)]) + elif isinstance(resolver_like, dict): + return StaticResolver(resolver_like) + elif isinstance(resolver_like, UriRedirect): + return RedirectResolver(resolver_like.from_uri, resolver_like.to_uri) + elif isinstance(resolver_like, UriPackage): + return PackageResolver(resolver_like.uri, resolver_like.package) + elif isinstance(resolver_like, UriWrapper): + return WrapperResolver(resolver_like.uri, resolver_like.wrapper) + else: + return UriResolverAggregator([resolver_like], resolver_name) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.py new file mode 100644 index 00000000..e69de29b diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/uri_resolver_like.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/uri_resolver_like.py deleted file mode 100644 index f86bdb77..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/uri_resolver_like.py +++ /dev/null @@ -1,5 +0,0 @@ -from typing import List, Union - -from polywrap_core import Uri, UriPackage, UriWrapper - -UriResolverLike = Union[Uri, UriPackage, UriWrapper, List["UriResolverLike"]] \ No newline at end of file diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py index 709a01e9..0c57c82c 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py @@ -1,2 +1,3 @@ from .base_resolver import * -from .redirect_resolver import * \ No newline at end of file +from .redirect_resolver import * +from .fs_resolver import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/base_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/base_resolver.py index 49e78b9b..a3f49024 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/base_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/base_resolver.py @@ -10,7 +10,7 @@ ) from polywrap_result import Result -from ..fs_resolver import FsUriResolver +from .fs_resolver import FsUriResolver from .redirect_resolver import RedirectUriResolver diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/fs_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/fs_resolver.py similarity index 85% rename from packages/polywrap-uri-resolvers/polywrap_uri_resolvers/fs_resolver.py rename to packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/fs_resolver.py index f1b9bdc5..c1e8e5f9 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/fs_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/fs_resolver.py @@ -7,7 +7,6 @@ IUriResolutionContext, IUriResolver, Uri, - UriPackage, UriPackageOrWrapper, ) from polywrap_result import Err, Ok, Result @@ -49,12 +48,9 @@ async def try_resolve_uri( manifest = manifest_result.unwrap() return Ok( - UriPackage( - uri=uri, - package=WasmPackage( - wasm_module=wasm_module, - manifest=manifest, - file_reader=self.file_reader, - ), + WasmPackage( + wasm_module=wasm_module, + manifest=manifest, + file_reader=self.file_reader, ) ) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py index 4c12ca74..7b281327 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py @@ -1,9 +1,11 @@ -from .abc import IResolverWithHistory +from .abc.resolver_with_history import IResolverWithHistory from polywrap_core import Uri, Client, UriPackageOrWrapper, IUriResolutionContext, IWrapPackage, UriResolutionResult -from polywrap_result import Result +from polywrap_result import Result, Ok class PackageResolver(IResolverWithHistory): + __slots__ = ('uri', 'wrap_package') + uri: Uri wrap_package: IWrapPackage @@ -15,7 +17,4 @@ def get_step_description(self) -> str: return f'Package ({self.uri.uri})' async def _try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result["UriPackageOrWrapper"]: - if uri != self.uri: - return UriResolutionResult.ok(uri) - - return UriResolutionResult.ok(uri, self.wrap_package) \ No newline at end of file + return Ok(uri) if uri != self.uri else Ok(self.wrap_package) \ No newline at end of file diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py index 1f44c489..f81362ce 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py @@ -1,30 +1,45 @@ -from polywrap_core import IUriResolver, Uri, Client, IUriResolutionContext, UriPackageOrWrapper, UriResolutionResult +from polywrap_core import ( + IUriResolver, + Uri, + Client, + IUriResolutionContext, + UriPackageOrWrapper, +) -from polywrap_result import Result +from polywrap_result import Result, Err -from .helpers import UriResolverLike, InfiniteLoopError -from .builder import build_resolver +from .errors import InfiniteLoopError class RecursiveResolver(IUriResolver): + __slots__ = ("resolver",) + resolver: IUriResolver - def __init__(self, resolver: UriResolverLike): - self.resolver = build_resolver(resolver, None) + def __init__(self, resolver: IUriResolver): + self.resolver = resolver - async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + async def try_resolve_uri( + self, uri: Uri, client: Client, resolution_context: IUriResolutionContext + ) -> Result[UriPackageOrWrapper]: if resolution_context.is_resolving(uri): - return UriResolutionResult.err( + return Err( InfiniteLoopError(uri, resolution_context.get_history()) ) - + resolution_context.start_resolving(uri) - result = await self.resolver.try_resolve_uri( - uri, - client, - resolution_context - ) + result = await self.resolver.try_resolve_uri(uri, client, resolution_context) + + if result.is_ok(): + uri_package_or_wrapper = result.unwrap() + if ( + isinstance(uri_package_or_wrapper, Uri) + and uri_package_or_wrapper != uri + ): + result = await self.try_resolve_uri( + uri_package_or_wrapper, client, resolution_context + ) resolution_context.stop_resolving(uri) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py new file mode 100644 index 00000000..195b9dea --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py @@ -0,0 +1,27 @@ +from .abc.resolver_with_history import IResolverWithHistory +from polywrap_core import ( + Uri, + UriPackageOrWrapper, + Client, + IUriResolutionContext, +) +from polywrap_result import Result, Ok + + +class RedirectResolver(IResolverWithHistory): + __slots__ = ("from_uri", "to_uri") + + from_uri: Uri + to_uri: Uri + + def __init__(self, from_uri: Uri, to_uri: Uri) -> None: + self.from_uri = from_uri + self.to_uri = to_uri + + def get_step_description(self) -> str: + return f"Redirect ({self.from_uri} - {self.to_uri})" + + async def _try_resolve_uri( + self, uri: Uri, client: Client, resolution_context: IUriResolutionContext + ) -> Result[UriPackageOrWrapper]: + return Ok(uri) if uri != self.from_uri else Ok(self.to_uri) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py index ac15a671..6cd8a33e 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py @@ -1,52 +1,47 @@ -from typing import Dict, List, cast -from polywrap_core import IUriResolutionStep, UriResolutionResult, IUriResolver, UriPackageOrWrapper, Uri, Client, IUriResolutionContext, UriPackage, UriWrapper +from polywrap_core import ( + IUriResolutionStep, + IUriResolver, + UriPackageOrWrapper, + Uri, + Client, + IUriResolutionContext, + IWrapPackage, + Wrapper, +) from polywrap_result import Result, Ok -from .helpers import UriResolverLike +from .types import StaticResolverLike class StaticResolver(IUriResolver): - uri_map: Dict[Uri, UriPackageOrWrapper] + __slots__ = ("uri_map",) - def __init__(self, uri_map: Dict[Uri, UriPackageOrWrapper]): - self.uri_map = uri_map - - @staticmethod - def from_list(static_resolver_likes: List[UriResolverLike]) -> Result["StaticResolver"]: - uri_map: Dict[Uri, UriPackageOrWrapper] = {} - for static_resolver_like in static_resolver_likes: - if isinstance(static_resolver_like, list): - resolver = StaticResolver.from_list(cast(List[UriResolverLike], static_resolver_like)) - for uri, package_or_wrapper in resolver.unwrap().uri_map.items(): - uri_map[uri] = package_or_wrapper - elif isinstance(static_resolver_like, UriPackage): - uri_package = UriPackage(uri=static_resolver_like.uri, package=static_resolver_like.package) - uri_map[uri_package.uri] = uri_package - elif isinstance(static_resolver_like, UriWrapper): - uri_wrapper = UriWrapper(uri=static_resolver_like.uri, wrapper=static_resolver_like.wrapper) # type: ignore - uri_map[uri_wrapper.uri] = uri_wrapper - else: - uri_map[static_resolver_like] = static_resolver_like + uri_map: StaticResolverLike - return Ok(StaticResolver(uri_map)) + def __init__(self, uri_map: StaticResolverLike): + self.uri_map = uri_map - async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result["UriPackageOrWrapper"]: + async def try_resolve_uri( + self, uri: Uri, client: Client, resolution_context: IUriResolutionContext + ) -> Result["UriPackageOrWrapper"]: uri_package_or_wrapper = self.uri_map.get(uri) - result: Result[UriPackageOrWrapper] = UriResolutionResult.ok(uri) + result: Result[UriPackageOrWrapper] = Ok(uri) description: str = "StaticResolver - Miss" if uri_package_or_wrapper: - if isinstance(uri_package_or_wrapper, UriPackage): - result = UriResolutionResult.ok(uri, uri_package_or_wrapper.package) + if isinstance(uri_package_or_wrapper, IWrapPackage): + result = Ok(uri_package_or_wrapper) description = f"Static - Package ({uri})" - elif isinstance(uri_package_or_wrapper, UriWrapper): - result = UriResolutionResult.ok(uri, None, uri_package_or_wrapper.wrapper) + elif isinstance(uri_package_or_wrapper, Wrapper): + result = Ok(uri_package_or_wrapper) description = f"Static - Wrapper ({uri})" else: - result = UriResolutionResult.ok(uri) - description = f"Static - Wrapper ({uri})" + result = Ok(uri_package_or_wrapper) + description = f"Static - Redirect ({uri}, {uri_package_or_wrapper})" - step = IUriResolutionStep(source_uri=uri, result=result, description=description) + step = IUriResolutionStep( + source_uri=uri, result=result, description=description + ) resolution_context.track_step(step) return result diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py new file mode 100644 index 00000000..683ea59b --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py @@ -0,0 +1,6 @@ +from .static_resolver_like import * +from .uri_resolver_like import * +from .uri_package import * +from .uri_redirect import * +from .uri_wrapper import * +from .wrapper_cache import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py new file mode 100644 index 00000000..d3f01467 --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py @@ -0,0 +1,7 @@ +from typing import Dict +from polywrap_core import ( + UriPackageOrWrapper, + Uri +) + +StaticResolverLike = Dict[Uri, UriPackageOrWrapper] \ No newline at end of file diff --git a/packages/polywrap-core/polywrap_core/types/uri_package.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py similarity index 57% rename from packages/polywrap-core/polywrap_core/types/uri_package.py rename to packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py index 01a42b4f..9a309add 100644 --- a/packages/polywrap-core/polywrap_core/types/uri_package.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py @@ -1,9 +1,5 @@ -from __future__ import annotations - from dataclasses import dataclass - -from .uri import Uri -from .wrap_package import IWrapPackage +from polywrap_core import Uri, IWrapPackage @dataclass(slots=True, kw_only=True) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_redirect.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_redirect.py new file mode 100644 index 00000000..619d003c --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_redirect.py @@ -0,0 +1,9 @@ +from dataclasses import dataclass + +from polywrap_core import Uri + + +@dataclass(slots=True, kw_only=True) +class UriRedirect: + from_uri: Uri + to_uri: Uri diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py new file mode 100644 index 00000000..6eb04f3e --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py @@ -0,0 +1,19 @@ +from __future__ import annotations +from typing import List, Union + +from polywrap_core import IUriResolver + +from .uri_package import UriPackage +from .uri_redirect import UriRedirect +from .uri_wrapper import UriWrapper +from .static_resolver_like import StaticResolverLike + + +UriResolverLike = Union[ + StaticResolverLike, + UriRedirect, + UriPackage, + UriWrapper, + IUriResolver, + List["UriResolverLike"], +] diff --git a/packages/polywrap-core/polywrap_core/types/uri_wrapper.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_wrapper.py similarity index 71% rename from packages/polywrap-core/polywrap_core/types/uri_wrapper.py rename to packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_wrapper.py index 03f7f22a..4388f0e7 100644 --- a/packages/polywrap-core/polywrap_core/types/uri_wrapper.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_wrapper.py @@ -1,7 +1,6 @@ from dataclasses import dataclass -from .uri import Uri -from .wrapper import Wrapper +from polywrap_core import Uri, Wrapper @dataclass(slots=True, kw_only=True) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py new file mode 100644 index 00000000..54abd1bd --- /dev/null +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py @@ -0,0 +1,25 @@ +from typing import List, Optional + +from polywrap_core import IUriResolver, Uri, IUriResolutionContext, Client +from polywrap_result import Result, Ok + +from .abc.uri_resolver_aggregator import IUriResolverAggregator + + +class UriResolverAggregator(IUriResolverAggregator): + __slots__ = ("resolvers", "name") + + resolvers: List[IUriResolver] + name: Optional[str] + + def __init__(self, resolvers: List[IUriResolver], name: Optional[str] = None): + self.name = name + self.resolvers = resolvers + + def get_step_description(self) -> str: + return self.name or "UriResolverAggregator" + + async def get_uri_resolvers( + self, uri: Uri, client: Client, resolution_context: IUriResolutionContext + ) -> Result[List[IUriResolver]]: + return Ok(self.resolvers) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_wrapper.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_wrapper.py deleted file mode 100644 index 9b904ea3..00000000 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_wrapper.py +++ /dev/null @@ -1,31 +0,0 @@ -# TODO: properly implement this -from typing import Union -from polywrap_core import Uri, Client, IUriResolutionContext, UriPackageOrWrapper -from polywrap_uri_resolvers import IResolverWithHistory -from polywrap_result import Result - -class UriResolverWrapper(IResolverWithHistory): - implementation_uri: Uri - - def __init__(self, uri: Uri) -> None: - self.implementation_uri = uri - - def get_step_description(self) -> str: - return f"ResolverExtension ({self.implementation_uri})" - - async def _try_resolve_uri( - self, - uri: Uri, - client: Client, - resolution_context: IUriResolutionContext - ) -> Result[UriPackageOrWrapper]: - raise NotImplemented - - -async def try_resolve_uri_with_implementation( - uri: Uri, - implementation_uri: Uri, - client: Client, - resolution_context: IUriResolutionContext -) -> Result[Union[str, bytes, None]]: - raise NotImplemented diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py index ad7f101d..ae470517 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py @@ -1,16 +1,17 @@ -from .abc import IResolverWithHistory +from .abc.resolver_with_history import IResolverWithHistory from polywrap_core import ( Uri, UriPackageOrWrapper, Wrapper, - UriResolutionResult, Client, IUriResolutionContext, ) -from polywrap_result import Result +from polywrap_result import Result, Ok class WrapperResolver(IResolverWithHistory): + __slots__ = ("uri", "wrapper") + uri: Uri wrapper: Wrapper @@ -24,6 +25,4 @@ def get_step_description(self) -> str: async def _try_resolve_uri( self, uri: Uri, client: Client, resolution_context: IUriResolutionContext ) -> Result[UriPackageOrWrapper]: - if uri != self.uri: - return UriResolutionResult.ok(uri) - return UriResolutionResult.ok(uri, None, self.wrapper) + return Ok(uri) if uri != self.uri else Ok(self.wrapper) diff --git a/packages/polywrap-uri-resolvers/pyproject.toml b/packages/polywrap-uri-resolvers/pyproject.toml index a6375fed..9876a942 100644 --- a/packages/polywrap-uri-resolvers/pyproject.toml +++ b/packages/polywrap-uri-resolvers/pyproject.toml @@ -36,7 +36,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-wasm/pyproject.toml b/packages/polywrap-wasm/pyproject.toml index fb1c44df..7361350c 100644 --- a/packages/polywrap-wasm/pyproject.toml +++ b/packages/polywrap-wasm/pyproject.toml @@ -38,7 +38,8 @@ exclude_dirs = ["tests"] target-version = ["py310"] [tool.pyright] -# default +typeCheckingMode = "strict" +reportShadowedImports = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/python-monorepo.code-workspace b/python-monorepo.code-workspace index d0068837..494b2b2e 100644 --- a/python-monorepo.code-workspace +++ b/python-monorepo.code-workspace @@ -40,6 +40,10 @@ "settings": { "files.exclude": { "**/packages/*": true - } + }, + "docify.programmingLanguage": "python", + "docify.style": "Google", + "docify.intelligentDetection": true, + "docify.sidePanelReviewMode": true } } From 64bd31c253013a18816a39fd464499b3c2e24666 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Fri, 9 Dec 2022 16:09:11 +0400 Subject: [PATCH 2/8] fix: errors --- .../polywrap-client/polywrap_client/client.py | 14 +-- packages/polywrap-client/tests/test_client.py | 5 +- packages/polywrap-client/tests/test_sha3.py | 24 ++-- packages/polywrap-client/tests/test_timer.py | 98 ++++++++--------- .../polywrap_core/types/__init__.py | 3 - .../polywrap_core/types/client.py | 11 +- .../polywrap_core/types/invoke.py | 2 +- .../polywrap_core/types/wasm_package.py | 1 + .../polywrap_core/uri_resolution/__init__.py | 1 - .../uri_resolution/uri_resolution_context.py | 6 +- .../utils/get_env_from_uri_history.py | 2 +- .../polywrap_plugin/__init__.py | 2 +- .../polywrap-plugin/polywrap_plugin/module.py | 19 ++-- .../polywrap_plugin/package.py | 11 +- .../polywrap_plugin/wrapper.py | 22 ++-- .../polywrap_result/__init__.py | 16 +-- packages/polywrap-result/pyproject.toml | 1 + .../polywrap_uri_resolvers/__init__.py | 15 ++- .../polywrap_uri_resolvers/abc/__init__.py | 2 +- .../abc/resolver_with_history.py | 6 +- .../abc/uri_resolver_aggregator.py | 35 ++++-- .../polywrap_uri_resolvers/cache/__init__.py | 4 +- .../cache/cache_resolver.py | 10 +- .../cache/wrapper_cache.py | 1 + .../cache/wrapper_cache_interface.py | 1 + .../polywrap_uri_resolvers/errors/__init__.py | 2 +- .../errors/infinite_loop_error.py | 7 +- .../helpers/get_uri_resolution_path.py | 6 +- .../helpers/resolver_like_to_resolver.py | 23 ++-- .../polywrap_uri_resolvers/legacy/__init__.py | 2 +- .../package_resolver.py | 23 ++-- .../recursive_resolver.py | 11 +- .../redirect_resolver.py | 10 +- .../polywrap_uri_resolvers/static_resolver.py | 10 +- .../polywrap_uri_resolvers/types/__init__.py | 3 +- .../types/static_resolver_like.py | 8 +- .../types/uri_package.py | 3 +- .../types/uri_resolver_like.py | 4 +- .../uri_resolver_aggregator.py | 4 +- .../wrapper_resolver.py | 9 +- .../tests/test_file_resolver.py | 4 +- .../tests/test_static_resolver.py | 104 +++++++++--------- .../polywrap-wasm/polywrap_wasm/imports.py | 3 +- .../polywrap_wasm/inmemory_file_reader.py | 10 +- .../polywrap_wasm/wasm_package.py | 7 +- .../polywrap_wasm/wasm_wrapper.py | 2 +- 46 files changed, 295 insertions(+), 272 deletions(-) diff --git a/packages/polywrap-client/polywrap_client/client.py b/packages/polywrap-client/polywrap_client/client.py index d1e2eb58..2ac5601c 100644 --- a/packages/polywrap-client/polywrap_client/client.py +++ b/packages/polywrap-client/polywrap_client/client.py @@ -7,15 +7,15 @@ from polywrap_core import ( Client, ClientConfig, + Env, GetFileOptions, GetManifestOptions, InvokerOptions, IUriResolutionContext, IUriResolver, TryResolveUriOptions, - Env, Uri, - UriPackage, + IWrapPackage, UriPackageOrWrapper, UriResolutionContext, Wrapper, @@ -61,9 +61,7 @@ def get_implementations(self, uri: Uri) -> Result[Union[List[Uri], None]]: else: return Err.from_str(f"Unable to find implementations for uri: {uri}") - def get_env_by_uri( - self, uri: Uri - ) -> Union[Env, None]: + def get_env_by_uri(self, uri: Uri) -> Union[Env, None]: return self._config.envs.get(uri) async def get_file( @@ -122,10 +120,10 @@ async def load_wrapper( ) ) - if isinstance(uri_package_or_wrapper, UriPackage): - return await uri_package_or_wrapper.package.create_wrapper() + if isinstance(uri_package_or_wrapper, IWrapPackage): + return await uri_package_or_wrapper.create_wrapper() - return Ok(uri_package_or_wrapper.wrapper) + return Ok(uri_package_or_wrapper) async def invoke(self, options: InvokerOptions) -> Result[Any]: resolution_context = options.resolution_context or UriResolutionContext() diff --git a/packages/polywrap-client/tests/test_client.py b/packages/polywrap-client/tests/test_client.py index 663d0125..33900114 100644 --- a/packages/polywrap-client/tests/test_client.py +++ b/packages/polywrap-client/tests/test_client.py @@ -3,7 +3,7 @@ import pytest from polywrap_client import PolywrapClient, PolywrapClientConfig from polywrap_manifest import deserialize_wrap_manifest -from polywrap_core import Uri, InvokerOptions, UriWrapper +from polywrap_core import Uri, InvokerOptions from polywrap_uri_resolvers import BaseUriResolver, SimpleFileReader, StaticResolver from polywrap_result import Result, Ok, Err from polywrap_wasm import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH, IFileReader, WasmWrapper @@ -58,8 +58,7 @@ async def test_invoke( wasm_module=simple_wrap_module, manifest=manifest ) - uri_wrapper = UriWrapper(uri=Uri("ens/wrapper.eth"), wrapper=wrapper) - resolver = StaticResolver.from_list([uri_wrapper]).unwrap() + resolver = StaticResolver({Uri("ens/wrapper.eth"): wrapper}) config = PolywrapClientConfig(resolver=resolver) client = PolywrapClient(config=config) diff --git a/packages/polywrap-client/tests/test_sha3.py b/packages/polywrap-client/tests/test_sha3.py index 4aa52ee9..aeaf4c00 100644 --- a/packages/polywrap-client/tests/test_sha3.py +++ b/packages/polywrap-client/tests/test_sha3.py @@ -19,7 +19,7 @@ async def test_invoke_sha3_512(): result = await client.invoke(options) s = hashlib.sha512() s.update(b"hello polywrap!") - assert result.result == s.digest() + assert result.unwrap() == s.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_sha3_384(): @@ -27,7 +27,7 @@ async def test_invoke_sha3_384(): result = await client.invoke(options) s = hashlib.sha384() s.update(b"hello polywrap!") - assert result.result == s.digest() + assert result.unwrap() == s.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_sha3_256(): @@ -35,7 +35,7 @@ async def test_invoke_sha3_256(): result = await client.invoke(options) s = hashlib.sha256() s.update(b"hello polywrap!") - assert result.result == s.digest() + assert result.unwrap() == s.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_sha3_224(): @@ -43,7 +43,7 @@ async def test_invoke_sha3_224(): result = await client.invoke(options) s = hashlib.sha224() s.update(b"hello polywrap!") - assert result.result == s.digest() + assert result.unwrap() == s.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_keccak_512(): @@ -51,7 +51,7 @@ async def test_invoke_keccak_512(): result = await client.invoke(options) k = keccak.new(digest_bits=512) k.update(b'hello polywrap!') - assert result.result == k.digest() + assert result.unwrap() == k.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_keccak_384(): @@ -59,7 +59,7 @@ async def test_invoke_keccak_384(): result = await client.invoke(options) k = keccak.new(digest_bits=384) k.update(b'hello polywrap!') - assert result.result == k.digest() + assert result.unwrap() == k.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_keccak_256(): @@ -67,7 +67,7 @@ async def test_invoke_keccak_256(): result = await client.invoke(options) k = keccak.new(digest_bits=256) k.update(b'hello polywrap!') - assert result.result == k.digest() + assert result.unwrap() == k.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_keccak_224(): @@ -75,7 +75,7 @@ async def test_invoke_keccak_224(): result = await client.invoke(options) k = keccak.new(digest_bits=224) k.update(b'hello polywrap!') - assert result.result == k.digest() + assert result.unwrap() == k.digest() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_hex_keccak_256(): @@ -83,14 +83,14 @@ async def test_invoke_hex_keccak_256(): result = await client.invoke(options) k = keccak.new(digest_bits=256) k.update(b'hello polywrap!') - assert result.result == k.hexdigest() + assert result.unwrap() == k.hexdigest() @pytest.mark.skip(reason="buffer keccak must be implemented in python in order to assert") async def test_invoke_buffer_keccak_256(): options = InvokerOptions(uri=uri, method="buffer_keccak_256", args=args, encode_result=False) result = await client.invoke(options) # TODO: Not sure exactly what this function `buffer_keccak_256` is doing in order to assert it properly - assert result.result == False + assert result.unwrap() == False @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_shake_256(): @@ -99,7 +99,7 @@ async def test_invoke_shake_256(): result = await client.invoke(options) s = SHAKE256.new() s.update(b"hello polywrap!") - assert result.result == s.read(8).hex() + assert result.unwrap() == s.read(8).hex() @pytest.mark.skip(reason="can't invoke sha3 wrapper due to an error related to wasmtime") async def test_invoke_shake_128(): @@ -108,4 +108,4 @@ async def test_invoke_shake_128(): result = await client.invoke(options) s = SHAKE128.new() s.update(b"hello polywrap!") - assert result.result == s.read(8).hex() \ No newline at end of file + assert result.unwrap() == s.read(8).hex() \ No newline at end of file diff --git a/packages/polywrap-client/tests/test_timer.py b/packages/polywrap-client/tests/test_timer.py index e75a08d8..435b5050 100644 --- a/packages/polywrap-client/tests/test_timer.py +++ b/packages/polywrap-client/tests/test_timer.py @@ -1,49 +1,49 @@ -import asyncio -from typing import Any, Dict - -from pathlib import Path -from polywrap_core import Invoker, Uri, InvokerOptions, UriWrapper, Wrapper -from polywrap_plugin import PluginModule, PluginWrapper -from polywrap_uri_resolvers import StaticResolver -from polywrap_manifest import AnyWrapManifest -from polywrap_result import Result, Ok, Err -from polywrap_client import PolywrapClient, PolywrapClientConfig -from pytest import fixture - - -@fixture -def timer_module(): - class TimerModule(PluginModule[None, str]): - def __init__(self, config: None): - super().__init__(config) - - async def sleep(self, args: Dict[str, Any], client: Invoker): - await asyncio.sleep(args["time"]) - print(f"Woke up after {args['time']} seconds") - return Ok(True) - - return TimerModule(None) - -@fixture -def simple_wrap_manifest(): - wrap_path = Path(__file__).parent / "cases" / "simple-invoke" / "wrap.info" - with open(wrap_path, "rb") as f: - yield f.read() - -@fixture -def timer_wrapper(timer_module: PluginModule[None, str], simple_wrap_manifest: AnyWrapManifest): - return PluginWrapper(module=timer_module, manifest=simple_wrap_manifest) - - -async def test_timer(timer_wrapper: Wrapper): - uri_wrapper = UriWrapper(uri=Uri("ens/timer.eth"), wrapper=timer_wrapper) - resolver = StaticResolver.from_list([uri_wrapper]).unwrap() - - config = PolywrapClientConfig(resolver=resolver) - - client = PolywrapClient(config) - uri = Uri('ens/timer.eth') or Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') - args = { "time": 1 } - options = InvokerOptions(uri=uri, method="sleep", args=args, encode_result=False) - result = await client.invoke(options) - assert result.unwrap() == True \ No newline at end of file +# import asyncio +# from typing import Any, Dict + +# from pathlib import Path +# from polywrap_core import Invoker, Uri, InvokerOptions, UriWrapper, Wrapper +# from polywrap_plugin import PluginModule, PluginWrapper +# from polywrap_uri_resolvers import StaticResolver +# from polywrap_manifest import AnyWrapManifest +# from polywrap_result import Result, Ok, Err +# from polywrap_client import PolywrapClient, PolywrapClientConfig +# from pytest import fixture + + +# @fixture +# def timer_module(): +# class TimerModule(PluginModule[None, str]): +# def __init__(self, config: None): +# super().__init__(config) + +# async def sleep(self, args: Dict[str, Any], client: Invoker): +# await asyncio.sleep(args["time"]) +# print(f"Woke up after {args['time']} seconds") +# return Ok(True) + +# return TimerModule(None) + +# @fixture +# def simple_wrap_manifest(): +# wrap_path = Path(__file__).parent / "cases" / "simple-invoke" / "wrap.info" +# with open(wrap_path, "rb") as f: +# yield f.read() + +# @fixture +# def timer_wrapper(timer_module: PluginModule[None, str], simple_wrap_manifest: AnyWrapManifest): +# return PluginWrapper(module=timer_module, manifest=simple_wrap_manifest) + + +# async def test_timer(timer_wrapper: Wrapper): +# uri_wrapper = UriWrapper(uri=Uri("ens/timer.eth"), wrapper=timer_wrapper) +# resolver = StaticResolver.from_list([uri_wrapper]).unwrap() + +# config = PolywrapClientConfig(resolver=resolver) + +# client = PolywrapClient(config) +# uri = Uri('ens/timer.eth') or Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') +# args = { "time": 1 } +# options = InvokerOptions(uri=uri, method="sleep", args=args, encode_result=False) +# result = await client.invoke(options) +# assert result.unwrap() == True diff --git a/packages/polywrap-core/polywrap_core/types/__init__.py b/packages/polywrap-core/polywrap_core/types/__init__.py index 68b6b46b..540038c2 100644 --- a/packages/polywrap-core/polywrap_core/types/__init__.py +++ b/packages/polywrap-core/polywrap_core/types/__init__.py @@ -2,14 +2,11 @@ from .file_reader import * from .invoke import * from .uri import * -from .uri_package import * from .uri_package_wrapper import * from .uri_resolution_context import * from .uri_resolution_step import * from .uri_resolver import * from .uri_resolver_handler import * -from .uri_wrapper import * -from .wrap_package import * from .wasm_package import * from .wrap_package import * from .wrapper import * diff --git a/packages/polywrap-core/polywrap_core/types/client.py b/packages/polywrap-core/polywrap_core/types/client.py index a3f84854..c95fa5c8 100644 --- a/packages/polywrap-core/polywrap_core/types/client.py +++ b/packages/polywrap-core/polywrap_core/types/client.py @@ -2,20 +2,21 @@ from abc import abstractmethod from dataclasses import dataclass, field -from typing import List, Optional, Union, Dict +from typing import Dict, List, Optional, Union from polywrap_manifest import AnyWrapManifest, DeserializeManifestOptions from polywrap_result import Result +from .env import Env from .invoke import Invoker from .uri import Uri -from .env import Env from .uri_resolver import IUriResolver from .uri_resolver_handler import UriResolverHandler + @dataclass(slots=True, kw_only=True) class ClientConfig: - envs: Dict[Uri, Env] = field(default_factory=dict) + envs: Dict[Uri, Env] = field(default_factory=dict) interfaces: Dict[Uri, List[Uri]] = field(default_factory=dict) resolver: IUriResolver @@ -41,9 +42,7 @@ def get_envs(self) -> Dict[Uri, Env]: pass @abstractmethod - def get_env_by_uri( - self, uri: Uri - ) -> Union[Env, None]: + def get_env_by_uri(self, uri: Uri) -> Union[Env, None]: pass @abstractmethod diff --git a/packages/polywrap-core/polywrap_core/types/invoke.py b/packages/polywrap-core/polywrap_core/types/invoke.py index 47634396..c1dfc289 100644 --- a/packages/polywrap-core/polywrap_core/types/invoke.py +++ b/packages/polywrap-core/polywrap_core/types/invoke.py @@ -6,8 +6,8 @@ from polywrap_result import Result -from .uri import Uri from .env import Env +from .uri import Uri from .uri_resolution_context import IUriResolutionContext diff --git a/packages/polywrap-core/polywrap_core/types/wasm_package.py b/packages/polywrap-core/polywrap_core/types/wasm_package.py index 1ec3a901..3961049b 100644 --- a/packages/polywrap-core/polywrap_core/types/wasm_package.py +++ b/packages/polywrap-core/polywrap_core/types/wasm_package.py @@ -1,6 +1,7 @@ from abc import ABC, abstractmethod from polywrap_result import Result + from .wrap_package import IWrapPackage diff --git a/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py b/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py index 05625f16..0f016bb7 100644 --- a/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py +++ b/packages/polywrap-core/polywrap_core/uri_resolution/__init__.py @@ -1,2 +1 @@ from .uri_resolution_context import * - diff --git a/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py b/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py index 749e3231..e3655c86 100644 --- a/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py +++ b/packages/polywrap-core/polywrap_core/uri_resolution/uri_resolution_context.py @@ -1,10 +1,6 @@ from typing import List, Optional, Set -from ..types import ( - IUriResolutionContext, - IUriResolutionStep, - Uri, -) +from ..types import IUriResolutionContext, IUriResolutionStep, Uri class UriResolutionContext(IUriResolutionContext): diff --git a/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py b/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py index 2ed445cb..61f04a16 100644 --- a/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py +++ b/packages/polywrap-core/polywrap_core/utils/get_env_from_uri_history.py @@ -1,4 +1,4 @@ -from typing import List, Union, Dict, Any +from typing import Any, Dict, List, Union from ..types import Client, Uri diff --git a/packages/polywrap-plugin/polywrap_plugin/__init__.py b/packages/polywrap-plugin/polywrap_plugin/__init__.py index 52e2fcf4..8fc6dc84 100644 --- a/packages/polywrap-plugin/polywrap_plugin/__init__.py +++ b/packages/polywrap-plugin/polywrap_plugin/__init__.py @@ -1,3 +1,3 @@ from .module import * from .package import * -from .wrapper import * \ No newline at end of file +from .wrapper import * diff --git a/packages/polywrap-plugin/polywrap_plugin/module.py b/packages/polywrap-plugin/polywrap_plugin/module.py index 38d4bad0..9866d432 100644 --- a/packages/polywrap-plugin/polywrap_plugin/module.py +++ b/packages/polywrap-plugin/polywrap_plugin/module.py @@ -1,11 +1,12 @@ from abc import ABC -from typing import Any, Dict, TypeVar, Generic, List, cast +from typing import Any, Dict, Generic, List, TypeVar, cast from polywrap_core import Invoker, execute_maybe_async_function from polywrap_result import Err, Ok, Result -TConfig = TypeVar('TConfig') -TResult = TypeVar('TResult') +TConfig = TypeVar("TConfig") +TResult = TypeVar("TResult") + class PluginModule(Generic[TConfig, TResult], ABC): env: Dict[str, Any] @@ -17,7 +18,9 @@ def __init__(self, config: TConfig): def set_env(self, env: Dict[str, Any]) -> None: self.env = env - async def __wrap_invoke__(self, method: str, args: Dict[str, Any], client: Invoker) -> Result[TResult]: + async def __wrap_invoke__( + self, method: str, args: Dict[str, Any], client: Invoker + ) -> Result[TResult]: methods: List[str] = [name for name in dir(self) if name == method] if not methods: @@ -26,10 +29,12 @@ async def __wrap_invoke__(self, method: str, args: Dict[str, Any], client: Invok callable_method = getattr(self, method) if callable(callable_method): try: - result = await execute_maybe_async_function(callable_method, args, client) + result = await execute_maybe_async_function( + callable_method, args, client + ) if isinstance(result, (Ok, Err)): return cast(Result[TResult], result) - return Ok(result) + return Ok(result) except Exception as e: return Err(e) - return Err.from_str(f"{method} is an attribute, not a method") \ No newline at end of file + return Err.from_str(f"{method} is an attribute, not a method") diff --git a/packages/polywrap-plugin/polywrap_plugin/package.py b/packages/polywrap-plugin/polywrap_plugin/package.py index 742051b8..321d5884 100644 --- a/packages/polywrap-plugin/polywrap_plugin/package.py +++ b/packages/polywrap-plugin/polywrap_plugin/package.py @@ -1,20 +1,19 @@ from typing import Generic, Optional, cast -from polywrap_core import IWrapPackage, Wrapper, GetManifestOptions +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 .wrapper import PluginWrapper + class PluginPackage(Generic[TConfig, TResult], IWrapPackage): module: PluginModule[TConfig, TResult] manifest: AnyWrapManifest def __init__( - self, - module: PluginModule[TConfig, TResult], - manifest: AnyWrapManifest + self, module: PluginModule[TConfig, TResult], manifest: AnyWrapManifest ): self.module = module self.manifest = manifest @@ -22,5 +21,7 @@ def __init__( async def create_wrapper(self) -> Result[Wrapper]: return Ok(PluginWrapper(module=self.module, manifest=self.manifest)) - async def get_manifest(self, options: Optional[GetManifestOptions] = None) -> Result[AnyWrapManifest]: + async def get_manifest( + self, options: Optional[GetManifestOptions] = None + ) -> Result[AnyWrapManifest]: return Ok(self.manifest) diff --git a/packages/polywrap-plugin/polywrap_plugin/wrapper.py b/packages/polywrap-plugin/polywrap_plugin/wrapper.py index 94024e0b..c9510f1e 100644 --- a/packages/polywrap-plugin/polywrap_plugin/wrapper.py +++ b/packages/polywrap-plugin/polywrap_plugin/wrapper.py @@ -1,11 +1,11 @@ -from typing import Any, Dict, Union, cast, Generic +from typing import Any, Dict, Generic, Union, cast from polywrap_core import ( GetFileOptions, InvocableResult, InvokeOptions, Invoker, - Wrapper + Wrapper, ) from polywrap_manifest import AnyWrapManifest from polywrap_msgpack import msgpack_decode @@ -13,10 +13,13 @@ from .module import PluginModule, TConfig, TResult + class PluginWrapper(Wrapper, Generic[TConfig, TResult]): module: PluginModule[TConfig, TResult] - def __init__(self, module: PluginModule[TConfig, TResult], manifest: AnyWrapManifest) -> None: + def __init__( + self, module: PluginModule[TConfig, TResult], manifest: AnyWrapManifest + ) -> None: self.module = module self.manifest = manifest @@ -27,17 +30,20 @@ async def invoke( self.module.set_env(env) args: Union[Dict[str, Any], bytes] = options.args or {} - decoded_args: Dict[str, Any] = msgpack_decode(args) if isinstance(args, bytes) else args + decoded_args: Dict[str, Any] = ( + msgpack_decode(args) if isinstance(args, bytes) else args + ) - result: Result[TResult] = await self.module.__wrap_invoke__(options.method, decoded_args, invoker) + result: Result[TResult] = await self.module.__wrap_invoke__( + options.method, decoded_args, invoker + ) if result.is_err(): return cast(Err, result.err) - return Ok(InvocableResult(result=result.unwrap(),encoded=False)) - + return Ok(InvocableResult(result=result.unwrap(), encoded=False)) async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: return Err.from_str("client.get_file(..) is not implemented for plugins") def get_manifest(self) -> Result[AnyWrapManifest]: - return Ok(self.manifest) \ No newline at end of file + return Ok(self.manifest) diff --git a/packages/polywrap-result/polywrap_result/__init__.py b/packages/polywrap-result/polywrap_result/__init__.py index a60b62a5..78c9b638 100644 --- a/packages/polywrap-result/polywrap_result/__init__.py +++ b/packages/polywrap-result/polywrap_result/__init__.py @@ -9,17 +9,7 @@ import inspect import sys import types -from typing import ( - Any, - Callable, - Generic, - NoReturn, - Type, - TypeVar, - Union, - cast, - overload, -) +from typing import Any, Callable, Generic, NoReturn, TypeVar, Union, cast, overload if sys.version_info[:2] >= (3, 10): from typing import ParamSpec @@ -62,7 +52,7 @@ def __eq__(self, other: Any) -> bool: return isinstance(other, Ok) and self.value == cast(Ok[T], other).value def __ne__(self, other: Any) -> bool: - return not (self == other) + return not self == other def __hash__(self) -> int: return hash((True, self._value)) @@ -201,7 +191,7 @@ def __eq__(self, other: Any) -> bool: return isinstance(other, Err) and self.value == other.value def __ne__(self, other: Any) -> bool: - return not (self == other) + return not self == other def __hash__(self) -> int: return hash((False, self._value)) diff --git a/packages/polywrap-result/pyproject.toml b/packages/polywrap-result/pyproject.toml index ceb43d04..a0f5ed2f 100644 --- a/packages/polywrap-result/pyproject.toml +++ b/packages/polywrap-result/pyproject.toml @@ -33,6 +33,7 @@ target-version = ["py310"] [tool.pyright] typeCheckingMode = "strict" reportShadowedImports = false +reportInvalidTypeVarUse = false [tool.pytest.ini_options] asyncio_mode = "auto" diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py index a9fd2819..0169f580 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/__init__.py @@ -1,12 +1,11 @@ +from .types import * from .abc import * +from .errors import * from .helpers import * from .legacy import * -from .legacy.fs_resolver import * -from .legacy.redirect_resolver import * -from .static_resolver import * +from .cache import * from .recursive_resolver import * -from .remove.uri_resolver_wrapper import * -from .remove.builder import * - - -# TODO: ❯ recursive, static, uri aggregator, cache resolver, uri extentions \ No newline at end of file +from .static_resolver import * +from .redirect_resolver import * +from .package_resolver import * +from .wrapper_resolver import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py index b5594fa0..fe041e8e 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/__init__.py @@ -1,3 +1,3 @@ +from ..cache.wrapper_cache import * from .resolver_with_history import * from .uri_resolver_aggregator import * -from ..cache.wrapper_cache import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/resolver_with_history.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/resolver_with_history.py index 63c01522..d06bb5d7 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/resolver_with_history.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/resolver_with_history.py @@ -1,12 +1,12 @@ from abc import ABC, abstractmethod from polywrap_core import ( + Client, + IUriResolutionContext, + IUriResolutionStep, IUriResolver, Uri, - IUriResolutionContext, UriPackageOrWrapper, - Client, - IUriResolutionStep, ) from polywrap_result import Result diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py index 83cf7ac8..ebe12340 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py @@ -1,13 +1,22 @@ from abc import ABC, abstractmethod from typing import List, cast -from polywrap_core import IUriResolutionStep, IUriResolver, Uri, IUriResolutionContext, Client, UriPackageOrWrapper -from polywrap_result import Result, Err +from polywrap_core import ( + Client, + IUriResolutionContext, + IUriResolutionStep, + IUriResolver, + Uri, + UriPackageOrWrapper, +) +from polywrap_result import Err, Result class IUriResolverAggregator(IUriResolver, ABC): @abstractmethod - async def get_uri_resolvers(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[List[IUriResolver]]: + async def get_uri_resolvers( + self, uri: Uri, client: Client, resolution_context: IUriResolutionContext + ) -> Result[List[IUriResolver]]: pass @abstractmethod @@ -23,14 +32,16 @@ async def try_resolve_uri( return cast(Err, resolvers_result) return await self.try_resolve_uri_with_resolvers( - uri, - client, - resolvers_result.unwrap(), - resolution_context + uri, client, resolvers_result.unwrap(), resolution_context ) - - async def try_resolve_uri_with_resolvers(self, uri: Uri, client: Client, resolvers: List[IUriResolver], resolution_context: IUriResolutionContext) -> Result["UriPackageOrWrapper"]: + async def try_resolve_uri_with_resolvers( + self, + uri: Uri, + client: Client, + resolvers: List[IUriResolver], + resolution_context: IUriResolutionContext, + ) -> Result["UriPackageOrWrapper"]: sub_context = resolution_context.create_sub_history_context() for resolver in resolvers: @@ -43,8 +54,8 @@ async def try_resolve_uri_with_resolvers(self, uri: Uri, client: Client, resolve step = IUriResolutionStep( source_uri=uri, result=result, - sub_history=sub_context.get_history(), - description=self.get_step_description() + sub_history=sub_context.get_history(), + description=self.get_step_description(), ) resolution_context.track_step(step) @@ -56,7 +67,7 @@ async def try_resolve_uri_with_resolvers(self, uri: Uri, client: Client, resolve source_uri=uri, result=result, sub_history=sub_context.get_history(), - description=self.get_step_description() + description=self.get_step_description(), ) resolution_context.track_step(step) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py index f9ee37a2..8f5aa050 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/__init__.py @@ -1,3 +1,3 @@ -from .wrapper_cache_interface import * -from .wrapper_cache import * from .cache_resolver import * +from .wrapper_cache import * +from .wrapper_cache_interface import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py index 26a7385e..a86f431f 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/cache_resolver.py @@ -1,16 +1,18 @@ from typing import Any, List, Optional + from polywrap_core import ( - IUriResolver, - Uri, Client, IUriResolutionContext, IUriResolutionStep, + IUriResolver, IWrapPackage, - Wrapper, + Uri, UriPackageOrWrapper, + Wrapper, ) from polywrap_manifest import DeserializeManifestOptions -from polywrap_result import Result, Ok +from polywrap_result import Ok, Result + from .wrapper_cache_interface import IWrapperCache diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py index 1d8418de..74b9f307 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache.py @@ -1,4 +1,5 @@ from typing import Dict, Union + from polywrap_core import Uri, Wrapper from .wrapper_cache_interface import IWrapperCache diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py index e80b9e9a..a92c6f7c 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/cache/wrapper_cache_interface.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod from typing import Union + from polywrap_core import Uri, Wrapper diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py index 01289f4c..a4532063 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/__init__.py @@ -1 +1 @@ -from .infinite_loop_error import * \ No newline at end of file +from .infinite_loop_error import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py index 1b912273..d1cefd1d 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/errors/infinite_loop_error.py @@ -1,7 +1,8 @@ -from typing import List -from polywrap_core import Uri, IUriResolutionStep -from dataclasses import asdict import json +from dataclasses import asdict +from typing import List + +from polywrap_core import IUriResolutionStep, Uri from ..helpers.get_uri_resolution_path import get_uri_resolution_path diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py index 24e28296..02c912e4 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/get_uri_resolution_path.py @@ -1,6 +1,6 @@ from typing import List -from polywrap_core import IUriResolutionStep, Uri, IWrapPackage, Wrapper +from polywrap_core import IUriResolutionStep, IWrapPackage, Uri, Wrapper def get_uri_resolution_path( @@ -8,7 +8,9 @@ def get_uri_resolution_path( ) -> List[IUriResolutionStep]: # Get all non-empty items from the resolution history - def add_uri_resolution_path_for_sub_history(step: IUriResolutionStep) -> IUriResolutionStep: + def add_uri_resolution_path_for_sub_history( + step: IUriResolutionStep, + ) -> IUriResolutionStep: if step.sub_history and len(step.sub_history): step.sub_history = get_uri_resolution_path(step.sub_history) return step diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py index f5cfa5dc..aecf02e0 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.py @@ -1,18 +1,25 @@ from typing import List, Optional, cast -from ..types import UriResolverLike, UriRedirect, UriPackage, UriWrapper -from ..uri_resolver_aggregator import UriResolverAggregator -from ..redirect_resolver import RedirectResolver +from polywrap_core import IUriResolver + from ..package_resolver import PackageResolver -from ..wrapper_resolver import WrapperResolver +from ..redirect_resolver import RedirectResolver from ..static_resolver import StaticResolver - -from polywrap_core import IUriResolver +from ..types import UriPackage, UriRedirect, UriResolverLike, UriWrapper +from ..uri_resolver_aggregator import UriResolverAggregator +from ..wrapper_resolver import WrapperResolver -def resolver_like_to_resolver(resolver_like: UriResolverLike, resolver_name: Optional[str] = None) -> IUriResolver: +def resolver_like_to_resolver( + resolver_like: UriResolverLike, resolver_name: Optional[str] = None +) -> IUriResolver: if isinstance(resolver_like, list): - return UriResolverAggregator([resolver_like_to_resolver(x, resolver_name) for x in cast(List[UriResolverLike], resolver_like)]) + return UriResolverAggregator( + [ + resolver_like_to_resolver(x, resolver_name) + for x in cast(List[UriResolverLike], resolver_like) + ] + ) elif isinstance(resolver_like, dict): return StaticResolver(resolver_like) elif isinstance(resolver_like, UriRedirect): diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py index 0c57c82c..68ee2c9d 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/legacy/__init__.py @@ -1,3 +1,3 @@ from .base_resolver import * -from .redirect_resolver import * from .fs_resolver import * +from .redirect_resolver import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py index 7b281327..27c2f94c 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/package_resolver.py @@ -1,10 +1,17 @@ -from .abc.resolver_with_history import IResolverWithHistory -from polywrap_core import Uri, Client, UriPackageOrWrapper, IUriResolutionContext, IWrapPackage, UriResolutionResult -from polywrap_result import Result, Ok +from polywrap_core import ( + Client, + IUriResolutionContext, + IWrapPackage, + Uri, + UriPackageOrWrapper, +) +from polywrap_result import Ok, Result + +from .abc import IResolverWithHistory class PackageResolver(IResolverWithHistory): - __slots__ = ('uri', 'wrap_package') + __slots__ = ("uri", "wrap_package") uri: Uri wrap_package: IWrapPackage @@ -14,7 +21,9 @@ def __init__(self, uri: Uri, wrap_package: IWrapPackage): self.wrap_package = wrap_package def get_step_description(self) -> str: - return f'Package ({self.uri.uri})' + return f"Package ({self.uri.uri})" - async def _try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result["UriPackageOrWrapper"]: - return Ok(uri) if uri != self.uri else Ok(self.wrap_package) \ No newline at end of file + async def _try_resolve_uri( + self, uri: Uri, client: Client, resolution_context: IUriResolutionContext + ) -> Result["UriPackageOrWrapper"]: + return Ok(uri) if uri != self.uri else Ok(self.wrap_package) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py index f81362ce..435c3a02 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/recursive_resolver.py @@ -1,12 +1,11 @@ from polywrap_core import ( - IUriResolver, - Uri, Client, IUriResolutionContext, + IUriResolver, + Uri, UriPackageOrWrapper, ) - -from polywrap_result import Result, Err +from polywrap_result import Err, Result from .errors import InfiniteLoopError @@ -23,9 +22,7 @@ async def try_resolve_uri( self, uri: Uri, client: Client, resolution_context: IUriResolutionContext ) -> Result[UriPackageOrWrapper]: if resolution_context.is_resolving(uri): - return Err( - InfiniteLoopError(uri, resolution_context.get_history()) - ) + return Err(InfiniteLoopError(uri, resolution_context.get_history())) resolution_context.start_resolving(uri) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py index 195b9dea..acf14c29 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/redirect_resolver.py @@ -1,11 +1,7 @@ +from polywrap_core import Client, IUriResolutionContext, Uri, UriPackageOrWrapper +from polywrap_result import Ok, Result + from .abc.resolver_with_history import IResolverWithHistory -from polywrap_core import ( - Uri, - UriPackageOrWrapper, - Client, - IUriResolutionContext, -) -from polywrap_result import Result, Ok class RedirectResolver(IResolverWithHistory): diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py index 6cd8a33e..6b1168f3 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/static_resolver.py @@ -1,14 +1,14 @@ from polywrap_core import ( - IUriResolutionStep, - IUriResolver, - UriPackageOrWrapper, - Uri, Client, IUriResolutionContext, + IUriResolutionStep, + IUriResolver, IWrapPackage, + Uri, + UriPackageOrWrapper, Wrapper, ) -from polywrap_result import Result, Ok +from polywrap_result import Ok, Result from .types import StaticResolverLike diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py index 683ea59b..8e30a412 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/__init__.py @@ -1,6 +1,5 @@ from .static_resolver_like import * -from .uri_resolver_like import * from .uri_package import * from .uri_redirect import * +from .uri_resolver_like import * from .uri_wrapper import * -from .wrapper_cache import * diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py index d3f01467..20e5aca5 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/static_resolver_like.py @@ -1,7 +1,5 @@ from typing import Dict -from polywrap_core import ( - UriPackageOrWrapper, - Uri -) -StaticResolverLike = Dict[Uri, UriPackageOrWrapper] \ No newline at end of file +from polywrap_core import Uri, UriPackageOrWrapper + +StaticResolverLike = Dict[Uri, UriPackageOrWrapper] diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py index 9a309add..688ba593 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_package.py @@ -1,5 +1,6 @@ from dataclasses import dataclass -from polywrap_core import Uri, IWrapPackage + +from polywrap_core import IWrapPackage, Uri @dataclass(slots=True, kw_only=True) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py index 6eb04f3e..21413572 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/types/uri_resolver_like.py @@ -1,13 +1,13 @@ from __future__ import annotations + from typing import List, Union from polywrap_core import IUriResolver +from .static_resolver_like import StaticResolverLike from .uri_package import UriPackage from .uri_redirect import UriRedirect from .uri_wrapper import UriWrapper -from .static_resolver_like import StaticResolverLike - UriResolverLike = Union[ StaticResolverLike, diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py index 54abd1bd..af5d4f0b 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/uri_resolver_aggregator.py @@ -1,7 +1,7 @@ from typing import List, Optional -from polywrap_core import IUriResolver, Uri, IUriResolutionContext, Client -from polywrap_result import Result, Ok +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri +from polywrap_result import Ok, Result from .abc.uri_resolver_aggregator import IUriResolverAggregator diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py index ae470517..00a5c9cb 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/wrapper_resolver.py @@ -1,12 +1,13 @@ -from .abc.resolver_with_history import IResolverWithHistory from polywrap_core import ( + Client, + IUriResolutionContext, Uri, UriPackageOrWrapper, Wrapper, - Client, - IUriResolutionContext, ) -from polywrap_result import Result, Ok +from polywrap_result import Ok, Result + +from .abc.resolver_with_history import IResolverWithHistory class WrapperResolver(IResolverWithHistory): diff --git a/packages/polywrap-uri-resolvers/tests/test_file_resolver.py b/packages/polywrap-uri-resolvers/tests/test_file_resolver.py index aa9e6c11..8908f36c 100644 --- a/packages/polywrap-uri-resolvers/tests/test_file_resolver.py +++ b/packages/polywrap-uri-resolvers/tests/test_file_resolver.py @@ -2,7 +2,7 @@ from pathlib import Path -from polywrap_core import IFileReader, IUriResolver, Uri, UriPackage +from polywrap_core import IFileReader, IUriResolver, Uri, IWrapPackage from polywrap_uri_resolvers import FsUriResolver, SimpleFileReader @pytest.fixture @@ -22,4 +22,4 @@ async def test_file_resolver(fs_resolver: IUriResolver): result = await fs_resolver.try_resolve_uri(uri, None, None) # type: ignore assert result.is_ok - assert isinstance(result.unwrap(), UriPackage) + assert isinstance(result.unwrap(), IWrapPackage) diff --git a/packages/polywrap-uri-resolvers/tests/test_static_resolver.py b/packages/polywrap-uri-resolvers/tests/test_static_resolver.py index f7733860..2ddeae58 100644 --- a/packages/polywrap-uri-resolvers/tests/test_static_resolver.py +++ b/packages/polywrap-uri-resolvers/tests/test_static_resolver.py @@ -1,70 +1,70 @@ -import pytest -from pathlib import Path +# import pytest +# from pathlib import Path -from polywrap_result import Ok, Err, Result -from polywrap_wasm import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH, IFileReader, WasmPackage, WasmWrapper -from polywrap_core import UriPackage, Uri, UriResolutionContext, UriWrapper, IWrapPackage -from polywrap_client import PolywrapClient -from polywrap_uri_resolvers import StaticResolver -from polywrap_manifest import deserialize_wrap_manifest +# from polywrap_result import Ok, Err, Result +# from polywrap_wasm import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH, IFileReader, WasmPackage, WasmWrapper +# from polywrap_core import UriPackage, Uri, UriResolutionContext, UriWrapper, IWrapPackage +# from polywrap_client import PolywrapClient +# from polywrap_uri_resolvers import StaticResolver +# from polywrap_manifest import deserialize_wrap_manifest -@pytest.fixture -def simple_wrap_module(): - wrap_path = Path(__file__).parent / "cases" / "simple" / "wrap.wasm" - with open(wrap_path, "rb") as f: - yield f.read() +# @pytest.fixture +# def simple_wrap_module(): +# wrap_path = Path(__file__).parent / "cases" / "simple" / "wrap.wasm" +# with open(wrap_path, "rb") as f: +# yield f.read() -@pytest.fixture -def simple_wrap_manifest(): - wrap_path = Path(__file__).parent / "cases" / "simple" / "wrap.info" - with open(wrap_path, "rb") as f: - yield f.read() +# @pytest.fixture +# def simple_wrap_manifest(): +# wrap_path = Path(__file__).parent / "cases" / "simple" / "wrap.info" +# with open(wrap_path, "rb") as f: +# yield f.read() -@pytest.fixture -def simple_file_reader(simple_wrap_module: bytes, simple_wrap_manifest: bytes): - class FileReader(IFileReader): - async def read_file(self, file_path: str) -> Result[bytes]: - if file_path == WRAP_MODULE_PATH: - return Ok(simple_wrap_module) - if file_path == WRAP_MANIFEST_PATH: - return Ok(simple_wrap_manifest) - return Err.from_str(f"FileNotFound: {file_path}") +# @pytest.fixture +# def simple_file_reader(simple_wrap_module: bytes, simple_wrap_manifest: bytes): +# class FileReader(IFileReader): +# async def read_file(self, file_path: str) -> Result[bytes]: +# if file_path == WRAP_MODULE_PATH: +# return Ok(simple_wrap_module) +# if file_path == WRAP_MANIFEST_PATH: +# return Ok(simple_wrap_manifest) +# return Err.from_str(f"FileNotFound: {file_path}") - yield FileReader() +# yield FileReader() -@pytest.mark.asyncio -async def test_static_resolver( - simple_file_reader: IFileReader, - simple_wrap_module: bytes, - simple_wrap_manifest: bytes -): - package = WasmPackage(simple_file_reader) +# @pytest.mark.asyncio +# async def test_static_resolver( +# simple_file_reader: IFileReader, +# simple_wrap_module: bytes, +# simple_wrap_manifest: bytes +# ): +# package = WasmPackage(simple_file_reader) - manifest = deserialize_wrap_manifest(simple_wrap_manifest).unwrap() - wrapper = WasmWrapper(simple_file_reader, simple_wrap_module, manifest) +# manifest = deserialize_wrap_manifest(simple_wrap_manifest).unwrap() +# wrapper = WasmWrapper(simple_file_reader, simple_wrap_module, manifest) - uri_wrapper = UriWrapper(uri=Uri("ens/wrapper.eth"), wrapper=wrapper) - uri_package = UriPackage(uri=Uri("ens/package.eth"), package=package) +# uri_wrapper = UriWrapper(uri=Uri("ens/wrapper.eth"), wrapper=wrapper) +# uri_package = UriPackage(uri=Uri("ens/package.eth"), package=package) - resolver = StaticResolver.from_list([ uri_package, uri_wrapper, [ - UriPackage(uri=Uri("ens/nested-package.eth"), package=package) - ]]).unwrap() +# resolver = StaticResolver.from_list([ uri_package, uri_wrapper, [ +# UriPackage(uri=Uri("ens/nested-package.eth"), package=package) +# ]]).unwrap() - resolution_context = UriResolutionContext() - result = await resolver.try_resolve_uri(Uri("ens/package.eth"), PolywrapClient(), resolution_context) +# resolution_context = UriResolutionContext() +# result = await resolver.try_resolve_uri(Uri("ens/package.eth"), PolywrapClient(), resolution_context) - assert result.is_ok - assert isinstance((result.unwrap()).package, IWrapPackage) +# assert result.is_ok +# assert isinstance((result.unwrap()).package, IWrapPackage) - result = await resolver.try_resolve_uri(Uri("ens/wrapper.eth"), PolywrapClient(), resolution_context) +# result = await resolver.try_resolve_uri(Uri("ens/wrapper.eth"), PolywrapClient(), resolution_context) - assert result.is_ok - assert isinstance((result.unwrap()).wrapper, WasmWrapper) +# assert result.is_ok +# assert isinstance((result.unwrap()).wrapper, WasmWrapper) - result = await resolver.try_resolve_uri(Uri("ens/nested-package.eth"), PolywrapClient(), resolution_context) +# result = await resolver.try_resolve_uri(Uri("ens/nested-package.eth"), PolywrapClient(), resolution_context) - assert result.is_ok - assert isinstance((result.unwrap()).package, IWrapPackage) +# assert result.is_ok +# assert isinstance((result.unwrap()).package, IWrapPackage) diff --git a/packages/polywrap-wasm/polywrap_wasm/imports.py b/packages/polywrap-wasm/polywrap_wasm/imports.py index ba562013..5df718b9 100644 --- a/packages/polywrap-wasm/polywrap_wasm/imports.py +++ b/packages/polywrap-wasm/polywrap_wasm/imports.py @@ -1,8 +1,9 @@ from textwrap import dedent from typing import Any, List, cast + from polywrap_core import Invoker, InvokerOptions, Uri -from polywrap_result import Result, Ok, Err from polywrap_msgpack import msgpack_encode +from polywrap_result import Err, Ok, Result from unsync import Unfuture, unsync from wasmtime import ( FuncType, diff --git a/packages/polywrap-wasm/polywrap_wasm/inmemory_file_reader.py b/packages/polywrap-wasm/polywrap_wasm/inmemory_file_reader.py index cff1cd73..df7732fa 100644 --- a/packages/polywrap-wasm/polywrap_wasm/inmemory_file_reader.py +++ b/packages/polywrap-wasm/polywrap_wasm/inmemory_file_reader.py @@ -1,6 +1,7 @@ from typing import Optional + from polywrap_core import IFileReader -from polywrap_result import Result, Ok +from polywrap_result import Ok, Result from .constants import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH @@ -10,7 +11,12 @@ class InMemoryFileReader(IFileReader): _wasm_module: Optional[bytes] _base_file_reader: IFileReader - def __init__(self, base_file_reader: IFileReader, wasm_module: Optional[bytes] = None, wasm_manifest: Optional[bytes] = None): + def __init__( + self, + base_file_reader: IFileReader, + wasm_module: Optional[bytes] = None, + wasm_manifest: Optional[bytes] = None, + ): self._wasm_module = wasm_module self._wasm_manifest = wasm_manifest self._base_file_reader = base_file_reader diff --git a/packages/polywrap-wasm/polywrap_wasm/wasm_package.py b/packages/polywrap-wasm/polywrap_wasm/wasm_package.py index c4aa533b..d15e689d 100644 --- a/packages/polywrap-wasm/polywrap_wasm/wasm_package.py +++ b/packages/polywrap-wasm/polywrap_wasm/wasm_package.py @@ -1,8 +1,8 @@ from typing import Optional, Union, cast -from polywrap_core import IFileReader, IWasmPackage, Wrapper, GetManifestOptions +from polywrap_core import GetManifestOptions, IFileReader, IWasmPackage, Wrapper from polywrap_manifest import AnyWrapManifest, deserialize_wrap_manifest -from polywrap_result import Result, Ok, Err +from polywrap_result import Err, Ok, Result from .constants import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH from .inmemory_file_reader import InMemoryFileReader @@ -38,7 +38,7 @@ async def get_manifest( if self.manifest: encoded_manifest = self.manifest else: - result = await self.file_reader.read_file(WRAP_MANIFEST_PATH) + result = await self.file_reader.read_file(WRAP_MANIFEST_PATH) if result.is_err(): return cast(Err, result) encoded_manifest = result.unwrap() @@ -58,7 +58,6 @@ async def get_wasm_module(self) -> Result[bytes]: self.wasm_module = result.unwrap() return Ok(self.wasm_module) - async def create_wrapper(self) -> Result[Wrapper]: wasm_module_result = await self.get_wasm_module() if wasm_module_result.is_err(): diff --git a/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py b/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py index 5ee874ac..345df792 100644 --- a/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py +++ b/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py @@ -11,7 +11,7 @@ ) from polywrap_manifest import AnyWrapManifest from polywrap_msgpack import msgpack_encode -from polywrap_result import Result, Ok, Err +from polywrap_result import Err, Ok, Result from wasmtime import Module, Store from .exports import WrapExports From e8a28f28fbe2ebe380ef719213377b93ae8b2a8e Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Fri, 9 Dec 2022 16:32:11 +0400 Subject: [PATCH 3/8] fix: typings --- packages/polywrap-client/tests/test_client.py | 5 +- .../typings/polywrap_core/__init__.pyi | 8 + .../typings/polywrap_core/types/__init__.pyi | 18 + .../typings/polywrap_core/types/client.pyi | 60 ++++ .../typings/polywrap_core/types/env.pyi | 7 + .../polywrap_core/types/file_reader.pyi | 14 + .../typings/polywrap_core/types/invoke.pyi | 67 ++++ .../typings/polywrap_core/types/uri.pyi | 81 +++++ .../types/uri_package_wrapper.pyi | 10 + .../types/uri_resolution_context.pyi | 44 +++ .../types/uri_resolution_step.pyi | 20 ++ .../polywrap_core/types/uri_resolver.pyi | 35 ++ .../types/uri_resolver_handler.pyi | 19 ++ .../polywrap_core/types/wasm_package.pyi | 15 + .../polywrap_core/types/wrap_package.pyi | 22 ++ .../typings/polywrap_core/types/wrapper.pyi | 34 ++ .../polywrap_core/uri_resolution/__init__.pyi | 6 + .../uri_resolution/uri_resolution_context.pyi | 41 +++ .../typings/polywrap_core/utils/__init__.pyi | 9 + .../utils/get_env_from_uri_history.pyi | 10 + .../polywrap_core/utils/init_wrapper.pyi | 10 + .../polywrap_core/utils/instance_of.pyi | 9 + .../polywrap_core/utils/maybe_async.pyi | 12 + .../typings/polywrap_manifest/__init__.pyi | 7 + .../typings/polywrap_manifest/deserialize.pyi | 16 + .../typings/polywrap_manifest/manifest.pyi | 44 +++ .../typings/polywrap_manifest/wrap_0_1.pyi | 209 ++++++++++++ .../typings/polywrap_msgpack/__init__.pyi | 74 ++++ .../typings/polywrap_result/__init__.pyi | 322 ++++++++++++++++++ .../polywrap_uri_resolvers/__init__.pyi | 16 + .../polywrap_uri_resolvers/abc/__init__.pyi | 8 + .../abc/resolver_with_history.pyi | 17 + .../abc/uri_resolver_aggregator.pyi | 26 ++ .../polywrap_uri_resolvers/cache/__init__.pyi | 8 + .../cache/cache_resolver.pyi | 33 ++ .../cache/wrapper_cache.pyi | 21 ++ .../cache/wrapper_cache_interface.pyi | 19 ++ .../errors/__init__.pyi | 6 + .../errors/infinite_loop_error.pyi | 13 + .../helpers/__init__.pyi | 6 + .../helpers/get_uri_resolution_path.pyi | 10 + .../helpers/resolver_like_to_resolver.pyi | 11 + .../helpers/resolver_with_loop_guard.pyi | 4 + .../legacy/__init__.pyi | 8 + .../legacy/base_resolver.pyi | 21 ++ .../legacy/fs_resolver.pyi | 23 ++ .../legacy/redirect_resolver.pyi | 18 + .../package_resolver.pyi | 19 ++ .../recursive_resolver.pyi | 18 + .../redirect_resolver.pyi | 19 ++ .../static_resolver.pyi | 19 ++ .../polywrap_uri_resolvers/types/__init__.pyi | 10 + .../types/static_resolver_like.pyi | 8 + .../types/uri_package.pyi | 14 + .../types/uri_redirect.pyi | 14 + .../types/uri_resolver_like.pyi | 12 + .../types/uri_wrapper.pyi | 14 + .../uri_resolver_aggregator.pyi | 24 ++ .../wrapper_resolver.pyi | 19 ++ .../typings/polywrap_wasm/__init__.pyi | 14 + .../typings/polywrap_wasm/buffer.pyi | 22 ++ .../typings/polywrap_wasm/constants.pyi | 6 + .../typings/polywrap_wasm/errors.pyi | 15 + .../typings/polywrap_wasm/exports.pyi | 18 + .../typings/polywrap_wasm/imports.pyi | 21 ++ .../polywrap_wasm/inmemory_file_reader.pyi | 20 ++ .../typings/polywrap_wasm/types/__init__.pyi | 6 + .../typings/polywrap_wasm/types/state.pyi | 38 +++ .../typings/polywrap_wasm/wasm_package.pyi | 27 ++ .../typings/polywrap_wasm/wasm_wrapper.pyi | 35 ++ .../polywrap_core/types/__init__.py | 1 + .../polywrap_core/types/wasm_package.py | 2 +- .../polywrap_core/types/wrapper.py | 6 +- .../typings/polywrap_manifest/__init__.pyi | 7 + .../typings/polywrap_manifest/deserialize.pyi | 16 + .../typings/polywrap_manifest/manifest.pyi | 45 +++ .../typings/polywrap_manifest/wrap_0_1.pyi | 209 ++++++++++++ .../typings/polywrap_result/__init__.pyi | 322 ++++++++++++++++++ .../polywrap_plugin/package.py | 2 +- .../typings/polywrap_core/__init__.pyi | 8 + .../typings/polywrap_core/types/__init__.pyi | 19 ++ .../typings/polywrap_core/types/client.pyi | 60 ++++ .../typings/polywrap_core/types/env.pyi | 7 + .../polywrap_core/types/file_reader.pyi | 14 + .../typings/polywrap_core/types/invoke.pyi | 67 ++++ .../typings/polywrap_core/types/uri.pyi | 81 +++++ .../polywrap_core/types/uri_package.pyi | 15 + .../types/uri_package_wrapper.pyi | 10 + .../types/uri_resolution_context.pyi | 44 +++ .../types/uri_resolution_step.pyi | 20 ++ .../polywrap_core/types/uri_resolver.pyi | 35 ++ .../types/uri_resolver_handler.pyi | 19 ++ .../polywrap_core/types/uri_wrapper.pyi | 15 + .../polywrap_core/types/wasm_package.pyi | 15 + .../polywrap_core/types/wrap_package.pyi | 22 ++ .../typings/polywrap_core/types/wrapper.pyi | 34 ++ .../polywrap_core/uri_resolution/__init__.pyi | 7 + .../uri_resolution/uri_resolution_context.pyi | 41 +++ .../uri_resolution/uri_resolution_result.pyi | 21 ++ .../typings/polywrap_core/utils/__init__.pyi | 9 + .../utils/get_env_from_uri_history.pyi | 10 + .../polywrap_core/utils/init_wrapper.pyi | 10 + .../polywrap_core/utils/instance_of.pyi | 9 + .../polywrap_core/utils/maybe_async.pyi | 12 + .../typings/polywrap_manifest/__init__.pyi | 7 + .../typings/polywrap_manifest/deserialize.pyi | 16 + .../typings/polywrap_manifest/manifest.pyi | 44 +++ .../typings/polywrap_manifest/wrap_0_1.pyi | 209 ++++++++++++ .../typings/polywrap_msgpack/__init__.pyi | 74 ++++ .../typings/polywrap_result/__init__.pyi | 322 ++++++++++++++++++ .../abc/uri_resolver_aggregator.py | 4 +- .../typings/polywrap_core/__init__.pyi | 8 + .../typings/polywrap_core/types/__init__.pyi | 17 + .../typings/polywrap_core/types/client.pyi | 60 ++++ .../typings/polywrap_core/types/env.pyi | 7 + .../polywrap_core/types/file_reader.pyi | 14 + .../typings/polywrap_core/types/invoke.pyi | 67 ++++ .../typings/polywrap_core/types/uri.pyi | 81 +++++ .../types/uri_package_wrapper.pyi | 10 + .../types/uri_resolution_context.pyi | 44 +++ .../types/uri_resolution_step.pyi | 20 ++ .../polywrap_core/types/uri_resolver.pyi | 35 ++ .../types/uri_resolver_handler.pyi | 19 ++ .../polywrap_core/types/wasm_package.pyi | 15 + .../polywrap_core/types/wrap_package.pyi | 22 ++ .../typings/polywrap_core/types/wrapper.pyi | 34 ++ .../polywrap_core/uri_resolution/__init__.pyi | 6 + .../uri_resolution/uri_resolution_context.pyi | 41 +++ .../typings/polywrap_core/utils/__init__.pyi | 9 + .../utils/get_env_from_uri_history.pyi | 10 + .../polywrap_core/utils/init_wrapper.pyi | 10 + .../polywrap_core/utils/instance_of.pyi | 9 + .../polywrap_core/utils/maybe_async.pyi | 12 + .../typings/polywrap_manifest/__init__.pyi | 7 + .../typings/polywrap_manifest/deserialize.pyi | 16 + .../typings/polywrap_manifest/manifest.pyi | 44 +++ .../typings/polywrap_manifest/wrap_0_1.pyi | 209 ++++++++++++ .../typings/polywrap_result/__init__.pyi | 322 ++++++++++++++++++ .../typings/polywrap_wasm/__init__.pyi | 14 + .../typings/polywrap_wasm/buffer.pyi | 22 ++ .../typings/polywrap_wasm/constants.pyi | 6 + .../typings/polywrap_wasm/errors.pyi | 15 + .../typings/polywrap_wasm/exports.pyi | 18 + .../typings/polywrap_wasm/imports.pyi | 21 ++ .../polywrap_wasm/inmemory_file_reader.pyi | 20 ++ .../typings/polywrap_wasm/types/__init__.pyi | 6 + .../typings/polywrap_wasm/types/state.pyi | 38 +++ .../typings/polywrap_wasm/wasm_package.pyi | 27 ++ .../typings/polywrap_wasm/wasm_wrapper.pyi | 35 ++ .../polywrap-wasm/polywrap_wasm/buffer.py | 2 +- .../polywrap-wasm/polywrap_wasm/imports.py | 3 +- .../polywrap_wasm/wasm_wrapper.py | 4 +- .../typings/polywrap_core/__init__.pyi | 8 + .../typings/polywrap_core/types/__init__.pyi | 17 + .../typings/polywrap_core/types/client.pyi | 60 ++++ .../typings/polywrap_core/types/env.pyi | 7 + .../polywrap_core/types/file_reader.pyi | 14 + .../typings/polywrap_core/types/invoke.pyi | 67 ++++ .../typings/polywrap_core/types/uri.pyi | 81 +++++ .../types/uri_package_wrapper.pyi | 10 + .../types/uri_resolution_context.pyi | 44 +++ .../types/uri_resolution_step.pyi | 20 ++ .../polywrap_core/types/uri_resolver.pyi | 35 ++ .../types/uri_resolver_handler.pyi | 19 ++ .../polywrap_core/types/wasm_package.pyi | 15 + .../polywrap_core/types/wrap_package.pyi | 22 ++ .../typings/polywrap_core/types/wrapper.pyi | 34 ++ .../polywrap_core/uri_resolution/__init__.pyi | 6 + .../uri_resolution/uri_resolution_context.pyi | 41 +++ .../typings/polywrap_core/utils/__init__.pyi | 9 + .../utils/get_env_from_uri_history.pyi | 10 + .../polywrap_core/utils/init_wrapper.pyi | 10 + .../polywrap_core/utils/instance_of.pyi | 9 + .../polywrap_core/utils/maybe_async.pyi | 12 + .../typings/polywrap_manifest/__init__.pyi | 7 + .../typings/polywrap_manifest/deserialize.pyi | 16 + .../typings/polywrap_manifest/manifest.pyi | 44 +++ .../typings/polywrap_manifest/wrap_0_1.pyi | 209 ++++++++++++ .../typings/polywrap_msgpack/__init__.pyi | 74 ++++ .../typings/polywrap_result/__init__.pyi | 322 ++++++++++++++++++ 180 files changed, 6384 insertions(+), 15 deletions(-) create mode 100644 packages/polywrap-client/typings/polywrap_core/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/client.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/env.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/file_reader.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/invoke.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/uri.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/uri_package_wrapper.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/uri_resolution_context.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/uri_resolution_step.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/uri_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/uri_resolver_handler.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/wasm_package.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/wrap_package.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/types/wrapper.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/uri_resolution/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/utils/get_env_from_uri_history.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/utils/init_wrapper.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/utils/maybe_async.pyi create mode 100644 packages/polywrap-client/typings/polywrap_manifest/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_manifest/deserialize.pyi create mode 100644 packages/polywrap-client/typings/polywrap_manifest/manifest.pyi create mode 100644 packages/polywrap-client/typings/polywrap_manifest/wrap_0_1.pyi create mode 100644 packages/polywrap-client/typings/polywrap_msgpack/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_result/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/abc/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/abc/resolver_with_history.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/abc/uri_resolver_aggregator.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/cache/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/cache/cache_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache_interface.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/errors/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/errors/infinite_loop_error.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/get_uri_resolution_path.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/base_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/fs_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/redirect_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/package_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/recursive_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/redirect_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/static_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/types/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/types/static_resolver_like.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_package.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_redirect.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_resolver_like.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_wrapper.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/uri_resolver_aggregator.pyi create mode 100644 packages/polywrap-client/typings/polywrap_uri_resolvers/wrapper_resolver.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/buffer.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/constants.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/errors.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/exports.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/imports.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/inmemory_file_reader.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/types/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/types/state.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/wasm_package.pyi create mode 100644 packages/polywrap-client/typings/polywrap_wasm/wasm_wrapper.pyi create mode 100644 packages/polywrap-core/typings/polywrap_manifest/__init__.pyi create mode 100644 packages/polywrap-core/typings/polywrap_manifest/deserialize.pyi create mode 100644 packages/polywrap-core/typings/polywrap_manifest/manifest.pyi create mode 100644 packages/polywrap-core/typings/polywrap_manifest/wrap_0_1.pyi create mode 100644 packages/polywrap-core/typings/polywrap_result/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/client.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/env.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/file_reader.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_context.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_step.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver_handler.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/wrap_package.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/utils/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/utils/get_env_from_uri_history.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/utils/init_wrapper.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/utils/instance_of.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/utils/maybe_async.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_manifest/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_manifest/deserialize.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_manifest/manifest.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_manifest/wrap_0_1.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_msgpack/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_result/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/client.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/env.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/file_reader.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/invoke.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_package_wrapper.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_context.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_step.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver_handler.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/wasm_package.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrap_package.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrapper.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/utils/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/utils/get_env_from_uri_history.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/utils/init_wrapper.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/utils/instance_of.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/utils/maybe_async.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_manifest/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_manifest/deserialize.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_manifest/manifest.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_manifest/wrap_0_1.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_result/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/buffer.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/constants.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/errors.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/exports.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/imports.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/inmemory_file_reader.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/state.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_package.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_wrapper.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/client.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/env.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/file_reader.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/invoke.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/uri.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/uri_package_wrapper.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_context.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_step.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver_handler.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/wasm_package.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/wrap_package.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/types/wrapper.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/uri_resolution/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/utils/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/utils/get_env_from_uri_history.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/utils/init_wrapper.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/utils/instance_of.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/utils/maybe_async.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_manifest/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_manifest/deserialize.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_manifest/manifest.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_manifest/wrap_0_1.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_msgpack/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_result/__init__.pyi diff --git a/packages/polywrap-client/tests/test_client.py b/packages/polywrap-client/tests/test_client.py index 33900114..41b9663e 100644 --- a/packages/polywrap-client/tests/test_client.py +++ b/packages/polywrap-client/tests/test_client.py @@ -1,12 +1,11 @@ import pytest from pathlib import Path -import pytest from polywrap_client import PolywrapClient, PolywrapClientConfig from polywrap_manifest import deserialize_wrap_manifest -from polywrap_core import Uri, InvokerOptions +from polywrap_core import Uri, InvokerOptions, IFileReader from polywrap_uri_resolvers import BaseUriResolver, SimpleFileReader, StaticResolver from polywrap_result import Result, Ok, Err -from polywrap_wasm import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH, IFileReader, WasmWrapper +from polywrap_wasm import WRAP_MANIFEST_PATH, WRAP_MODULE_PATH, WasmWrapper @pytest.fixture def simple_wrap_module(): diff --git a/packages/polywrap-client/typings/polywrap_core/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/__init__.pyi new file mode 100644 index 00000000..0f0cde3d --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from .types import * +from .uri_resolution import * +from .utils import * + diff --git a/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi new file mode 100644 index 00000000..30e5f011 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi @@ -0,0 +1,18 @@ +""" +This type stub file was generated by pyright. +""" + +from .client import * +from .file_reader import * +from .invoke import * +from .env import * +from .uri import * +from .uri_package_wrapper import * +from .uri_resolution_context import * +from .uri_resolution_step import * +from .uri_resolver import * +from .uri_resolver_handler import * +from .wasm_package import * +from .wrap_package import * +from .wrapper import * + diff --git a/packages/polywrap-client/typings/polywrap_core/types/client.pyi b/packages/polywrap-client/typings/polywrap_core/types/client.pyi new file mode 100644 index 00000000..d1a2ab03 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/client.pyi @@ -0,0 +1,60 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from dataclasses import dataclass +from typing import Dict, List, Optional, Union +from polywrap_manifest import AnyWrapManifest, DeserializeManifestOptions +from polywrap_result import Result +from .env import Env +from .invoke import Invoker +from .uri import Uri +from .uri_resolver import IUriResolver +from .uri_resolver_handler import UriResolverHandler + +@dataclass(slots=True, kw_only=True) +class ClientConfig: + envs: Dict[Uri, Env] = ... + interfaces: Dict[Uri, List[Uri]] = ... + resolver: IUriResolver + + +@dataclass(slots=True, kw_only=True) +class GetFileOptions: + path: str + encoding: Optional[str] = ... + + +@dataclass(slots=True, kw_only=True) +class GetManifestOptions(DeserializeManifestOptions): + ... + + +class Client(Invoker, UriResolverHandler): + @abstractmethod + def get_interfaces(self) -> Dict[Uri, List[Uri]]: + ... + + @abstractmethod + def get_envs(self) -> Dict[Uri, Env]: + ... + + @abstractmethod + def get_env_by_uri(self, uri: Uri) -> Union[Env, None]: + ... + + @abstractmethod + def get_uri_resolver(self) -> IUriResolver: + ... + + @abstractmethod + async def get_file(self, uri: Uri, options: GetFileOptions) -> Result[Union[bytes, str]]: + ... + + @abstractmethod + async def get_manifest(self, uri: Uri, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/env.pyi b/packages/polywrap-client/typings/polywrap_core/types/env.pyi new file mode 100644 index 00000000..2d02a65d --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/env.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict + +Env = Dict[str, Any] diff --git a/packages/polywrap-client/typings/polywrap_core/types/file_reader.pyi b/packages/polywrap-client/typings/polywrap_core/types/file_reader.pyi new file mode 100644 index 00000000..946a80dc --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/file_reader.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result + +class IFileReader(ABC): + @abstractmethod + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/invoke.pyi b/packages/polywrap-client/typings/polywrap_core/types/invoke.pyi new file mode 100644 index 00000000..59c615a5 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/invoke.pyi @@ -0,0 +1,67 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Any, Dict, List, Optional, Union +from polywrap_result import Result +from .env import Env +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext + +@dataclass(slots=True, kw_only=True) +class InvokeOptions: + """ + Options required for a wrapper invocation. + + Args: + uri: Uri of the wrapper + method: Method to be executed + args: Arguments for the method, structured as a dictionary + config: Override the client's config for all invokes within this invoke. + context_id: Invoke id used to track query context data set internally. + """ + uri: Uri + method: str + args: Optional[Union[Dict[str, Any], bytes]] = ... + env: Optional[Env] = ... + resolution_context: Optional[IUriResolutionContext] = ... + + +@dataclass(slots=True, kw_only=True) +class InvocableResult: + """ + Result of a wrapper invocation + + Args: + data: Invoke result data. The type of this value is the return type of the method. + encoded: It will be set true if result is encoded + """ + result: Optional[Any] = ... + encoded: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class InvokerOptions(InvokeOptions): + encode_result: Optional[bool] = ... + + +class Invoker(ABC): + @abstractmethod + async def invoke(self, options: InvokerOptions) -> Result[Any]: + ... + + @abstractmethod + def get_implementations(self, uri: Uri) -> Result[Union[List[Uri], None]]: + ... + + + +class Invocable(ABC): + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/uri.pyi b/packages/polywrap-client/typings/polywrap_core/types/uri.pyi new file mode 100644 index 00000000..5371344c --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/uri.pyi @@ -0,0 +1,81 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from functools import total_ordering +from typing import Any, Optional, Tuple, Union + +@dataclass(slots=True, kw_only=True) +class UriConfig: + """URI configuration.""" + authority: str + path: str + uri: str + ... + + +@total_ordering +class Uri: + """ + A Polywrap URI. + + Some examples of valid URIs are: + wrap://ipfs/QmHASH + wrap://ens/sub.dimain.eth + wrap://fs/directory/file.txt + wrap://uns/domain.crypto + Breaking down the various parts of the URI, as it applies + to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): + **wrap://** - URI Scheme: differentiates Polywrap URIs. + **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. + **sub.domain.eth** - URI Path: tells the Authority where the API resides. + """ + def __init__(self, uri: str) -> None: + ... + + def __str__(self) -> str: + ... + + def __repr__(self) -> str: + ... + + def __hash__(self) -> int: + ... + + def __eq__(self, b: object) -> bool: + ... + + def __lt__(self, b: Uri) -> bool: + ... + + @property + def authority(self) -> str: + ... + + @property + def path(self) -> str: + ... + + @property + def uri(self) -> str: + ... + + @staticmethod + def equals(a: Uri, b: Uri) -> bool: + ... + + @staticmethod + def is_uri(value: Any) -> bool: + ... + + @staticmethod + def is_valid_uri(uri: str, parsed: Optional[UriConfig] = ...) -> Tuple[Union[UriConfig, None], bool]: + ... + + @staticmethod + def parse_uri(uri: str) -> UriConfig: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/uri_package_wrapper.pyi b/packages/polywrap-client/typings/polywrap_core/types/uri_package_wrapper.pyi new file mode 100644 index 00000000..619b7e14 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/uri_package_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Union +from .uri import Uri +from .wrap_package import IWrapPackage +from .wrapper import Wrapper + +UriPackageOrWrapper = Union[Uri, Wrapper, IWrapPackage] diff --git a/packages/polywrap-client/typings/polywrap_core/types/uri_resolution_context.pyi b/packages/polywrap-client/typings/polywrap_core/types/uri_resolution_context.pyi new file mode 100644 index 00000000..90cb7ff4 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/uri_resolution_context.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import List +from .uri import Uri +from .uri_resolution_step import IUriResolutionStep + +class IUriResolutionContext(ABC): + @abstractmethod + def is_resolving(self, uri: Uri) -> bool: + ... + + @abstractmethod + def start_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def stop_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def track_step(self, step: IUriResolutionStep) -> None: + ... + + @abstractmethod + def get_history(self) -> List[IUriResolutionStep]: + ... + + @abstractmethod + def get_resolution_path(self) -> List[Uri]: + ... + + @abstractmethod + def create_sub_history_context(self) -> IUriResolutionContext: + ... + + @abstractmethod + def create_sub_context(self) -> IUriResolutionContext: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/uri_resolution_step.pyi b/packages/polywrap-client/typings/polywrap_core/types/uri_resolution_step.pyi new file mode 100644 index 00000000..226d83f9 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/uri_resolution_step.pyi @@ -0,0 +1,20 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from typing import List, Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class IUriResolutionStep: + source_uri: Uri + result: Result[UriPackageOrWrapper] + description: Optional[str] = ... + sub_history: Optional[List[IUriResolutionStep]] = ... + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/uri_resolver.pyi b/packages/polywrap-client/typings/polywrap_core/types/uri_resolver.pyi new file mode 100644 index 00000000..3cc60242 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/uri_resolver.pyi @@ -0,0 +1,35 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext +from .client import Client +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class TryResolveUriOptions: + """ + Args: + no_cache_read: If set to true, the resolveUri function will not use the cache to resolve the uri. + no_cache_write: If set to true, the resolveUri function will not cache the results + config: Override the client's config for all resolutions. + context_id: Id used to track context data set internally. + """ + uri: Uri + resolution_context: Optional[IUriResolutionContext] = ... + + +class IUriResolver(ABC): + @abstractmethod + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/uri_resolver_handler.pyi b/packages/polywrap-client/typings/polywrap_core/types/uri_resolver_handler.pyi new file mode 100644 index 00000000..3ec6cea2 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/uri_resolver_handler.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING +from polywrap_result import Result +from .uri_resolver import TryResolveUriOptions +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +class UriResolverHandler(ABC): + @abstractmethod + async def try_resolve_uri(self, options: TryResolveUriOptions) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/wasm_package.pyi b/packages/polywrap-client/typings/polywrap_core/types/wasm_package.pyi new file mode 100644 index 00000000..4de7f1f7 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/wasm_package.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result +from .wrap_package import IWrapPackage + +class IWasmPackage(IWrapPackage, ABC): + @abstractmethod + async def get_wasm_module(self) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/wrap_package.pyi b/packages/polywrap-client/typings/polywrap_core/types/wrap_package.pyi new file mode 100644 index 00000000..72015a06 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/wrap_package.pyi @@ -0,0 +1,22 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import Optional +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetManifestOptions +from .wrapper import Wrapper + +class IWrapPackage(ABC): + @abstractmethod + async def create_wrapper(self) -> Result[Wrapper]: + ... + + @abstractmethod + async def get_manifest(self, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/types/wrapper.pyi b/packages/polywrap-client/typings/polywrap_core/types/wrapper.pyi new file mode 100644 index 00000000..4a05539f --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/types/wrapper.pyi @@ -0,0 +1,34 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from typing import Any, Dict, Union +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetFileOptions +from .invoke import Invocable, InvokeOptions, Invoker + +class Wrapper(Invocable): + """ + Invoke the Wrapper based on the provided [[InvokeOptions]] + + Args: + options: Options for this invocation. + client: The client instance requesting this invocation. This client will be used for any sub-invokes that occur. + """ + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[Any]: + ... + + @abstractmethod + async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: + ... + + @abstractmethod + def get_manifest(self) -> Result[AnyWrapManifest]: + ... + + + +WrapperCache = Dict[str, Wrapper] diff --git a/packages/polywrap-client/typings/polywrap_core/uri_resolution/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/uri_resolution/__init__.pyi new file mode 100644 index 00000000..aacd9177 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/uri_resolution/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .uri_resolution_context import * + diff --git a/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi b/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi new file mode 100644 index 00000000..bd999afc --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi @@ -0,0 +1,41 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Set +from ..types import IUriResolutionContext, IUriResolutionStep, Uri + +class UriResolutionContext(IUriResolutionContext): + resolving_uri_set: Set[Uri] + resolution_path: List[Uri] + history: List[IUriResolutionStep] + __slots__ = ... + def __init__(self, resolving_uri_set: Optional[Set[Uri]] = ..., resolution_path: Optional[List[Uri]] = ..., history: Optional[List[IUriResolutionStep]] = ...) -> None: + ... + + def is_resolving(self, uri: Uri) -> bool: + ... + + def start_resolving(self, uri: Uri) -> None: + ... + + def stop_resolving(self, uri: Uri) -> None: + ... + + def track_step(self, step: IUriResolutionStep) -> None: + ... + + def get_history(self) -> List[IUriResolutionStep]: + ... + + def get_resolution_path(self) -> List[Uri]: + ... + + def create_sub_history_context(self) -> UriResolutionContext: + ... + + def create_sub_context(self) -> UriResolutionContext: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi new file mode 100644 index 00000000..b2a379f8 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from .get_env_from_uri_history import * +from .init_wrapper import * +from .instance_of import * +from .maybe_async import * + diff --git a/packages/polywrap-client/typings/polywrap_core/utils/get_env_from_uri_history.pyi b/packages/polywrap-client/typings/polywrap_core/utils/get_env_from_uri_history.pyi new file mode 100644 index 00000000..b75c0458 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/utils/get_env_from_uri_history.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict, List, Union +from ..types import Client, Uri + +def get_env_from_uri_history(uri_history: List[Uri], client: Client) -> Union[Dict[str, Any], None]: + ... + diff --git a/packages/polywrap-client/typings/polywrap_core/utils/init_wrapper.pyi b/packages/polywrap-client/typings/polywrap_core/utils/init_wrapper.pyi new file mode 100644 index 00000000..87c450a0 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/utils/init_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any +from ..types import Wrapper + +async def init_wrapper(packageOrWrapper: Any) -> Wrapper: + ... + diff --git a/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi b/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi new file mode 100644 index 00000000..84ac59e0 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any + +def instance_of(obj: Any, cls: Any): # -> bool: + ... + diff --git a/packages/polywrap-client/typings/polywrap_core/utils/maybe_async.pyi b/packages/polywrap-client/typings/polywrap_core/utils/maybe_async.pyi new file mode 100644 index 00000000..e6e6f0be --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/utils/maybe_async.pyi @@ -0,0 +1,12 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Awaitable, Callable, Optional, Union + +def is_coroutine(test: Optional[Union[Awaitable[Any], Any]] = ...) -> bool: + ... + +async def execute_maybe_async_function(func: Callable[..., Any], *args: Any) -> Any: + ... + diff --git a/packages/polywrap-client/typings/polywrap_manifest/__init__.pyi b/packages/polywrap-client/typings/polywrap_manifest/__init__.pyi new file mode 100644 index 00000000..fa27423a --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_manifest/__init__.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from .deserialize import * +from .manifest import * + diff --git a/packages/polywrap-client/typings/polywrap_manifest/deserialize.pyi b/packages/polywrap-client/typings/polywrap_manifest/deserialize.pyi new file mode 100644 index 00000000..5fd1f32c --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_manifest/deserialize.pyi @@ -0,0 +1,16 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_result import Result +from .manifest import * + +""" +This file was automatically generated by scripts/templates/deserialize.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/deserialize.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +def deserialize_wrap_manifest(manifest: bytes, options: Optional[DeserializeManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + diff --git a/packages/polywrap-client/typings/polywrap_manifest/manifest.pyi b/packages/polywrap-client/typings/polywrap_manifest/manifest.pyi new file mode 100644 index 00000000..b5a88605 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_manifest/manifest.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from enum import Enum +from .wrap_0_1 import Abi as WrapAbi_0_1_0_1, WrapManifest as WrapManifest_0_1 + +""" +This file was automatically generated by scripts/templates/__init__.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/__init__.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +@dataclass(slots=True, kw_only=True) +class DeserializeManifestOptions: + no_validate: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class serializeManifestOptions: + no_validate: Optional[bool] = ... + + +class WrapManifestVersions(Enum): + VERSION_0_1 = ... + def __new__(cls, value: int, *aliases: str) -> WrapManifestVersions: + ... + + + +class WrapManifestAbiVersions(Enum): + VERSION_0_1 = ... + + +class WrapAbiVersions(Enum): + VERSION_0_1 = ... + + +AnyWrapManifest = WrapManifest_0_1 +AnyWrapAbi = WrapAbi_0_1_0_1 +WrapManifest = ... +WrapAbi = WrapAbi_0_1_0_1 +latest_wrap_manifest_version = ... +latest_wrap_abi_version = ... diff --git a/packages/polywrap-client/typings/polywrap_manifest/wrap_0_1.pyi b/packages/polywrap-client/typings/polywrap_manifest/wrap_0_1.pyi new file mode 100644 index 00000000..90b68065 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_manifest/wrap_0_1.pyi @@ -0,0 +1,209 @@ +""" +This type stub file was generated by pyright. +""" + +from enum import Enum +from typing import List, Optional +from pydantic import BaseModel + +class Version(Enum): + """ + WRAP Standard Version + """ + VERSION_0_1_0 = ... + VERSION_0_1 = ... + + +class Type(Enum): + """ + Wrapper Package Type + """ + WASM = ... + INTERFACE = ... + PLUGIN = ... + + +class Env(BaseModel): + required: Optional[bool] = ... + + +class GetImplementations(BaseModel): + enabled: bool + ... + + +class CapabilityDefinition(BaseModel): + get_implementations: Optional[GetImplementations] = ... + + +class ImportedDefinition(BaseModel): + uri: str + namespace: str + native_type: str = ... + + +class WithKind(BaseModel): + kind: float + ... + + +class WithComment(BaseModel): + comment: Optional[str] = ... + + +class GenericDefinition(WithKind): + type: str + name: Optional[str] = ... + required: Optional[bool] = ... + + +class ScalarType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + BOOLEAN = ... + BYTES = ... + BIG_INT = ... + BIG_NUMBER = ... + JSON = ... + + +class ScalarDefinition(GenericDefinition): + type: ScalarType + ... + + +class MapKeyType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + + +class ObjectRef(GenericDefinition): + ... + + +class EnumRef(GenericDefinition): + ... + + +class UnresolvedObjectOrEnumRef(GenericDefinition): + ... + + +class ImportedModuleRef(BaseModel): + type: Optional[str] = ... + + +class InterfaceImplementedDefinition(GenericDefinition): + ... + + +class EnumDefinition(GenericDefinition, WithComment): + constants: Optional[List[str]] = ... + + +class InterfaceDefinition(GenericDefinition, ImportedDefinition): + capabilities: Optional[CapabilityDefinition] = ... + + +class ImportedEnumDefinition(EnumDefinition, ImportedDefinition): + ... + + +class WrapManifest(BaseModel): + class Config: + extra = ... + + + version: Version = ... + type: Type = ... + name: str = ... + abi: Abi = ... + + +class Abi(BaseModel): + version: Optional[str] = ... + object_types: Optional[List[ObjectDefinition]] = ... + module_type: Optional[ModuleDefinition] = ... + enum_types: Optional[List[EnumDefinition]] = ... + interface_types: Optional[List[InterfaceDefinition]] = ... + imported_object_types: Optional[List[ImportedObjectDefinition]] = ... + imported_module_types: Optional[List[ImportedModuleDefinition]] = ... + imported_enum_types: Optional[List[ImportedEnumDefinition]] = ... + imported_env_types: Optional[List[ImportedEnvDefinition]] = ... + env_type: Optional[EnvDefinition] = ... + + +class ObjectDefinition(GenericDefinition, WithComment): + properties: Optional[List[PropertyDefinition]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class ModuleDefinition(GenericDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + imports: Optional[List[ImportedModuleRef]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class MethodDefinition(GenericDefinition, WithComment): + arguments: Optional[List[PropertyDefinition]] = ... + env: Optional[Env] = ... + return_: Optional[PropertyDefinition] = ... + + +class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + is_interface: Optional[bool] = ... + + +class AnyDefinition(GenericDefinition): + array: Optional[ArrayDefinition] = ... + scalar: Optional[ScalarDefinition] = ... + map: Optional[MapDefinition] = ... + object: Optional[ObjectRef] = ... + enum: Optional[EnumRef] = ... + unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = ... + + +class EnvDefinition(ObjectDefinition): + ... + + +class ImportedObjectDefinition(ObjectDefinition, ImportedDefinition, WithComment): + ... + + +class PropertyDefinition(WithComment, AnyDefinition): + ... + + +class ArrayDefinition(AnyDefinition): + item: Optional[GenericDefinition] = ... + + +class MapKeyDefinition(AnyDefinition): + type: Optional[MapKeyType] = ... + + +class MapDefinition(AnyDefinition, WithComment): + key: Optional[MapKeyDefinition] = ... + value: Optional[GenericDefinition] = ... + + +class ImportedEnvDefinition(ImportedObjectDefinition): + ... + + diff --git a/packages/polywrap-client/typings/polywrap_msgpack/__init__.pyi b/packages/polywrap-client/typings/polywrap_msgpack/__init__.pyi new file mode 100644 index 00000000..205bd701 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_msgpack/__init__.pyi @@ -0,0 +1,74 @@ +""" +This type stub file was generated by pyright. +""" + +import msgpack +from enum import Enum +from typing import Any, Dict, List, Set +from msgpack.exceptions import UnpackValueError + +""" +polywrap-msgpack adds ability to encode/decode to/from msgpack format. + +It provides msgpack_encode and msgpack_decode functions +which allows user to encode and decode to/from msgpack bytes + +It also defines the default Extension types and extension hook for +custom extension types defined by wrap standard +""" +class ExtensionTypes(Enum): + """Wrap msgpack extension types.""" + GENERIC_MAP = ... + + +def ext_hook(code: int, data: bytes) -> Any: + """Extension hook for extending the msgpack supported types. + + Args: + code (int): extension type code (>0 & <256) + data (bytes): msgpack deserializable data as payload + + Raises: + UnpackValueError: when given invalid extension type code + + Returns: + Any: decoded object + """ + ... + +def sanitize(value: Any) -> Any: + """Sanitizes the value into msgpack encoder compatible format. + + Args: + value: any valid python value + + Raises: + ValueError: when dict key isn't string + + Returns: + Any: msgpack compatible sanitized value + """ + ... + +def msgpack_encode(value: Any) -> bytes: + """Encode any python object into msgpack bytes. + + Args: + value: any valid python object + + Returns: + bytes: encoded msgpack value + """ + ... + +def msgpack_decode(val: bytes) -> Any: + """Decode msgpack bytes into a valid python object. + + Args: + val: msgpack encoded bytes + + Returns: + Any: python object + """ + ... + diff --git a/packages/polywrap-client/typings/polywrap_result/__init__.pyi b/packages/polywrap-client/typings/polywrap_result/__init__.pyi new file mode 100644 index 00000000..d704a49f --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_result/__init__.pyi @@ -0,0 +1,322 @@ +""" +This type stub file was generated by pyright. +""" + +import inspect +import sys +import types +from __future__ import annotations +from typing import Any, Callable, Generic, NoReturn, ParamSpec, TypeVar, Union, cast, overload +from typing_extensions import ParamSpec + +""" +A simple Rust like Result type for Python 3. + +This project has been forked from the https://github.com/rustedpy/result. +""" +if sys.version_info[: 2] >= (3, 10): + ... +else: + ... +T = TypeVar("T", covariant=True) +U = TypeVar("U") +F = TypeVar("F") +P = ... +R = TypeVar("R") +TBE = TypeVar("TBE", bound=BaseException) +class Ok(Generic[T]): + """ + A value that indicates success and which stores arbitrary data for the return value. + """ + _value: T + __match_args__ = ... + __slots__ = ... + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, value: T) -> None: + ... + + def __init__(self, value: Any = ...) -> None: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> T: + """ + Return the value. + """ + ... + + def err(self) -> None: + """ + Return `None`. + """ + ... + + @property + def value(self) -> T: + """ + Return the inner value. + """ + ... + + def expect(self, _message: str) -> T: + """ + Return the value. + """ + ... + + def expect_err(self, message: str) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap(self) -> T: + """ + Return the value. + """ + ... + + def unwrap_err(self) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap_or(self, _default: U) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_raise(self) -> T: + """ + Return the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + The contained result is `Ok`, so return `Ok` with original value mapped to + a new value using the passed in function. + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return the original value mapped to a new + value using the passed in function. + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return original value mapped to + a new value using the passed in `op` function. + """ + ... + + def map_err(self, op: Callable[[Exception], F]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Ok`, so return the result of `op` with the + original value passed in + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + + +class Err: + """ + A value that signifies failure and which stores arbitrary data for the error. + """ + __match_args__ = ... + __slots__ = ... + def __init__(self, value: Exception) -> None: + ... + + @classmethod + def from_str(cls, value: str) -> Err: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> None: + """ + Return `None`. + """ + ... + + def err(self) -> Exception: + """ + Return the error. + """ + ... + + @property + def value(self) -> Exception: + """ + Return the inner value. + """ + ... + + def expect(self, message: str) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def expect_err(self, _message: str) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap(self) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def unwrap_err(self) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap_or(self, default: U) -> U: + """ + Return `default`. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + The contained result is ``Err``, so return the result of applying + ``op`` to the error value. + """ + ... + + def unwrap_or_raise(self) -> NoReturn: + """ + The contained result is ``Err``, so raise the exception with the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + Return `Err` with the same value + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + Return the default value + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + Return the result of the default operation + """ + ... + + def map_err(self, op: Callable[[Exception], Exception]) -> Result[T]: + """ + The contained result is `Err`, so return `Err` with original error mapped to + a new value using the passed in function. + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Err`, so return `Err` with the original value + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Err`, so return the result of `op` with the + original value passed in + """ + ... + + + +Result = Union[Ok[T], Err] +class UnwrapError(Exception): + """ + Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + + The original ``Result`` can be accessed via the ``.result`` attribute, but + this is not intended for regular use, as type information is lost: + ``UnwrapError`` doesn't know about both ``T`` and ``E``, since it's raised + from ``Ok()`` or ``Err()`` which only knows about either ``T`` or ``E``, + not both. + """ + _result: Result[Any] + def __init__(self, result: Result[Any], message: str) -> None: + ... + + @property + def result(self) -> Result[Any]: + """ + Returns the original result. + """ + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/__init__.pyi new file mode 100644 index 00000000..c7c96766 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/__init__.pyi @@ -0,0 +1,16 @@ +""" +This type stub file was generated by pyright. +""" + +from .types import * +from .abc import * +from .errors import * +from .helpers import * +from .legacy import * +from .cache import * +from .recursive_resolver import * +from .static_resolver import * +from .redirect_resolver import * +from .package_resolver import * +from .wrapper_resolver import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/__init__.pyi new file mode 100644 index 00000000..ad874c88 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from ..cache.wrapper_cache import * +from .resolver_with_history import * +from .uri_resolver_aggregator import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/resolver_with_history.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/resolver_with_history.pyi new file mode 100644 index 00000000..cdbf5a8d --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/resolver_with_history.pyi @@ -0,0 +1,17 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri + +class IResolverWithHistory(IUriResolver, ABC): + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext): # -> Result[UriPackageOrWrapper]: + ... + + @abstractmethod + def get_step_description(self) -> str: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/uri_resolver_aggregator.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/uri_resolver_aggregator.pyi new file mode 100644 index 00000000..a3fa29da --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/abc/uri_resolver_aggregator.pyi @@ -0,0 +1,26 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import List +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri, UriPackageOrWrapper +from polywrap_result import Result + +class IUriResolverAggregator(IUriResolver, ABC): + @abstractmethod + async def get_uri_resolvers(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[List[IUriResolver]]: + ... + + @abstractmethod + def get_step_description(self) -> str: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + async def try_resolve_uri_with_resolvers(self, uri: Uri, client: Client, resolvers: List[IUriResolver], resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/__init__.pyi new file mode 100644 index 00000000..0ef1cefd --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from .cache_resolver import * +from .wrapper_cache import * +from .wrapper_cache_interface import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/cache_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/cache_resolver.pyi new file mode 100644 index 00000000..56799192 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/cache_resolver.pyi @@ -0,0 +1,33 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Optional +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri, UriPackageOrWrapper +from polywrap_manifest import DeserializeManifestOptions +from polywrap_result import Result +from .wrapper_cache_interface import IWrapperCache + +class CacheResolverOptions: + deserialize_manifest_options: DeserializeManifestOptions + end_on_redirect: Optional[bool] + ... + + +class PackageToWrapperCacheResolver: + __slots__ = ... + name: str + resolver_to_cache: IUriResolver + cache: IWrapperCache + options: CacheResolverOptions + def __init__(self, resolver_to_cache: IUriResolver, cache: IWrapperCache, options: CacheResolverOptions) -> None: + ... + + def get_options(self) -> Any: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache.pyi new file mode 100644 index 00000000..fd7279d3 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache.pyi @@ -0,0 +1,21 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Dict, Union +from polywrap_core import Uri, Wrapper +from .wrapper_cache_interface import IWrapperCache + +class WrapperCache(IWrapperCache): + map: Dict[Uri, Wrapper] + def __init__(self) -> None: + ... + + def get(self, uri: Uri) -> Union[Wrapper, None]: + ... + + def set(self, uri: Uri, wrapper: Wrapper) -> None: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache_interface.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache_interface.pyi new file mode 100644 index 00000000..fdba2419 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/cache/wrapper_cache_interface.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import Union +from polywrap_core import Uri, Wrapper + +class IWrapperCache(ABC): + @abstractmethod + def get(self, uri: Uri) -> Union[Wrapper, None]: + ... + + @abstractmethod + def set(self, uri: Uri, wrapper: Wrapper) -> None: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/errors/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/errors/__init__.pyi new file mode 100644 index 00000000..15fea92a --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/errors/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .infinite_loop_error import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/errors/infinite_loop_error.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/errors/infinite_loop_error.pyi new file mode 100644 index 00000000..73aa1179 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/errors/infinite_loop_error.pyi @@ -0,0 +1,13 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List +from polywrap_core import IUriResolutionStep, Uri + +class InfiniteLoopError(Exception): + def __init__(self, uri: Uri, history: List[IUriResolutionStep]) -> None: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/__init__.pyi new file mode 100644 index 00000000..a630f5f4 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .resolver_like_to_resolver import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/get_uri_resolution_path.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/get_uri_resolution_path.pyi new file mode 100644 index 00000000..5a3728f2 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/get_uri_resolution_path.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List +from polywrap_core import IUriResolutionStep + +def get_uri_resolution_path(history: List[IUriResolutionStep]) -> List[IUriResolutionStep]: + ... + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.pyi new file mode 100644 index 00000000..65ae23cb --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_like_to_resolver.pyi @@ -0,0 +1,11 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_core import IUriResolver +from ..types import UriResolverLike + +def resolver_like_to_resolver(resolver_like: UriResolverLike, resolver_name: Optional[str] = ...) -> IUriResolver: + ... + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.pyi new file mode 100644 index 00000000..006bc274 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/helpers/resolver_with_loop_guard.pyi @@ -0,0 +1,4 @@ +""" +This type stub file was generated by pyright. +""" + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/__init__.pyi new file mode 100644 index 00000000..8d6b9c75 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from .base_resolver import * +from .fs_resolver import * +from .redirect_resolver import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/base_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/base_resolver.pyi new file mode 100644 index 00000000..853fc88a --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/base_resolver.pyi @@ -0,0 +1,21 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Dict +from polywrap_core import Client, IFileReader, IUriResolutionContext, IUriResolver, Uri, UriPackageOrWrapper +from polywrap_result import Result +from .fs_resolver import FsUriResolver +from .redirect_resolver import RedirectUriResolver + +class BaseUriResolver(IUriResolver): + _fs_resolver: FsUriResolver + _redirect_resolver: RedirectUriResolver + def __init__(self, file_reader: IFileReader, redirects: Dict[Uri, Uri]) -> None: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/fs_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/fs_resolver.pyi new file mode 100644 index 00000000..ec10da97 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/fs_resolver.pyi @@ -0,0 +1,23 @@ +""" +This type stub file was generated by pyright. +""" + +from polywrap_core import Client, IFileReader, IUriResolutionContext, IUriResolver, Uri, UriPackageOrWrapper +from polywrap_result import Result + +class SimpleFileReader(IFileReader): + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + +class FsUriResolver(IUriResolver): + file_reader: IFileReader + def __init__(self, file_reader: IFileReader) -> None: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/redirect_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/redirect_resolver.pyi new file mode 100644 index 00000000..36deb475 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/legacy/redirect_resolver.pyi @@ -0,0 +1,18 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Dict +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri +from polywrap_result import Result + +class RedirectUriResolver(IUriResolver): + _redirects: Dict[Uri, Uri] + def __init__(self, redirects: Dict[Uri, Uri]) -> None: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[Uri]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/package_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/package_resolver.pyi new file mode 100644 index 00000000..60dc4a68 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/package_resolver.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from polywrap_core import IWrapPackage, Uri +from .abc import IResolverWithHistory + +class PackageResolver(IResolverWithHistory): + __slots__ = ... + uri: Uri + wrap_package: IWrapPackage + def __init__(self, uri: Uri, wrap_package: IWrapPackage) -> None: + ... + + def get_step_description(self) -> str: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/recursive_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/recursive_resolver.pyi new file mode 100644 index 00000000..80e68090 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/recursive_resolver.pyi @@ -0,0 +1,18 @@ +""" +This type stub file was generated by pyright. +""" + +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri, UriPackageOrWrapper +from polywrap_result import Result + +class RecursiveResolver(IUriResolver): + __slots__ = ... + resolver: IUriResolver + def __init__(self, resolver: IUriResolver) -> None: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/redirect_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/redirect_resolver.pyi new file mode 100644 index 00000000..58f53594 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/redirect_resolver.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from polywrap_core import Uri +from .abc.resolver_with_history import IResolverWithHistory + +class RedirectResolver(IResolverWithHistory): + __slots__ = ... + from_uri: Uri + to_uri: Uri + def __init__(self, from_uri: Uri, to_uri: Uri) -> None: + ... + + def get_step_description(self) -> str: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/static_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/static_resolver.pyi new file mode 100644 index 00000000..f684e8bc --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/static_resolver.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri, UriPackageOrWrapper +from polywrap_result import Result +from .types import StaticResolverLike + +class StaticResolver(IUriResolver): + __slots__ = ... + uri_map: StaticResolverLike + def __init__(self, uri_map: StaticResolverLike) -> None: + ... + + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/types/__init__.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/__init__.pyi new file mode 100644 index 00000000..56634112 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/__init__.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from .static_resolver_like import * +from .uri_package import * +from .uri_redirect import * +from .uri_resolver_like import * +from .uri_wrapper import * + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/types/static_resolver_like.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/static_resolver_like.pyi new file mode 100644 index 00000000..4930107f --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/static_resolver_like.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Dict +from polywrap_core import Uri, UriPackageOrWrapper + +StaticResolverLike = Dict[Uri, UriPackageOrWrapper] diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_package.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_package.pyi new file mode 100644 index 00000000..478c9d16 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_package.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from polywrap_core import IWrapPackage, Uri + +@dataclass(slots=True, kw_only=True) +class UriPackage: + uri: Uri + package: IWrapPackage + ... + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_redirect.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_redirect.pyi new file mode 100644 index 00000000..6fbe6588 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_redirect.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from polywrap_core import Uri + +@dataclass(slots=True, kw_only=True) +class UriRedirect: + from_uri: Uri + to_uri: Uri + ... + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_resolver_like.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_resolver_like.pyi new file mode 100644 index 00000000..2db10fa5 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_resolver_like.pyi @@ -0,0 +1,12 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Union +from polywrap_core import IUriResolver +from .static_resolver_like import StaticResolverLike +from .uri_package import UriPackage +from .uri_redirect import UriRedirect +from .uri_wrapper import UriWrapper + +UriResolverLike = Union[StaticResolverLike, UriRedirect, UriPackage, UriWrapper, IUriResolver, List["UriResolverLike"],] diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_wrapper.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_wrapper.pyi new file mode 100644 index 00000000..0f4d03d2 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/types/uri_wrapper.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from polywrap_core import Uri, Wrapper + +@dataclass(slots=True, kw_only=True) +class UriWrapper: + uri: Uri + wrapper: Wrapper + ... + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/uri_resolver_aggregator.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/uri_resolver_aggregator.pyi new file mode 100644 index 00000000..c410a4f6 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/uri_resolver_aggregator.pyi @@ -0,0 +1,24 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional +from polywrap_core import Client, IUriResolutionContext, IUriResolver, Uri +from polywrap_result import Result +from .abc.uri_resolver_aggregator import IUriResolverAggregator + +class UriResolverAggregator(IUriResolverAggregator): + __slots__ = ... + resolvers: List[IUriResolver] + name: Optional[str] + def __init__(self, resolvers: List[IUriResolver], name: Optional[str] = ...) -> None: + ... + + def get_step_description(self) -> str: + ... + + async def get_uri_resolvers(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[List[IUriResolver]]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_uri_resolvers/wrapper_resolver.pyi b/packages/polywrap-client/typings/polywrap_uri_resolvers/wrapper_resolver.pyi new file mode 100644 index 00000000..435d9bc2 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_uri_resolvers/wrapper_resolver.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from polywrap_core import Uri, Wrapper +from .abc.resolver_with_history import IResolverWithHistory + +class WrapperResolver(IResolverWithHistory): + __slots__ = ... + uri: Uri + wrapper: Wrapper + def __init__(self, uri: Uri, wrapper: Wrapper) -> None: + ... + + def get_step_description(self) -> str: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_wasm/__init__.pyi b/packages/polywrap-client/typings/polywrap_wasm/__init__.pyi new file mode 100644 index 00000000..a0e3eff3 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/__init__.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from .buffer import * +from .constants import * +from .errors import * +from .exports import * +from .imports import * +from .inmemory_file_reader import * +from .types import * +from .wasm_package import * +from .wasm_wrapper import * + diff --git a/packages/polywrap-client/typings/polywrap_wasm/buffer.pyi b/packages/polywrap-client/typings/polywrap_wasm/buffer.pyi new file mode 100644 index 00000000..38a89b58 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/buffer.pyi @@ -0,0 +1,22 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional + +BufferPointer = ... +def read_bytes(memory_pointer: BufferPointer, memory_length: int, offset: Optional[int] = ..., length: Optional[int] = ...) -> bytearray: + ... + +def read_string(memory_pointer: BufferPointer, memory_length: int, offset: int, length: int) -> str: + ... + +def write_string(memory_pointer: BufferPointer, memory_length: int, value: str, value_offset: int) -> None: + ... + +def write_bytes(memory_pointer: BufferPointer, memory_length: int, value: bytes, value_offset: int) -> None: + ... + +def mem_cpy(memory_pointer: BufferPointer, memory_length: int, value: bytearray, value_length: int, value_offset: int) -> None: + ... + diff --git a/packages/polywrap-client/typings/polywrap_wasm/constants.pyi b/packages/polywrap-client/typings/polywrap_wasm/constants.pyi new file mode 100644 index 00000000..1270a60f --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/constants.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +WRAP_MANIFEST_PATH: str +WRAP_MODULE_PATH: str diff --git a/packages/polywrap-client/typings/polywrap_wasm/errors.pyi b/packages/polywrap-client/typings/polywrap_wasm/errors.pyi new file mode 100644 index 00000000..6c852f15 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/errors.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +class WasmAbortError(RuntimeError): + def __init__(self, message: str) -> None: + ... + + + +class ExportNotFoundError(Exception): + """raises when an export isn't found in the wasm module""" + ... + + diff --git a/packages/polywrap-client/typings/polywrap_wasm/exports.pyi b/packages/polywrap-client/typings/polywrap_wasm/exports.pyi new file mode 100644 index 00000000..47bda1c4 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/exports.pyi @@ -0,0 +1,18 @@ +""" +This type stub file was generated by pyright. +""" + +from wasmtime import Func, Instance, Store + +class WrapExports: + _instance: Instance + _store: Store + _wrap_invoke: Func + def __init__(self, instance: Instance, store: Store) -> None: + ... + + def __wrap_invoke__(self, method_length: int, args_length: int, env_length: int) -> bool: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_wasm/imports.pyi b/packages/polywrap-client/typings/polywrap_wasm/imports.pyi new file mode 100644 index 00000000..2c1f58bc --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/imports.pyi @@ -0,0 +1,21 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any +from polywrap_core import Invoker, InvokerOptions +from polywrap_result import Result +from unsync import unsync +from wasmtime import Instance, Memory, Store +from .types.state import State + +@unsync +async def unsync_invoke(invoker: Invoker, options: InvokerOptions) -> Result[Any]: + ... + +def create_memory(store: Store, module: bytes) -> Memory: + ... + +def create_instance(store: Store, module: bytes, state: State, invoker: Invoker) -> Instance: + ... + diff --git a/packages/polywrap-client/typings/polywrap_wasm/inmemory_file_reader.pyi b/packages/polywrap-client/typings/polywrap_wasm/inmemory_file_reader.pyi new file mode 100644 index 00000000..f655b83f --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/inmemory_file_reader.pyi @@ -0,0 +1,20 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_core import IFileReader +from polywrap_result import Result + +class InMemoryFileReader(IFileReader): + _wasm_manifest: Optional[bytes] + _wasm_module: Optional[bytes] + _base_file_reader: IFileReader + def __init__(self, base_file_reader: IFileReader, wasm_module: Optional[bytes] = ..., wasm_manifest: Optional[bytes] = ...) -> None: + ... + + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_wasm/types/__init__.pyi b/packages/polywrap-client/typings/polywrap_wasm/types/__init__.pyi new file mode 100644 index 00000000..3deed82d --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/types/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .state import * + diff --git a/packages/polywrap-client/typings/polywrap_wasm/types/state.pyi b/packages/polywrap-client/typings/polywrap_wasm/types/state.pyi new file mode 100644 index 00000000..6e08aa22 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/types/state.pyi @@ -0,0 +1,38 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from typing import Any, List, Optional, TypedDict + +class RawInvokeResult(TypedDict): + result: Optional[bytes] + error: Optional[str] + ... + + +class RawSubinvokeResult(TypedDict): + result: Optional[bytes] + error: Optional[str] + args: List[Any] + ... + + +class RawSubinvokeImplementationResult(TypedDict): + result: Optional[bytes] + error: Optional[str] + args: List[Any] + ... + + +@dataclass(kw_only=True, slots=True) +class State: + invoke: RawInvokeResult = ... + subinvoke: RawSubinvokeResult = ... + subinvoke_implementation: RawSubinvokeImplementationResult = ... + get_implementations_result: Optional[bytes] = ... + method: Optional[str] = ... + args: Optional[bytes] = ... + env: Optional[bytes] = ... + + diff --git a/packages/polywrap-client/typings/polywrap_wasm/wasm_package.pyi b/packages/polywrap-client/typings/polywrap_wasm/wasm_package.pyi new file mode 100644 index 00000000..c92ab00d --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/wasm_package.pyi @@ -0,0 +1,27 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional, Union +from polywrap_core import GetManifestOptions, IFileReader, IWasmPackage, Wrapper +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result + +class WasmPackage(IWasmPackage): + file_reader: IFileReader + manifest: Optional[Union[bytes, AnyWrapManifest]] + wasm_module: Optional[bytes] + def __init__(self, file_reader: IFileReader, manifest: Optional[Union[bytes, AnyWrapManifest]] = ..., wasm_module: Optional[bytes] = ...) -> None: + ... + + async def get_manifest(self, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + async def get_wasm_module(self) -> Result[bytes]: + ... + + async def create_wrapper(self) -> Result[Wrapper]: + ... + + + diff --git a/packages/polywrap-client/typings/polywrap_wasm/wasm_wrapper.pyi b/packages/polywrap-client/typings/polywrap_wasm/wasm_wrapper.pyi new file mode 100644 index 00000000..d5249391 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_wasm/wasm_wrapper.pyi @@ -0,0 +1,35 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Union +from polywrap_core import GetFileOptions, IFileReader, InvocableResult, InvokeOptions, Invoker, Wrapper +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from wasmtime import Store +from .types.state import State + +class WasmWrapper(Wrapper): + file_reader: IFileReader + wasm_module: bytes + manifest: AnyWrapManifest + def __init__(self, file_reader: IFileReader, wasm_module: bytes, manifest: AnyWrapManifest) -> None: + ... + + def get_manifest(self) -> Result[AnyWrapManifest]: + ... + + def get_wasm_module(self) -> Result[bytes]: + ... + + async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: + ... + + def create_wasm_instance(self, store: Store, state: State, invoker: Invoker): # -> Instance | None: + ... + + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + + diff --git a/packages/polywrap-core/polywrap_core/types/__init__.py b/packages/polywrap-core/polywrap_core/types/__init__.py index 540038c2..3563398a 100644 --- a/packages/polywrap-core/polywrap_core/types/__init__.py +++ b/packages/polywrap-core/polywrap_core/types/__init__.py @@ -2,6 +2,7 @@ from .file_reader import * from .invoke import * from .uri import * +from .env import * from .uri_package_wrapper import * from .uri_resolution_context import * from .uri_resolution_step import * diff --git a/packages/polywrap-core/polywrap_core/types/wasm_package.py b/packages/polywrap-core/polywrap_core/types/wasm_package.py index 3961049b..3e0daf27 100644 --- a/packages/polywrap-core/polywrap_core/types/wasm_package.py +++ b/packages/polywrap-core/polywrap_core/types/wasm_package.py @@ -7,5 +7,5 @@ class IWasmPackage(IWrapPackage, ABC): @abstractmethod - async def get_wasm_module() -> Result[bytes]: + async def get_wasm_module(self) -> Result[bytes]: pass diff --git a/packages/polywrap-core/polywrap_core/types/wrapper.py b/packages/polywrap-core/polywrap_core/types/wrapper.py index eb06e566..ae29a5f6 100644 --- a/packages/polywrap-core/polywrap_core/types/wrapper.py +++ b/packages/polywrap-core/polywrap_core/types/wrapper.py @@ -1,11 +1,11 @@ from abc import abstractmethod -from typing import Dict, Union +from typing import Any, Dict, Union from polywrap_manifest import AnyWrapManifest from polywrap_result import Result from .client import GetFileOptions -from .invoke import Invocable, InvocableResult, InvokeOptions, Invoker +from .invoke import Invocable, InvokeOptions, Invoker class Wrapper(Invocable): @@ -20,7 +20,7 @@ class Wrapper(Invocable): @abstractmethod async def invoke( self, options: InvokeOptions, invoker: Invoker - ) -> Result[InvocableResult]: + ) -> Result[Any]: pass @abstractmethod diff --git a/packages/polywrap-core/typings/polywrap_manifest/__init__.pyi b/packages/polywrap-core/typings/polywrap_manifest/__init__.pyi new file mode 100644 index 00000000..fa27423a --- /dev/null +++ b/packages/polywrap-core/typings/polywrap_manifest/__init__.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from .deserialize import * +from .manifest import * + diff --git a/packages/polywrap-core/typings/polywrap_manifest/deserialize.pyi b/packages/polywrap-core/typings/polywrap_manifest/deserialize.pyi new file mode 100644 index 00000000..5fd1f32c --- /dev/null +++ b/packages/polywrap-core/typings/polywrap_manifest/deserialize.pyi @@ -0,0 +1,16 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_result import Result +from .manifest import * + +""" +This file was automatically generated by scripts/templates/deserialize.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/deserialize.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +def deserialize_wrap_manifest(manifest: bytes, options: Optional[DeserializeManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + diff --git a/packages/polywrap-core/typings/polywrap_manifest/manifest.pyi b/packages/polywrap-core/typings/polywrap_manifest/manifest.pyi new file mode 100644 index 00000000..96e8d343 --- /dev/null +++ b/packages/polywrap-core/typings/polywrap_manifest/manifest.pyi @@ -0,0 +1,45 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from enum import Enum +from typing import Optional +from .wrap_0_1 import Abi as WrapAbi_0_1_0_1, WrapManifest as WrapManifest_0_1 + +""" +This file was automatically generated by scripts/templates/__init__.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/__init__.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +@dataclass(slots=True, kw_only=True) +class DeserializeManifestOptions: + no_validate: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class serializeManifestOptions: + no_validate: Optional[bool] = ... + + +class WrapManifestVersions(Enum): + VERSION_0_1 = ... + def __new__(cls, value: int, *aliases: str) -> WrapManifestVersions: + ... + + + +class WrapManifestAbiVersions(Enum): + VERSION_0_1 = ... + + +class WrapAbiVersions(Enum): + VERSION_0_1 = ... + + +AnyWrapManifest = WrapManifest_0_1 +AnyWrapAbi = WrapAbi_0_1_0_1 +WrapManifest = WrapManifest_0_1 +WrapAbi = WrapAbi_0_1_0_1 +latest_wrap_manifest_version: str +latest_wrap_abi_version: str diff --git a/packages/polywrap-core/typings/polywrap_manifest/wrap_0_1.pyi b/packages/polywrap-core/typings/polywrap_manifest/wrap_0_1.pyi new file mode 100644 index 00000000..ed652916 --- /dev/null +++ b/packages/polywrap-core/typings/polywrap_manifest/wrap_0_1.pyi @@ -0,0 +1,209 @@ +""" +This type stub file was generated by pyright. +""" + +from enum import Enum +from typing import Any, List, Optional +from pydantic import BaseModel + +class Version(Enum): + """ + WRAP Standard Version + """ + VERSION_0_1_0 = ... + VERSION_0_1 = ... + + +class Type(Enum): + """ + Wrapper Package Type + """ + WASM = ... + INTERFACE = ... + PLUGIN = ... + + +class Env(BaseModel): + required: Optional[bool] = ... + + +class GetImplementations(BaseModel): + enabled: bool + ... + + +class CapabilityDefinition(BaseModel): + get_implementations: Optional[GetImplementations] = ... + + +class ImportedDefinition(BaseModel): + uri: str + namespace: str + native_type: str = ... + + +class WithKind(BaseModel): + kind: float + ... + + +class WithComment(BaseModel): + comment: Optional[str] = ... + + +class GenericDefinition(WithKind): + type: str + name: Optional[str] = ... + required: Optional[bool] = ... + + +class ScalarType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + BOOLEAN = ... + BYTES = ... + BIG_INT = ... + BIG_NUMBER = ... + JSON = ... + + +class ScalarDefinition(GenericDefinition): + type: ScalarType + ... + + +class MapKeyType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + + +class ObjectRef(GenericDefinition): + ... + + +class EnumRef(GenericDefinition): + ... + + +class UnresolvedObjectOrEnumRef(GenericDefinition): + ... + + +class ImportedModuleRef(BaseModel): + type: Optional[str] = ... + + +class InterfaceImplementedDefinition(GenericDefinition): + ... + + +class EnumDefinition(GenericDefinition, WithComment): + constants: Optional[List[str]] = ... + + +class InterfaceDefinition(GenericDefinition, ImportedDefinition): + capabilities: Optional[CapabilityDefinition] = ... + + +class ImportedEnumDefinition(EnumDefinition, ImportedDefinition): + ... + + +class WrapManifest(BaseModel): + class Config: + extra = Any + + + version: Version = ... + type: Type = ... + name: str = ... + abi: Abi = ... + + +class Abi(BaseModel): + version: Optional[str] = ... + object_types: Optional[List[ObjectDefinition]] = ... + module_type: Optional[ModuleDefinition] = ... + enum_types: Optional[List[EnumDefinition]] = ... + interface_types: Optional[List[InterfaceDefinition]] = ... + imported_object_types: Optional[List[ImportedObjectDefinition]] = ... + imported_module_types: Optional[List[ImportedModuleDefinition]] = ... + imported_enum_types: Optional[List[ImportedEnumDefinition]] = ... + imported_env_types: Optional[List[ImportedEnvDefinition]] = ... + env_type: Optional[EnvDefinition] = ... + + +class ObjectDefinition(GenericDefinition, WithComment): + properties: Optional[List[PropertyDefinition]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class ModuleDefinition(GenericDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + imports: Optional[List[ImportedModuleRef]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class MethodDefinition(GenericDefinition, WithComment): + arguments: Optional[List[PropertyDefinition]] = ... + env: Optional[Env] = ... + return_: Optional[PropertyDefinition] = ... + + +class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + is_interface: Optional[bool] = ... + + +class AnyDefinition(GenericDefinition): + array: Optional[ArrayDefinition] = ... + scalar: Optional[ScalarDefinition] = ... + map: Optional[MapDefinition] = ... + object: Optional[ObjectRef] = ... + enum: Optional[EnumRef] = ... + unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = ... + + +class EnvDefinition(ObjectDefinition): + ... + + +class ImportedObjectDefinition(ObjectDefinition, ImportedDefinition, WithComment): + ... + + +class PropertyDefinition(WithComment, AnyDefinition): + ... + + +class ArrayDefinition(AnyDefinition): + item: Optional[GenericDefinition] = ... + + +class MapKeyDefinition(AnyDefinition): + type: Optional[MapKeyType] = ... + + +class MapDefinition(AnyDefinition, WithComment): + key: Optional[MapKeyDefinition] = ... + value: Optional[GenericDefinition] = ... + + +class ImportedEnvDefinition(ImportedObjectDefinition): + ... + + diff --git a/packages/polywrap-core/typings/polywrap_result/__init__.pyi b/packages/polywrap-core/typings/polywrap_result/__init__.pyi new file mode 100644 index 00000000..d704a49f --- /dev/null +++ b/packages/polywrap-core/typings/polywrap_result/__init__.pyi @@ -0,0 +1,322 @@ +""" +This type stub file was generated by pyright. +""" + +import inspect +import sys +import types +from __future__ import annotations +from typing import Any, Callable, Generic, NoReturn, ParamSpec, TypeVar, Union, cast, overload +from typing_extensions import ParamSpec + +""" +A simple Rust like Result type for Python 3. + +This project has been forked from the https://github.com/rustedpy/result. +""" +if sys.version_info[: 2] >= (3, 10): + ... +else: + ... +T = TypeVar("T", covariant=True) +U = TypeVar("U") +F = TypeVar("F") +P = ... +R = TypeVar("R") +TBE = TypeVar("TBE", bound=BaseException) +class Ok(Generic[T]): + """ + A value that indicates success and which stores arbitrary data for the return value. + """ + _value: T + __match_args__ = ... + __slots__ = ... + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, value: T) -> None: + ... + + def __init__(self, value: Any = ...) -> None: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> T: + """ + Return the value. + """ + ... + + def err(self) -> None: + """ + Return `None`. + """ + ... + + @property + def value(self) -> T: + """ + Return the inner value. + """ + ... + + def expect(self, _message: str) -> T: + """ + Return the value. + """ + ... + + def expect_err(self, message: str) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap(self) -> T: + """ + Return the value. + """ + ... + + def unwrap_err(self) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap_or(self, _default: U) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_raise(self) -> T: + """ + Return the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + The contained result is `Ok`, so return `Ok` with original value mapped to + a new value using the passed in function. + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return the original value mapped to a new + value using the passed in function. + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return original value mapped to + a new value using the passed in `op` function. + """ + ... + + def map_err(self, op: Callable[[Exception], F]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Ok`, so return the result of `op` with the + original value passed in + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + + +class Err: + """ + A value that signifies failure and which stores arbitrary data for the error. + """ + __match_args__ = ... + __slots__ = ... + def __init__(self, value: Exception) -> None: + ... + + @classmethod + def from_str(cls, value: str) -> Err: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> None: + """ + Return `None`. + """ + ... + + def err(self) -> Exception: + """ + Return the error. + """ + ... + + @property + def value(self) -> Exception: + """ + Return the inner value. + """ + ... + + def expect(self, message: str) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def expect_err(self, _message: str) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap(self) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def unwrap_err(self) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap_or(self, default: U) -> U: + """ + Return `default`. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + The contained result is ``Err``, so return the result of applying + ``op`` to the error value. + """ + ... + + def unwrap_or_raise(self) -> NoReturn: + """ + The contained result is ``Err``, so raise the exception with the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + Return `Err` with the same value + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + Return the default value + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + Return the result of the default operation + """ + ... + + def map_err(self, op: Callable[[Exception], Exception]) -> Result[T]: + """ + The contained result is `Err`, so return `Err` with original error mapped to + a new value using the passed in function. + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Err`, so return `Err` with the original value + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Err`, so return the result of `op` with the + original value passed in + """ + ... + + + +Result = Union[Ok[T], Err] +class UnwrapError(Exception): + """ + Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + + The original ``Result`` can be accessed via the ``.result`` attribute, but + this is not intended for regular use, as type information is lost: + ``UnwrapError`` doesn't know about both ``T`` and ``E``, since it's raised + from ``Ok()`` or ``Err()`` which only knows about either ``T`` or ``E``, + not both. + """ + _result: Result[Any] + def __init__(self, result: Result[Any], message: str) -> None: + ... + + @property + def result(self) -> Result[Any]: + """ + Returns the original result. + """ + ... + + + diff --git a/packages/polywrap-plugin/polywrap_plugin/package.py b/packages/polywrap-plugin/polywrap_plugin/package.py index 321d5884..ebeb024f 100644 --- a/packages/polywrap-plugin/polywrap_plugin/package.py +++ b/packages/polywrap-plugin/polywrap_plugin/package.py @@ -1,4 +1,4 @@ -from typing import Generic, Optional, cast +from typing import Generic, Optional from polywrap_core import GetManifestOptions, IWrapPackage, Wrapper from polywrap_manifest import AnyWrapManifest diff --git a/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi new file mode 100644 index 00000000..0f0cde3d --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from .types import * +from .uri_resolution import * +from .utils import * + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi new file mode 100644 index 00000000..284e1b79 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from .client import * +from .file_reader import * +from .invoke import * +from .uri import * +from .uri_package import * +from .uri_package_wrapper import * +from .uri_resolution_context import * +from .uri_resolution_step import * +from .uri_resolver import * +from .uri_resolver_handler import * +from .uri_wrapper import * +from .wrap_package import * +from .wasm_package import * +from .wrapper import * + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi new file mode 100644 index 00000000..3e1ecf67 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi @@ -0,0 +1,60 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from dataclasses import dataclass +from typing import Dict, List, Optional, Union +from polywrap_manifest import AnyWrapManifest, DeserializeManifestOptions +from polywrap_result import Result +from .invoke import Invoker +from .uri import Uri +from .env import Env +from .uri_resolver import IUriResolver +from .uri_resolver_handler import UriResolverHandler + +@dataclass(slots=True, kw_only=True) +class ClientConfig: + envs: Dict[Uri, Env] = ... + interfaces: Dict[Uri, List[Uri]] = ... + resolver: IUriResolver + + +@dataclass(slots=True, kw_only=True) +class GetFileOptions: + path: str + encoding: Optional[str] = ... + + +@dataclass(slots=True, kw_only=True) +class GetManifestOptions(DeserializeManifestOptions): + ... + + +class Client(Invoker, UriResolverHandler): + @abstractmethod + def get_interfaces(self) -> Dict[Uri, List[Uri]]: + ... + + @abstractmethod + def get_envs(self) -> Dict[Uri, Env]: + ... + + @abstractmethod + def get_env_by_uri(self, uri: Uri) -> Union[Env, None]: + ... + + @abstractmethod + def get_uri_resolver(self) -> IUriResolver: + ... + + @abstractmethod + async def get_file(self, uri: Uri, options: GetFileOptions) -> Result[Union[bytes, str]]: + ... + + @abstractmethod + async def get_manifest(self, uri: Uri, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/env.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/env.pyi new file mode 100644 index 00000000..2d02a65d --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/env.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict + +Env = Dict[str, Any] diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/file_reader.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/file_reader.pyi new file mode 100644 index 00000000..946a80dc --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/file_reader.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result + +class IFileReader(ABC): + @abstractmethod + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi new file mode 100644 index 00000000..2a070a90 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi @@ -0,0 +1,67 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Any, Dict, List, Optional, Union +from polywrap_result import Result +from .uri import Uri +from .env import Env +from .uri_resolution_context import IUriResolutionContext + +@dataclass(slots=True, kw_only=True) +class InvokeOptions: + """ + Options required for a wrapper invocation. + + Args: + uri: Uri of the wrapper + method: Method to be executed + args: Arguments for the method, structured as a dictionary + config: Override the client's config for all invokes within this invoke. + context_id: Invoke id used to track query context data set internally. + """ + uri: Uri + method: str + args: Optional[Union[Dict[str, Any], bytes]] = ... + env: Optional[Env] = ... + resolution_context: Optional[IUriResolutionContext] = ... + + +@dataclass(slots=True, kw_only=True) +class InvocableResult: + """ + Result of a wrapper invocation + + Args: + data: Invoke result data. The type of this value is the return type of the method. + encoded: It will be set true if result is encoded + """ + result: Optional[Any] = ... + encoded: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class InvokerOptions(InvokeOptions): + encode_result: Optional[bool] = ... + + +class Invoker(ABC): + @abstractmethod + async def invoke(self, options: InvokerOptions) -> Result[Any]: + ... + + @abstractmethod + def get_implementations(self, uri: Uri) -> Result[Union[List[Uri], None]]: + ... + + + +class Invocable(ABC): + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri.pyi new file mode 100644 index 00000000..5371344c --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri.pyi @@ -0,0 +1,81 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from functools import total_ordering +from typing import Any, Optional, Tuple, Union + +@dataclass(slots=True, kw_only=True) +class UriConfig: + """URI configuration.""" + authority: str + path: str + uri: str + ... + + +@total_ordering +class Uri: + """ + A Polywrap URI. + + Some examples of valid URIs are: + wrap://ipfs/QmHASH + wrap://ens/sub.dimain.eth + wrap://fs/directory/file.txt + wrap://uns/domain.crypto + Breaking down the various parts of the URI, as it applies + to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): + **wrap://** - URI Scheme: differentiates Polywrap URIs. + **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. + **sub.domain.eth** - URI Path: tells the Authority where the API resides. + """ + def __init__(self, uri: str) -> None: + ... + + def __str__(self) -> str: + ... + + def __repr__(self) -> str: + ... + + def __hash__(self) -> int: + ... + + def __eq__(self, b: object) -> bool: + ... + + def __lt__(self, b: Uri) -> bool: + ... + + @property + def authority(self) -> str: + ... + + @property + def path(self) -> str: + ... + + @property + def uri(self) -> str: + ... + + @staticmethod + def equals(a: Uri, b: Uri) -> bool: + ... + + @staticmethod + def is_uri(value: Any) -> bool: + ... + + @staticmethod + def is_valid_uri(uri: str, parsed: Optional[UriConfig] = ...) -> Tuple[Union[UriConfig, None], bool]: + ... + + @staticmethod + def parse_uri(uri: str) -> UriConfig: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi new file mode 100644 index 00000000..ea321ac0 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from .uri import Uri +from .wrap_package import IWrapPackage + +@dataclass(slots=True, kw_only=True) +class UriPackage: + uri: Uri + package: IWrapPackage + ... + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi new file mode 100644 index 00000000..ef3413de --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Union +from .uri import Uri +from .uri_package import UriPackage +from .uri_wrapper import UriWrapper + +UriPackageOrWrapper = Union[Uri, UriWrapper, UriPackage] diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_context.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_context.pyi new file mode 100644 index 00000000..90cb7ff4 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_context.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import List +from .uri import Uri +from .uri_resolution_step import IUriResolutionStep + +class IUriResolutionContext(ABC): + @abstractmethod + def is_resolving(self, uri: Uri) -> bool: + ... + + @abstractmethod + def start_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def stop_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def track_step(self, step: IUriResolutionStep) -> None: + ... + + @abstractmethod + def get_history(self) -> List[IUriResolutionStep]: + ... + + @abstractmethod + def get_resolution_path(self) -> List[Uri]: + ... + + @abstractmethod + def create_sub_history_context(self) -> IUriResolutionContext: + ... + + @abstractmethod + def create_sub_context(self) -> IUriResolutionContext: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_step.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_step.pyi new file mode 100644 index 00000000..226d83f9 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolution_step.pyi @@ -0,0 +1,20 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from typing import List, Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class IUriResolutionStep: + source_uri: Uri + result: Result[UriPackageOrWrapper] + description: Optional[str] = ... + sub_history: Optional[List[IUriResolutionStep]] = ... + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver.pyi new file mode 100644 index 00000000..3cc60242 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver.pyi @@ -0,0 +1,35 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext +from .client import Client +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class TryResolveUriOptions: + """ + Args: + no_cache_read: If set to true, the resolveUri function will not use the cache to resolve the uri. + no_cache_write: If set to true, the resolveUri function will not cache the results + config: Override the client's config for all resolutions. + context_id: Id used to track context data set internally. + """ + uri: Uri + resolution_context: Optional[IUriResolutionContext] = ... + + +class IUriResolver(ABC): + @abstractmethod + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver_handler.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver_handler.pyi new file mode 100644 index 00000000..3ec6cea2 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_resolver_handler.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING +from polywrap_result import Result +from .uri_resolver import TryResolveUriOptions +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +class UriResolverHandler(ABC): + @abstractmethod + async def try_resolve_uri(self, options: TryResolveUriOptions) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi new file mode 100644 index 00000000..408529a8 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from .uri import Uri +from .wrapper import Wrapper + +@dataclass(slots=True, kw_only=True) +class UriWrapper: + uri: Uri + wrapper: Wrapper + ... + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi new file mode 100644 index 00000000..a7744aa1 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result +from .wrap_package import IWrapPackage + +class IWasmPackage(IWrapPackage, ABC): + @abstractmethod + async def get_wasm_module() -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/wrap_package.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/wrap_package.pyi new file mode 100644 index 00000000..72015a06 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/wrap_package.pyi @@ -0,0 +1,22 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import Optional +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetManifestOptions +from .wrapper import Wrapper + +class IWrapPackage(ABC): + @abstractmethod + async def create_wrapper(self) -> Result[Wrapper]: + ... + + @abstractmethod + async def get_manifest(self, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi new file mode 100644 index 00000000..cba4d900 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi @@ -0,0 +1,34 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from typing import Dict, Union +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetFileOptions +from .invoke import Invocable, InvocableResult, InvokeOptions, Invoker + +class Wrapper(Invocable): + """ + Invoke the Wrapper based on the provided [[InvokeOptions]] + + Args: + options: Options for this invocation. + client: The client instance requesting this invocation. This client will be used for any sub-invokes that occur. + """ + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + @abstractmethod + async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: + ... + + @abstractmethod + def get_manifest(self) -> Result[AnyWrapManifest]: + ... + + + +WrapperCache = Dict[str, Wrapper] diff --git a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi new file mode 100644 index 00000000..a4101f84 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from .uri_resolution_context import * +from .uri_resolution_result import * + diff --git a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi new file mode 100644 index 00000000..bd999afc --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi @@ -0,0 +1,41 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Set +from ..types import IUriResolutionContext, IUriResolutionStep, Uri + +class UriResolutionContext(IUriResolutionContext): + resolving_uri_set: Set[Uri] + resolution_path: List[Uri] + history: List[IUriResolutionStep] + __slots__ = ... + def __init__(self, resolving_uri_set: Optional[Set[Uri]] = ..., resolution_path: Optional[List[Uri]] = ..., history: Optional[List[IUriResolutionStep]] = ...) -> None: + ... + + def is_resolving(self, uri: Uri) -> bool: + ... + + def start_resolving(self, uri: Uri) -> None: + ... + + def stop_resolving(self, uri: Uri) -> None: + ... + + def track_step(self, step: IUriResolutionStep) -> None: + ... + + def get_history(self) -> List[IUriResolutionStep]: + ... + + def get_resolution_path(self) -> List[Uri]: + ... + + def create_sub_history_context(self) -> UriResolutionContext: + ... + + def create_sub_context(self) -> UriResolutionContext: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi new file mode 100644 index 00000000..c73c4fe1 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi @@ -0,0 +1,21 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional +from polywrap_result import Result +from ..types import IUriResolutionStep, IWrapPackage, Uri, UriPackageOrWrapper, Wrapper + +class UriResolutionResult: + result: Result[UriPackageOrWrapper] + history: Optional[List[IUriResolutionStep]] + @staticmethod + def ok(uri: Uri, package: Optional[IWrapPackage] = ..., wrapper: Optional[Wrapper] = ...) -> Result[UriPackageOrWrapper]: + ... + + @staticmethod + def err(error: Exception) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-plugin/typings/polywrap_core/utils/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/utils/__init__.pyi new file mode 100644 index 00000000..b2a379f8 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/utils/__init__.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from .get_env_from_uri_history import * +from .init_wrapper import * +from .instance_of import * +from .maybe_async import * + diff --git a/packages/polywrap-plugin/typings/polywrap_core/utils/get_env_from_uri_history.pyi b/packages/polywrap-plugin/typings/polywrap_core/utils/get_env_from_uri_history.pyi new file mode 100644 index 00000000..b75c0458 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/utils/get_env_from_uri_history.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict, List, Union +from ..types import Client, Uri + +def get_env_from_uri_history(uri_history: List[Uri], client: Client) -> Union[Dict[str, Any], None]: + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_core/utils/init_wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/utils/init_wrapper.pyi new file mode 100644 index 00000000..87c450a0 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/utils/init_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any +from ..types import Wrapper + +async def init_wrapper(packageOrWrapper: Any) -> Wrapper: + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_core/utils/instance_of.pyi b/packages/polywrap-plugin/typings/polywrap_core/utils/instance_of.pyi new file mode 100644 index 00000000..84ac59e0 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/utils/instance_of.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any + +def instance_of(obj: Any, cls: Any): # -> bool: + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_core/utils/maybe_async.pyi b/packages/polywrap-plugin/typings/polywrap_core/utils/maybe_async.pyi new file mode 100644 index 00000000..e6e6f0be --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/utils/maybe_async.pyi @@ -0,0 +1,12 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Awaitable, Callable, Optional, Union + +def is_coroutine(test: Optional[Union[Awaitable[Any], Any]] = ...) -> bool: + ... + +async def execute_maybe_async_function(func: Callable[..., Any], *args: Any) -> Any: + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_manifest/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_manifest/__init__.pyi new file mode 100644 index 00000000..fa27423a --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_manifest/__init__.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from .deserialize import * +from .manifest import * + diff --git a/packages/polywrap-plugin/typings/polywrap_manifest/deserialize.pyi b/packages/polywrap-plugin/typings/polywrap_manifest/deserialize.pyi new file mode 100644 index 00000000..5fd1f32c --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_manifest/deserialize.pyi @@ -0,0 +1,16 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_result import Result +from .manifest import * + +""" +This file was automatically generated by scripts/templates/deserialize.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/deserialize.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +def deserialize_wrap_manifest(manifest: bytes, options: Optional[DeserializeManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_manifest/manifest.pyi b/packages/polywrap-plugin/typings/polywrap_manifest/manifest.pyi new file mode 100644 index 00000000..b5a88605 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_manifest/manifest.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from enum import Enum +from .wrap_0_1 import Abi as WrapAbi_0_1_0_1, WrapManifest as WrapManifest_0_1 + +""" +This file was automatically generated by scripts/templates/__init__.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/__init__.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +@dataclass(slots=True, kw_only=True) +class DeserializeManifestOptions: + no_validate: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class serializeManifestOptions: + no_validate: Optional[bool] = ... + + +class WrapManifestVersions(Enum): + VERSION_0_1 = ... + def __new__(cls, value: int, *aliases: str) -> WrapManifestVersions: + ... + + + +class WrapManifestAbiVersions(Enum): + VERSION_0_1 = ... + + +class WrapAbiVersions(Enum): + VERSION_0_1 = ... + + +AnyWrapManifest = WrapManifest_0_1 +AnyWrapAbi = WrapAbi_0_1_0_1 +WrapManifest = ... +WrapAbi = WrapAbi_0_1_0_1 +latest_wrap_manifest_version = ... +latest_wrap_abi_version = ... diff --git a/packages/polywrap-plugin/typings/polywrap_manifest/wrap_0_1.pyi b/packages/polywrap-plugin/typings/polywrap_manifest/wrap_0_1.pyi new file mode 100644 index 00000000..90b68065 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_manifest/wrap_0_1.pyi @@ -0,0 +1,209 @@ +""" +This type stub file was generated by pyright. +""" + +from enum import Enum +from typing import List, Optional +from pydantic import BaseModel + +class Version(Enum): + """ + WRAP Standard Version + """ + VERSION_0_1_0 = ... + VERSION_0_1 = ... + + +class Type(Enum): + """ + Wrapper Package Type + """ + WASM = ... + INTERFACE = ... + PLUGIN = ... + + +class Env(BaseModel): + required: Optional[bool] = ... + + +class GetImplementations(BaseModel): + enabled: bool + ... + + +class CapabilityDefinition(BaseModel): + get_implementations: Optional[GetImplementations] = ... + + +class ImportedDefinition(BaseModel): + uri: str + namespace: str + native_type: str = ... + + +class WithKind(BaseModel): + kind: float + ... + + +class WithComment(BaseModel): + comment: Optional[str] = ... + + +class GenericDefinition(WithKind): + type: str + name: Optional[str] = ... + required: Optional[bool] = ... + + +class ScalarType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + BOOLEAN = ... + BYTES = ... + BIG_INT = ... + BIG_NUMBER = ... + JSON = ... + + +class ScalarDefinition(GenericDefinition): + type: ScalarType + ... + + +class MapKeyType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + + +class ObjectRef(GenericDefinition): + ... + + +class EnumRef(GenericDefinition): + ... + + +class UnresolvedObjectOrEnumRef(GenericDefinition): + ... + + +class ImportedModuleRef(BaseModel): + type: Optional[str] = ... + + +class InterfaceImplementedDefinition(GenericDefinition): + ... + + +class EnumDefinition(GenericDefinition, WithComment): + constants: Optional[List[str]] = ... + + +class InterfaceDefinition(GenericDefinition, ImportedDefinition): + capabilities: Optional[CapabilityDefinition] = ... + + +class ImportedEnumDefinition(EnumDefinition, ImportedDefinition): + ... + + +class WrapManifest(BaseModel): + class Config: + extra = ... + + + version: Version = ... + type: Type = ... + name: str = ... + abi: Abi = ... + + +class Abi(BaseModel): + version: Optional[str] = ... + object_types: Optional[List[ObjectDefinition]] = ... + module_type: Optional[ModuleDefinition] = ... + enum_types: Optional[List[EnumDefinition]] = ... + interface_types: Optional[List[InterfaceDefinition]] = ... + imported_object_types: Optional[List[ImportedObjectDefinition]] = ... + imported_module_types: Optional[List[ImportedModuleDefinition]] = ... + imported_enum_types: Optional[List[ImportedEnumDefinition]] = ... + imported_env_types: Optional[List[ImportedEnvDefinition]] = ... + env_type: Optional[EnvDefinition] = ... + + +class ObjectDefinition(GenericDefinition, WithComment): + properties: Optional[List[PropertyDefinition]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class ModuleDefinition(GenericDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + imports: Optional[List[ImportedModuleRef]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class MethodDefinition(GenericDefinition, WithComment): + arguments: Optional[List[PropertyDefinition]] = ... + env: Optional[Env] = ... + return_: Optional[PropertyDefinition] = ... + + +class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + is_interface: Optional[bool] = ... + + +class AnyDefinition(GenericDefinition): + array: Optional[ArrayDefinition] = ... + scalar: Optional[ScalarDefinition] = ... + map: Optional[MapDefinition] = ... + object: Optional[ObjectRef] = ... + enum: Optional[EnumRef] = ... + unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = ... + + +class EnvDefinition(ObjectDefinition): + ... + + +class ImportedObjectDefinition(ObjectDefinition, ImportedDefinition, WithComment): + ... + + +class PropertyDefinition(WithComment, AnyDefinition): + ... + + +class ArrayDefinition(AnyDefinition): + item: Optional[GenericDefinition] = ... + + +class MapKeyDefinition(AnyDefinition): + type: Optional[MapKeyType] = ... + + +class MapDefinition(AnyDefinition, WithComment): + key: Optional[MapKeyDefinition] = ... + value: Optional[GenericDefinition] = ... + + +class ImportedEnvDefinition(ImportedObjectDefinition): + ... + + diff --git a/packages/polywrap-plugin/typings/polywrap_msgpack/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_msgpack/__init__.pyi new file mode 100644 index 00000000..205bd701 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_msgpack/__init__.pyi @@ -0,0 +1,74 @@ +""" +This type stub file was generated by pyright. +""" + +import msgpack +from enum import Enum +from typing import Any, Dict, List, Set +from msgpack.exceptions import UnpackValueError + +""" +polywrap-msgpack adds ability to encode/decode to/from msgpack format. + +It provides msgpack_encode and msgpack_decode functions +which allows user to encode and decode to/from msgpack bytes + +It also defines the default Extension types and extension hook for +custom extension types defined by wrap standard +""" +class ExtensionTypes(Enum): + """Wrap msgpack extension types.""" + GENERIC_MAP = ... + + +def ext_hook(code: int, data: bytes) -> Any: + """Extension hook for extending the msgpack supported types. + + Args: + code (int): extension type code (>0 & <256) + data (bytes): msgpack deserializable data as payload + + Raises: + UnpackValueError: when given invalid extension type code + + Returns: + Any: decoded object + """ + ... + +def sanitize(value: Any) -> Any: + """Sanitizes the value into msgpack encoder compatible format. + + Args: + value: any valid python value + + Raises: + ValueError: when dict key isn't string + + Returns: + Any: msgpack compatible sanitized value + """ + ... + +def msgpack_encode(value: Any) -> bytes: + """Encode any python object into msgpack bytes. + + Args: + value: any valid python object + + Returns: + bytes: encoded msgpack value + """ + ... + +def msgpack_decode(val: bytes) -> Any: + """Decode msgpack bytes into a valid python object. + + Args: + val: msgpack encoded bytes + + Returns: + Any: python object + """ + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_result/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_result/__init__.pyi new file mode 100644 index 00000000..b04f91a7 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_result/__init__.pyi @@ -0,0 +1,322 @@ +""" +This type stub file was generated by pyright. +""" + +import inspect +import sys +import types +from __future__ import annotations +from typing import Any, Callable, Generic, NoReturn, ParamSpec, Type, TypeVar, Union, cast, overload +from typing_extensions import ParamSpec + +""" +A simple Rust like Result type for Python 3. + +This project has been forked from the https://github.com/rustedpy/result. +""" +if sys.version_info[: 2] >= (3, 10): + ... +else: + ... +T = TypeVar("T", covariant=True) +U = TypeVar("U") +F = TypeVar("F") +P = ... +R = TypeVar("R") +TBE = TypeVar("TBE", bound=BaseException) +class Ok(Generic[T]): + """ + A value that indicates success and which stores arbitrary data for the return value. + """ + _value: T + __match_args__ = ... + __slots__ = ... + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, value: T) -> None: + ... + + def __init__(self, value: Any = ...) -> None: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> T: + """ + Return the value. + """ + ... + + def err(self) -> None: + """ + Return `None`. + """ + ... + + @property + def value(self) -> T: + """ + Return the inner value. + """ + ... + + def expect(self, _message: str) -> T: + """ + Return the value. + """ + ... + + def expect_err(self, message: str) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap(self) -> T: + """ + Return the value. + """ + ... + + def unwrap_err(self) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap_or(self, _default: U) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_raise(self) -> T: + """ + Return the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + The contained result is `Ok`, so return `Ok` with original value mapped to + a new value using the passed in function. + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return the original value mapped to a new + value using the passed in function. + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return original value mapped to + a new value using the passed in `op` function. + """ + ... + + def map_err(self, op: Callable[[Exception], F]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Ok`, so return the result of `op` with the + original value passed in + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + + +class Err: + """ + A value that signifies failure and which stores arbitrary data for the error. + """ + __match_args__ = ... + __slots__ = ... + def __init__(self, value: Exception) -> None: + ... + + @classmethod + def from_str(cls, value: str) -> Err: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> None: + """ + Return `None`. + """ + ... + + def err(self) -> Exception: + """ + Return the error. + """ + ... + + @property + def value(self) -> Exception: + """ + Return the inner value. + """ + ... + + def expect(self, message: str) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def expect_err(self, _message: str) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap(self) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def unwrap_err(self) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap_or(self, default: U) -> U: + """ + Return `default`. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + The contained result is ``Err``, so return the result of applying + ``op`` to the error value. + """ + ... + + def unwrap_or_raise(self) -> NoReturn: + """ + The contained result is ``Err``, so raise the exception with the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + Return `Err` with the same value + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + Return the default value + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + Return the result of the default operation + """ + ... + + def map_err(self, op: Callable[[Exception], Exception]) -> Result[T]: + """ + The contained result is `Err`, so return `Err` with original error mapped to + a new value using the passed in function. + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Err`, so return `Err` with the original value + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Err`, so return the result of `op` with the + original value passed in + """ + ... + + + +Result = Union[Ok[T], Err] +class UnwrapError(Exception): + """ + Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + + The original ``Result`` can be accessed via the ``.result`` attribute, but + this is not intended for regular use, as type information is lost: + ``UnwrapError`` doesn't know about both ``T`` and ``E``, since it's raised + from ``Ok()`` or ``Err()`` which only knows about either ``T`` or ``E``, + not both. + """ + _result: Result[Any] + def __init__(self, result: Result[Any], message: str) -> None: + ... + + @property + def result(self) -> Result[Any]: + """ + Returns the original result. + """ + ... + + + diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py index ebe12340..a3b363c3 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/abc/uri_resolver_aggregator.py @@ -9,7 +9,7 @@ Uri, UriPackageOrWrapper, ) -from polywrap_result import Err, Result +from polywrap_result import Err, Ok, Result class IUriResolverAggregator(IUriResolver, ABC): @@ -61,7 +61,7 @@ async def try_resolve_uri_with_resolvers( return result - result = UriResolutionResult.ok(uri) + result = Ok(uri) step = IUriResolutionStep( source_uri=uri, diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi new file mode 100644 index 00000000..0f0cde3d --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from .types import * +from .uri_resolution import * +from .utils import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi new file mode 100644 index 00000000..17a9261d --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi @@ -0,0 +1,17 @@ +""" +This type stub file was generated by pyright. +""" + +from .client import * +from .file_reader import * +from .invoke import * +from .uri import * +from .uri_package_wrapper import * +from .uri_resolution_context import * +from .uri_resolution_step import * +from .uri_resolver import * +from .uri_resolver_handler import * +from .wasm_package import * +from .wrap_package import * +from .wrapper import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/client.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/client.pyi new file mode 100644 index 00000000..d1a2ab03 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/client.pyi @@ -0,0 +1,60 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from dataclasses import dataclass +from typing import Dict, List, Optional, Union +from polywrap_manifest import AnyWrapManifest, DeserializeManifestOptions +from polywrap_result import Result +from .env import Env +from .invoke import Invoker +from .uri import Uri +from .uri_resolver import IUriResolver +from .uri_resolver_handler import UriResolverHandler + +@dataclass(slots=True, kw_only=True) +class ClientConfig: + envs: Dict[Uri, Env] = ... + interfaces: Dict[Uri, List[Uri]] = ... + resolver: IUriResolver + + +@dataclass(slots=True, kw_only=True) +class GetFileOptions: + path: str + encoding: Optional[str] = ... + + +@dataclass(slots=True, kw_only=True) +class GetManifestOptions(DeserializeManifestOptions): + ... + + +class Client(Invoker, UriResolverHandler): + @abstractmethod + def get_interfaces(self) -> Dict[Uri, List[Uri]]: + ... + + @abstractmethod + def get_envs(self) -> Dict[Uri, Env]: + ... + + @abstractmethod + def get_env_by_uri(self, uri: Uri) -> Union[Env, None]: + ... + + @abstractmethod + def get_uri_resolver(self) -> IUriResolver: + ... + + @abstractmethod + async def get_file(self, uri: Uri, options: GetFileOptions) -> Result[Union[bytes, str]]: + ... + + @abstractmethod + async def get_manifest(self, uri: Uri, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/env.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/env.pyi new file mode 100644 index 00000000..2d02a65d --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/env.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict + +Env = Dict[str, Any] diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/file_reader.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/file_reader.pyi new file mode 100644 index 00000000..946a80dc --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/file_reader.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result + +class IFileReader(ABC): + @abstractmethod + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/invoke.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/invoke.pyi new file mode 100644 index 00000000..59c615a5 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/invoke.pyi @@ -0,0 +1,67 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Any, Dict, List, Optional, Union +from polywrap_result import Result +from .env import Env +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext + +@dataclass(slots=True, kw_only=True) +class InvokeOptions: + """ + Options required for a wrapper invocation. + + Args: + uri: Uri of the wrapper + method: Method to be executed + args: Arguments for the method, structured as a dictionary + config: Override the client's config for all invokes within this invoke. + context_id: Invoke id used to track query context data set internally. + """ + uri: Uri + method: str + args: Optional[Union[Dict[str, Any], bytes]] = ... + env: Optional[Env] = ... + resolution_context: Optional[IUriResolutionContext] = ... + + +@dataclass(slots=True, kw_only=True) +class InvocableResult: + """ + Result of a wrapper invocation + + Args: + data: Invoke result data. The type of this value is the return type of the method. + encoded: It will be set true if result is encoded + """ + result: Optional[Any] = ... + encoded: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class InvokerOptions(InvokeOptions): + encode_result: Optional[bool] = ... + + +class Invoker(ABC): + @abstractmethod + async def invoke(self, options: InvokerOptions) -> Result[Any]: + ... + + @abstractmethod + def get_implementations(self, uri: Uri) -> Result[Union[List[Uri], None]]: + ... + + + +class Invocable(ABC): + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri.pyi new file mode 100644 index 00000000..5371344c --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri.pyi @@ -0,0 +1,81 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from functools import total_ordering +from typing import Any, Optional, Tuple, Union + +@dataclass(slots=True, kw_only=True) +class UriConfig: + """URI configuration.""" + authority: str + path: str + uri: str + ... + + +@total_ordering +class Uri: + """ + A Polywrap URI. + + Some examples of valid URIs are: + wrap://ipfs/QmHASH + wrap://ens/sub.dimain.eth + wrap://fs/directory/file.txt + wrap://uns/domain.crypto + Breaking down the various parts of the URI, as it applies + to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): + **wrap://** - URI Scheme: differentiates Polywrap URIs. + **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. + **sub.domain.eth** - URI Path: tells the Authority where the API resides. + """ + def __init__(self, uri: str) -> None: + ... + + def __str__(self) -> str: + ... + + def __repr__(self) -> str: + ... + + def __hash__(self) -> int: + ... + + def __eq__(self, b: object) -> bool: + ... + + def __lt__(self, b: Uri) -> bool: + ... + + @property + def authority(self) -> str: + ... + + @property + def path(self) -> str: + ... + + @property + def uri(self) -> str: + ... + + @staticmethod + def equals(a: Uri, b: Uri) -> bool: + ... + + @staticmethod + def is_uri(value: Any) -> bool: + ... + + @staticmethod + def is_valid_uri(uri: str, parsed: Optional[UriConfig] = ...) -> Tuple[Union[UriConfig, None], bool]: + ... + + @staticmethod + def parse_uri(uri: str) -> UriConfig: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_package_wrapper.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_package_wrapper.pyi new file mode 100644 index 00000000..619b7e14 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_package_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Union +from .uri import Uri +from .wrap_package import IWrapPackage +from .wrapper import Wrapper + +UriPackageOrWrapper = Union[Uri, Wrapper, IWrapPackage] diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_context.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_context.pyi new file mode 100644 index 00000000..90cb7ff4 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_context.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import List +from .uri import Uri +from .uri_resolution_step import IUriResolutionStep + +class IUriResolutionContext(ABC): + @abstractmethod + def is_resolving(self, uri: Uri) -> bool: + ... + + @abstractmethod + def start_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def stop_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def track_step(self, step: IUriResolutionStep) -> None: + ... + + @abstractmethod + def get_history(self) -> List[IUriResolutionStep]: + ... + + @abstractmethod + def get_resolution_path(self) -> List[Uri]: + ... + + @abstractmethod + def create_sub_history_context(self) -> IUriResolutionContext: + ... + + @abstractmethod + def create_sub_context(self) -> IUriResolutionContext: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_step.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_step.pyi new file mode 100644 index 00000000..226d83f9 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolution_step.pyi @@ -0,0 +1,20 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from typing import List, Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class IUriResolutionStep: + source_uri: Uri + result: Result[UriPackageOrWrapper] + description: Optional[str] = ... + sub_history: Optional[List[IUriResolutionStep]] = ... + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver.pyi new file mode 100644 index 00000000..3cc60242 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver.pyi @@ -0,0 +1,35 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext +from .client import Client +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class TryResolveUriOptions: + """ + Args: + no_cache_read: If set to true, the resolveUri function will not use the cache to resolve the uri. + no_cache_write: If set to true, the resolveUri function will not cache the results + config: Override the client's config for all resolutions. + context_id: Id used to track context data set internally. + """ + uri: Uri + resolution_context: Optional[IUriResolutionContext] = ... + + +class IUriResolver(ABC): + @abstractmethod + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver_handler.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver_handler.pyi new file mode 100644 index 00000000..3ec6cea2 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/uri_resolver_handler.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING +from polywrap_result import Result +from .uri_resolver import TryResolveUriOptions +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +class UriResolverHandler(ABC): + @abstractmethod + async def try_resolve_uri(self, options: TryResolveUriOptions) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wasm_package.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wasm_package.pyi new file mode 100644 index 00000000..4de7f1f7 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wasm_package.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result +from .wrap_package import IWrapPackage + +class IWasmPackage(IWrapPackage, ABC): + @abstractmethod + async def get_wasm_module(self) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrap_package.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrap_package.pyi new file mode 100644 index 00000000..72015a06 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrap_package.pyi @@ -0,0 +1,22 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import Optional +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetManifestOptions +from .wrapper import Wrapper + +class IWrapPackage(ABC): + @abstractmethod + async def create_wrapper(self) -> Result[Wrapper]: + ... + + @abstractmethod + async def get_manifest(self, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrapper.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrapper.pyi new file mode 100644 index 00000000..4a05539f --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/wrapper.pyi @@ -0,0 +1,34 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from typing import Any, Dict, Union +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetFileOptions +from .invoke import Invocable, InvokeOptions, Invoker + +class Wrapper(Invocable): + """ + Invoke the Wrapper based on the provided [[InvokeOptions]] + + Args: + options: Options for this invocation. + client: The client instance requesting this invocation. This client will be used for any sub-invokes that occur. + """ + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[Any]: + ... + + @abstractmethod + async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: + ... + + @abstractmethod + def get_manifest(self) -> Result[AnyWrapManifest]: + ... + + + +WrapperCache = Dict[str, Wrapper] diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/__init__.pyi new file mode 100644 index 00000000..aacd9177 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .uri_resolution_context import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi new file mode 100644 index 00000000..bd999afc --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi @@ -0,0 +1,41 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Set +from ..types import IUriResolutionContext, IUriResolutionStep, Uri + +class UriResolutionContext(IUriResolutionContext): + resolving_uri_set: Set[Uri] + resolution_path: List[Uri] + history: List[IUriResolutionStep] + __slots__ = ... + def __init__(self, resolving_uri_set: Optional[Set[Uri]] = ..., resolution_path: Optional[List[Uri]] = ..., history: Optional[List[IUriResolutionStep]] = ...) -> None: + ... + + def is_resolving(self, uri: Uri) -> bool: + ... + + def start_resolving(self, uri: Uri) -> None: + ... + + def stop_resolving(self, uri: Uri) -> None: + ... + + def track_step(self, step: IUriResolutionStep) -> None: + ... + + def get_history(self) -> List[IUriResolutionStep]: + ... + + def get_resolution_path(self) -> List[Uri]: + ... + + def create_sub_history_context(self) -> UriResolutionContext: + ... + + def create_sub_context(self) -> UriResolutionContext: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/__init__.pyi new file mode 100644 index 00000000..b2a379f8 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/__init__.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from .get_env_from_uri_history import * +from .init_wrapper import * +from .instance_of import * +from .maybe_async import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/get_env_from_uri_history.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/get_env_from_uri_history.pyi new file mode 100644 index 00000000..b75c0458 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/get_env_from_uri_history.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict, List, Union +from ..types import Client, Uri + +def get_env_from_uri_history(uri_history: List[Uri], client: Client) -> Union[Dict[str, Any], None]: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/init_wrapper.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/init_wrapper.pyi new file mode 100644 index 00000000..87c450a0 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/init_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any +from ..types import Wrapper + +async def init_wrapper(packageOrWrapper: Any) -> Wrapper: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/instance_of.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/instance_of.pyi new file mode 100644 index 00000000..84ac59e0 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/instance_of.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any + +def instance_of(obj: Any, cls: Any): # -> bool: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/maybe_async.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/maybe_async.pyi new file mode 100644 index 00000000..e6e6f0be --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/utils/maybe_async.pyi @@ -0,0 +1,12 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Awaitable, Callable, Optional, Union + +def is_coroutine(test: Optional[Union[Awaitable[Any], Any]] = ...) -> bool: + ... + +async def execute_maybe_async_function(func: Callable[..., Any], *args: Any) -> Any: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_manifest/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/__init__.pyi new file mode 100644 index 00000000..fa27423a --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/__init__.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from .deserialize import * +from .manifest import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_manifest/deserialize.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/deserialize.pyi new file mode 100644 index 00000000..5fd1f32c --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/deserialize.pyi @@ -0,0 +1,16 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_result import Result +from .manifest import * + +""" +This file was automatically generated by scripts/templates/deserialize.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/deserialize.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +def deserialize_wrap_manifest(manifest: bytes, options: Optional[DeserializeManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_manifest/manifest.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/manifest.pyi new file mode 100644 index 00000000..b5a88605 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/manifest.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from enum import Enum +from .wrap_0_1 import Abi as WrapAbi_0_1_0_1, WrapManifest as WrapManifest_0_1 + +""" +This file was automatically generated by scripts/templates/__init__.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/__init__.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +@dataclass(slots=True, kw_only=True) +class DeserializeManifestOptions: + no_validate: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class serializeManifestOptions: + no_validate: Optional[bool] = ... + + +class WrapManifestVersions(Enum): + VERSION_0_1 = ... + def __new__(cls, value: int, *aliases: str) -> WrapManifestVersions: + ... + + + +class WrapManifestAbiVersions(Enum): + VERSION_0_1 = ... + + +class WrapAbiVersions(Enum): + VERSION_0_1 = ... + + +AnyWrapManifest = WrapManifest_0_1 +AnyWrapAbi = WrapAbi_0_1_0_1 +WrapManifest = ... +WrapAbi = WrapAbi_0_1_0_1 +latest_wrap_manifest_version = ... +latest_wrap_abi_version = ... diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_manifest/wrap_0_1.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/wrap_0_1.pyi new file mode 100644 index 00000000..90b68065 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_manifest/wrap_0_1.pyi @@ -0,0 +1,209 @@ +""" +This type stub file was generated by pyright. +""" + +from enum import Enum +from typing import List, Optional +from pydantic import BaseModel + +class Version(Enum): + """ + WRAP Standard Version + """ + VERSION_0_1_0 = ... + VERSION_0_1 = ... + + +class Type(Enum): + """ + Wrapper Package Type + """ + WASM = ... + INTERFACE = ... + PLUGIN = ... + + +class Env(BaseModel): + required: Optional[bool] = ... + + +class GetImplementations(BaseModel): + enabled: bool + ... + + +class CapabilityDefinition(BaseModel): + get_implementations: Optional[GetImplementations] = ... + + +class ImportedDefinition(BaseModel): + uri: str + namespace: str + native_type: str = ... + + +class WithKind(BaseModel): + kind: float + ... + + +class WithComment(BaseModel): + comment: Optional[str] = ... + + +class GenericDefinition(WithKind): + type: str + name: Optional[str] = ... + required: Optional[bool] = ... + + +class ScalarType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + BOOLEAN = ... + BYTES = ... + BIG_INT = ... + BIG_NUMBER = ... + JSON = ... + + +class ScalarDefinition(GenericDefinition): + type: ScalarType + ... + + +class MapKeyType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + + +class ObjectRef(GenericDefinition): + ... + + +class EnumRef(GenericDefinition): + ... + + +class UnresolvedObjectOrEnumRef(GenericDefinition): + ... + + +class ImportedModuleRef(BaseModel): + type: Optional[str] = ... + + +class InterfaceImplementedDefinition(GenericDefinition): + ... + + +class EnumDefinition(GenericDefinition, WithComment): + constants: Optional[List[str]] = ... + + +class InterfaceDefinition(GenericDefinition, ImportedDefinition): + capabilities: Optional[CapabilityDefinition] = ... + + +class ImportedEnumDefinition(EnumDefinition, ImportedDefinition): + ... + + +class WrapManifest(BaseModel): + class Config: + extra = ... + + + version: Version = ... + type: Type = ... + name: str = ... + abi: Abi = ... + + +class Abi(BaseModel): + version: Optional[str] = ... + object_types: Optional[List[ObjectDefinition]] = ... + module_type: Optional[ModuleDefinition] = ... + enum_types: Optional[List[EnumDefinition]] = ... + interface_types: Optional[List[InterfaceDefinition]] = ... + imported_object_types: Optional[List[ImportedObjectDefinition]] = ... + imported_module_types: Optional[List[ImportedModuleDefinition]] = ... + imported_enum_types: Optional[List[ImportedEnumDefinition]] = ... + imported_env_types: Optional[List[ImportedEnvDefinition]] = ... + env_type: Optional[EnvDefinition] = ... + + +class ObjectDefinition(GenericDefinition, WithComment): + properties: Optional[List[PropertyDefinition]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class ModuleDefinition(GenericDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + imports: Optional[List[ImportedModuleRef]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class MethodDefinition(GenericDefinition, WithComment): + arguments: Optional[List[PropertyDefinition]] = ... + env: Optional[Env] = ... + return_: Optional[PropertyDefinition] = ... + + +class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + is_interface: Optional[bool] = ... + + +class AnyDefinition(GenericDefinition): + array: Optional[ArrayDefinition] = ... + scalar: Optional[ScalarDefinition] = ... + map: Optional[MapDefinition] = ... + object: Optional[ObjectRef] = ... + enum: Optional[EnumRef] = ... + unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = ... + + +class EnvDefinition(ObjectDefinition): + ... + + +class ImportedObjectDefinition(ObjectDefinition, ImportedDefinition, WithComment): + ... + + +class PropertyDefinition(WithComment, AnyDefinition): + ... + + +class ArrayDefinition(AnyDefinition): + item: Optional[GenericDefinition] = ... + + +class MapKeyDefinition(AnyDefinition): + type: Optional[MapKeyType] = ... + + +class MapDefinition(AnyDefinition, WithComment): + key: Optional[MapKeyDefinition] = ... + value: Optional[GenericDefinition] = ... + + +class ImportedEnvDefinition(ImportedObjectDefinition): + ... + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_result/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_result/__init__.pyi new file mode 100644 index 00000000..d704a49f --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_result/__init__.pyi @@ -0,0 +1,322 @@ +""" +This type stub file was generated by pyright. +""" + +import inspect +import sys +import types +from __future__ import annotations +from typing import Any, Callable, Generic, NoReturn, ParamSpec, TypeVar, Union, cast, overload +from typing_extensions import ParamSpec + +""" +A simple Rust like Result type for Python 3. + +This project has been forked from the https://github.com/rustedpy/result. +""" +if sys.version_info[: 2] >= (3, 10): + ... +else: + ... +T = TypeVar("T", covariant=True) +U = TypeVar("U") +F = TypeVar("F") +P = ... +R = TypeVar("R") +TBE = TypeVar("TBE", bound=BaseException) +class Ok(Generic[T]): + """ + A value that indicates success and which stores arbitrary data for the return value. + """ + _value: T + __match_args__ = ... + __slots__ = ... + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, value: T) -> None: + ... + + def __init__(self, value: Any = ...) -> None: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> T: + """ + Return the value. + """ + ... + + def err(self) -> None: + """ + Return `None`. + """ + ... + + @property + def value(self) -> T: + """ + Return the inner value. + """ + ... + + def expect(self, _message: str) -> T: + """ + Return the value. + """ + ... + + def expect_err(self, message: str) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap(self) -> T: + """ + Return the value. + """ + ... + + def unwrap_err(self) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap_or(self, _default: U) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_raise(self) -> T: + """ + Return the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + The contained result is `Ok`, so return `Ok` with original value mapped to + a new value using the passed in function. + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return the original value mapped to a new + value using the passed in function. + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return original value mapped to + a new value using the passed in `op` function. + """ + ... + + def map_err(self, op: Callable[[Exception], F]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Ok`, so return the result of `op` with the + original value passed in + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + + +class Err: + """ + A value that signifies failure and which stores arbitrary data for the error. + """ + __match_args__ = ... + __slots__ = ... + def __init__(self, value: Exception) -> None: + ... + + @classmethod + def from_str(cls, value: str) -> Err: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> None: + """ + Return `None`. + """ + ... + + def err(self) -> Exception: + """ + Return the error. + """ + ... + + @property + def value(self) -> Exception: + """ + Return the inner value. + """ + ... + + def expect(self, message: str) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def expect_err(self, _message: str) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap(self) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def unwrap_err(self) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap_or(self, default: U) -> U: + """ + Return `default`. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + The contained result is ``Err``, so return the result of applying + ``op`` to the error value. + """ + ... + + def unwrap_or_raise(self) -> NoReturn: + """ + The contained result is ``Err``, so raise the exception with the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + Return `Err` with the same value + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + Return the default value + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + Return the result of the default operation + """ + ... + + def map_err(self, op: Callable[[Exception], Exception]) -> Result[T]: + """ + The contained result is `Err`, so return `Err` with original error mapped to + a new value using the passed in function. + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Err`, so return `Err` with the original value + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Err`, so return the result of `op` with the + original value passed in + """ + ... + + + +Result = Union[Ok[T], Err] +class UnwrapError(Exception): + """ + Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + + The original ``Result`` can be accessed via the ``.result`` attribute, but + this is not intended for regular use, as type information is lost: + ``UnwrapError`` doesn't know about both ``T`` and ``E``, since it's raised + from ``Ok()`` or ``Err()`` which only knows about either ``T`` or ``E``, + not both. + """ + _result: Result[Any] + def __init__(self, result: Result[Any], message: str) -> None: + ... + + @property + def result(self) -> Result[Any]: + """ + Returns the original result. + """ + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/__init__.pyi new file mode 100644 index 00000000..a0e3eff3 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/__init__.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from .buffer import * +from .constants import * +from .errors import * +from .exports import * +from .imports import * +from .inmemory_file_reader import * +from .types import * +from .wasm_package import * +from .wasm_wrapper import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/buffer.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/buffer.pyi new file mode 100644 index 00000000..38a89b58 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/buffer.pyi @@ -0,0 +1,22 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional + +BufferPointer = ... +def read_bytes(memory_pointer: BufferPointer, memory_length: int, offset: Optional[int] = ..., length: Optional[int] = ...) -> bytearray: + ... + +def read_string(memory_pointer: BufferPointer, memory_length: int, offset: int, length: int) -> str: + ... + +def write_string(memory_pointer: BufferPointer, memory_length: int, value: str, value_offset: int) -> None: + ... + +def write_bytes(memory_pointer: BufferPointer, memory_length: int, value: bytes, value_offset: int) -> None: + ... + +def mem_cpy(memory_pointer: BufferPointer, memory_length: int, value: bytearray, value_length: int, value_offset: int) -> None: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/constants.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/constants.pyi new file mode 100644 index 00000000..1270a60f --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/constants.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +WRAP_MANIFEST_PATH: str +WRAP_MODULE_PATH: str diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/errors.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/errors.pyi new file mode 100644 index 00000000..6c852f15 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/errors.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +class WasmAbortError(RuntimeError): + def __init__(self, message: str) -> None: + ... + + + +class ExportNotFoundError(Exception): + """raises when an export isn't found in the wasm module""" + ... + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/exports.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/exports.pyi new file mode 100644 index 00000000..47bda1c4 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/exports.pyi @@ -0,0 +1,18 @@ +""" +This type stub file was generated by pyright. +""" + +from wasmtime import Func, Instance, Store + +class WrapExports: + _instance: Instance + _store: Store + _wrap_invoke: Func + def __init__(self, instance: Instance, store: Store) -> None: + ... + + def __wrap_invoke__(self, method_length: int, args_length: int, env_length: int) -> bool: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/imports.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/imports.pyi new file mode 100644 index 00000000..2c1f58bc --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/imports.pyi @@ -0,0 +1,21 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any +from polywrap_core import Invoker, InvokerOptions +from polywrap_result import Result +from unsync import unsync +from wasmtime import Instance, Memory, Store +from .types.state import State + +@unsync +async def unsync_invoke(invoker: Invoker, options: InvokerOptions) -> Result[Any]: + ... + +def create_memory(store: Store, module: bytes) -> Memory: + ... + +def create_instance(store: Store, module: bytes, state: State, invoker: Invoker) -> Instance: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/inmemory_file_reader.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/inmemory_file_reader.pyi new file mode 100644 index 00000000..f655b83f --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/inmemory_file_reader.pyi @@ -0,0 +1,20 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_core import IFileReader +from polywrap_result import Result + +class InMemoryFileReader(IFileReader): + _wasm_manifest: Optional[bytes] + _wasm_module: Optional[bytes] + _base_file_reader: IFileReader + def __init__(self, base_file_reader: IFileReader, wasm_module: Optional[bytes] = ..., wasm_manifest: Optional[bytes] = ...) -> None: + ... + + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/__init__.pyi new file mode 100644 index 00000000..3deed82d --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .state import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/state.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/state.pyi new file mode 100644 index 00000000..6e08aa22 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/types/state.pyi @@ -0,0 +1,38 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from typing import Any, List, Optional, TypedDict + +class RawInvokeResult(TypedDict): + result: Optional[bytes] + error: Optional[str] + ... + + +class RawSubinvokeResult(TypedDict): + result: Optional[bytes] + error: Optional[str] + args: List[Any] + ... + + +class RawSubinvokeImplementationResult(TypedDict): + result: Optional[bytes] + error: Optional[str] + args: List[Any] + ... + + +@dataclass(kw_only=True, slots=True) +class State: + invoke: RawInvokeResult = ... + subinvoke: RawSubinvokeResult = ... + subinvoke_implementation: RawSubinvokeImplementationResult = ... + get_implementations_result: Optional[bytes] = ... + method: Optional[str] = ... + args: Optional[bytes] = ... + env: Optional[bytes] = ... + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_package.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_package.pyi new file mode 100644 index 00000000..c92ab00d --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_package.pyi @@ -0,0 +1,27 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional, Union +from polywrap_core import GetManifestOptions, IFileReader, IWasmPackage, Wrapper +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result + +class WasmPackage(IWasmPackage): + file_reader: IFileReader + manifest: Optional[Union[bytes, AnyWrapManifest]] + wasm_module: Optional[bytes] + def __init__(self, file_reader: IFileReader, manifest: Optional[Union[bytes, AnyWrapManifest]] = ..., wasm_module: Optional[bytes] = ...) -> None: + ... + + async def get_manifest(self, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + async def get_wasm_module(self) -> Result[bytes]: + ... + + async def create_wrapper(self) -> Result[Wrapper]: + ... + + + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_wrapper.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_wrapper.pyi new file mode 100644 index 00000000..d5249391 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_wasm/wasm_wrapper.pyi @@ -0,0 +1,35 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Union +from polywrap_core import GetFileOptions, IFileReader, InvocableResult, InvokeOptions, Invoker, Wrapper +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from wasmtime import Store +from .types.state import State + +class WasmWrapper(Wrapper): + file_reader: IFileReader + wasm_module: bytes + manifest: AnyWrapManifest + def __init__(self, file_reader: IFileReader, wasm_module: bytes, manifest: AnyWrapManifest) -> None: + ... + + def get_manifest(self) -> Result[AnyWrapManifest]: + ... + + def get_wasm_module(self) -> Result[bytes]: + ... + + async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: + ... + + def create_wasm_instance(self, store: Store, state: State, invoker: Invoker): # -> Instance | None: + ... + + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + + diff --git a/packages/polywrap-wasm/polywrap_wasm/buffer.py b/packages/polywrap-wasm/polywrap_wasm/buffer.py index e7519b07..5a3d28f3 100644 --- a/packages/polywrap-wasm/polywrap_wasm/buffer.py +++ b/packages/polywrap-wasm/polywrap_wasm/buffer.py @@ -1,5 +1,5 @@ import ctypes -from typing import TYPE_CHECKING, Any, Optional +from typing import TYPE_CHECKING, Any, Optional # pyright: ignore[reportUnusedImport] BufferPointer = ctypes._Pointer[ctypes.c_ubyte] if TYPE_CHECKING else Any # type: ignore diff --git a/packages/polywrap-wasm/polywrap_wasm/imports.py b/packages/polywrap-wasm/polywrap_wasm/imports.py index 5df718b9..4b5e163e 100644 --- a/packages/polywrap-wasm/polywrap_wasm/imports.py +++ b/packages/polywrap-wasm/polywrap_wasm/imports.py @@ -367,7 +367,8 @@ def wrap_get_implementations(uri_ptr: int, uri_len: int) -> bool: raise WasmAbortError( f"failed calling invoker.get_implementations({repr(Uri(uri))})" ) from result.unwrap_err() - implementations: List[str] = [uri.uri for uri in result.unwrap()] + maybeImpls = result.unwrap() + implementations: List[str] = [uri.uri for uri in maybeImpls] if maybeImpls else [] state.get_implementations_result = msgpack_encode(implementations) return len(implementations) > 0 diff --git a/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py b/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py index 345df792..8062cb46 100644 --- a/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py +++ b/packages/polywrap-wasm/polywrap_wasm/wasm_wrapper.py @@ -12,7 +12,7 @@ from polywrap_manifest import AnyWrapManifest from polywrap_msgpack import msgpack_encode from polywrap_result import Err, Ok, Result -from wasmtime import Module, Store +from wasmtime import Store from .exports import WrapExports from .imports import create_instance @@ -80,8 +80,6 @@ async def invoke( args_length = len(state.args) env_length = len(state.env) - # TODO: Pass all necessary args to this log - store = Store() instance = self.create_wasm_instance(store, state, invoker) if not instance: diff --git a/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi new file mode 100644 index 00000000..0f0cde3d --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi @@ -0,0 +1,8 @@ +""" +This type stub file was generated by pyright. +""" + +from .types import * +from .uri_resolution import * +from .utils import * + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi new file mode 100644 index 00000000..17a9261d --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi @@ -0,0 +1,17 @@ +""" +This type stub file was generated by pyright. +""" + +from .client import * +from .file_reader import * +from .invoke import * +from .uri import * +from .uri_package_wrapper import * +from .uri_resolution_context import * +from .uri_resolution_step import * +from .uri_resolver import * +from .uri_resolver_handler import * +from .wasm_package import * +from .wrap_package import * +from .wrapper import * + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/client.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/client.pyi new file mode 100644 index 00000000..d1a2ab03 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/client.pyi @@ -0,0 +1,60 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from dataclasses import dataclass +from typing import Dict, List, Optional, Union +from polywrap_manifest import AnyWrapManifest, DeserializeManifestOptions +from polywrap_result import Result +from .env import Env +from .invoke import Invoker +from .uri import Uri +from .uri_resolver import IUriResolver +from .uri_resolver_handler import UriResolverHandler + +@dataclass(slots=True, kw_only=True) +class ClientConfig: + envs: Dict[Uri, Env] = ... + interfaces: Dict[Uri, List[Uri]] = ... + resolver: IUriResolver + + +@dataclass(slots=True, kw_only=True) +class GetFileOptions: + path: str + encoding: Optional[str] = ... + + +@dataclass(slots=True, kw_only=True) +class GetManifestOptions(DeserializeManifestOptions): + ... + + +class Client(Invoker, UriResolverHandler): + @abstractmethod + def get_interfaces(self) -> Dict[Uri, List[Uri]]: + ... + + @abstractmethod + def get_envs(self) -> Dict[Uri, Env]: + ... + + @abstractmethod + def get_env_by_uri(self, uri: Uri) -> Union[Env, None]: + ... + + @abstractmethod + def get_uri_resolver(self) -> IUriResolver: + ... + + @abstractmethod + async def get_file(self, uri: Uri, options: GetFileOptions) -> Result[Union[bytes, str]]: + ... + + @abstractmethod + async def get_manifest(self, uri: Uri, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/env.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/env.pyi new file mode 100644 index 00000000..2d02a65d --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/env.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict + +Env = Dict[str, Any] diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/file_reader.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/file_reader.pyi new file mode 100644 index 00000000..946a80dc --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/file_reader.pyi @@ -0,0 +1,14 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result + +class IFileReader(ABC): + @abstractmethod + async def read_file(self, file_path: str) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/invoke.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/invoke.pyi new file mode 100644 index 00000000..59c615a5 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/invoke.pyi @@ -0,0 +1,67 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Any, Dict, List, Optional, Union +from polywrap_result import Result +from .env import Env +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext + +@dataclass(slots=True, kw_only=True) +class InvokeOptions: + """ + Options required for a wrapper invocation. + + Args: + uri: Uri of the wrapper + method: Method to be executed + args: Arguments for the method, structured as a dictionary + config: Override the client's config for all invokes within this invoke. + context_id: Invoke id used to track query context data set internally. + """ + uri: Uri + method: str + args: Optional[Union[Dict[str, Any], bytes]] = ... + env: Optional[Env] = ... + resolution_context: Optional[IUriResolutionContext] = ... + + +@dataclass(slots=True, kw_only=True) +class InvocableResult: + """ + Result of a wrapper invocation + + Args: + data: Invoke result data. The type of this value is the return type of the method. + encoded: It will be set true if result is encoded + """ + result: Optional[Any] = ... + encoded: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class InvokerOptions(InvokeOptions): + encode_result: Optional[bool] = ... + + +class Invoker(ABC): + @abstractmethod + async def invoke(self, options: InvokerOptions) -> Result[Any]: + ... + + @abstractmethod + def get_implementations(self, uri: Uri) -> Result[Union[List[Uri], None]]: + ... + + + +class Invocable(ABC): + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/uri.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/uri.pyi new file mode 100644 index 00000000..5371344c --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/uri.pyi @@ -0,0 +1,81 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from functools import total_ordering +from typing import Any, Optional, Tuple, Union + +@dataclass(slots=True, kw_only=True) +class UriConfig: + """URI configuration.""" + authority: str + path: str + uri: str + ... + + +@total_ordering +class Uri: + """ + A Polywrap URI. + + Some examples of valid URIs are: + wrap://ipfs/QmHASH + wrap://ens/sub.dimain.eth + wrap://fs/directory/file.txt + wrap://uns/domain.crypto + Breaking down the various parts of the URI, as it applies + to [the URI standard](https://tools.ietf.org/html/rfc3986#section-3): + **wrap://** - URI Scheme: differentiates Polywrap URIs. + **ipfs/** - URI Authority: allows the Polywrap URI resolution algorithm to determine an authoritative URI resolver. + **sub.domain.eth** - URI Path: tells the Authority where the API resides. + """ + def __init__(self, uri: str) -> None: + ... + + def __str__(self) -> str: + ... + + def __repr__(self) -> str: + ... + + def __hash__(self) -> int: + ... + + def __eq__(self, b: object) -> bool: + ... + + def __lt__(self, b: Uri) -> bool: + ... + + @property + def authority(self) -> str: + ... + + @property + def path(self) -> str: + ... + + @property + def uri(self) -> str: + ... + + @staticmethod + def equals(a: Uri, b: Uri) -> bool: + ... + + @staticmethod + def is_uri(value: Any) -> bool: + ... + + @staticmethod + def is_valid_uri(uri: str, parsed: Optional[UriConfig] = ...) -> Tuple[Union[UriConfig, None], bool]: + ... + + @staticmethod + def parse_uri(uri: str) -> UriConfig: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/uri_package_wrapper.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/uri_package_wrapper.pyi new file mode 100644 index 00000000..619b7e14 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/uri_package_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Union +from .uri import Uri +from .wrap_package import IWrapPackage +from .wrapper import Wrapper + +UriPackageOrWrapper = Union[Uri, Wrapper, IWrapPackage] diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_context.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_context.pyi new file mode 100644 index 00000000..90cb7ff4 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_context.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import List +from .uri import Uri +from .uri_resolution_step import IUriResolutionStep + +class IUriResolutionContext(ABC): + @abstractmethod + def is_resolving(self, uri: Uri) -> bool: + ... + + @abstractmethod + def start_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def stop_resolving(self, uri: Uri) -> None: + ... + + @abstractmethod + def track_step(self, step: IUriResolutionStep) -> None: + ... + + @abstractmethod + def get_history(self) -> List[IUriResolutionStep]: + ... + + @abstractmethod + def get_resolution_path(self) -> List[Uri]: + ... + + @abstractmethod + def create_sub_history_context(self) -> IUriResolutionContext: + ... + + @abstractmethod + def create_sub_context(self) -> IUriResolutionContext: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_step.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_step.pyi new file mode 100644 index 00000000..226d83f9 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolution_step.pyi @@ -0,0 +1,20 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from typing import List, Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class IUriResolutionStep: + source_uri: Uri + result: Result[UriPackageOrWrapper] + description: Optional[str] = ... + sub_history: Optional[List[IUriResolutionStep]] = ... + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver.pyi new file mode 100644 index 00000000..3cc60242 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver.pyi @@ -0,0 +1,35 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from dataclasses import dataclass +from typing import Optional, TYPE_CHECKING +from polywrap_result import Result +from .uri import Uri +from .uri_resolution_context import IUriResolutionContext +from .client import Client +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +@dataclass(slots=True, kw_only=True) +class TryResolveUriOptions: + """ + Args: + no_cache_read: If set to true, the resolveUri function will not use the cache to resolve the uri. + no_cache_write: If set to true, the resolveUri function will not cache the results + config: Override the client's config for all resolutions. + context_id: Id used to track context data set internally. + """ + uri: Uri + resolution_context: Optional[IUriResolutionContext] = ... + + +class IUriResolver(ABC): + @abstractmethod + async def try_resolve_uri(self, uri: Uri, client: Client, resolution_context: IUriResolutionContext) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver_handler.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver_handler.pyi new file mode 100644 index 00000000..3ec6cea2 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/uri_resolver_handler.pyi @@ -0,0 +1,19 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import TYPE_CHECKING +from polywrap_result import Result +from .uri_resolver import TryResolveUriOptions +from .uri_package_wrapper import UriPackageOrWrapper + +if TYPE_CHECKING: + ... +class UriResolverHandler(ABC): + @abstractmethod + async def try_resolve_uri(self, options: TryResolveUriOptions) -> Result[UriPackageOrWrapper]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/wasm_package.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/wasm_package.pyi new file mode 100644 index 00000000..4de7f1f7 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/wasm_package.pyi @@ -0,0 +1,15 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from polywrap_result import Result +from .wrap_package import IWrapPackage + +class IWasmPackage(IWrapPackage, ABC): + @abstractmethod + async def get_wasm_module(self) -> Result[bytes]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/wrap_package.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/wrap_package.pyi new file mode 100644 index 00000000..72015a06 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/wrap_package.pyi @@ -0,0 +1,22 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import ABC, abstractmethod +from typing import Optional +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetManifestOptions +from .wrapper import Wrapper + +class IWrapPackage(ABC): + @abstractmethod + async def create_wrapper(self) -> Result[Wrapper]: + ... + + @abstractmethod + async def get_manifest(self, options: Optional[GetManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/wrapper.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/wrapper.pyi new file mode 100644 index 00000000..4a05539f --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/types/wrapper.pyi @@ -0,0 +1,34 @@ +""" +This type stub file was generated by pyright. +""" + +from abc import abstractmethod +from typing import Any, Dict, Union +from polywrap_manifest import AnyWrapManifest +from polywrap_result import Result +from .client import GetFileOptions +from .invoke import Invocable, InvokeOptions, Invoker + +class Wrapper(Invocable): + """ + Invoke the Wrapper based on the provided [[InvokeOptions]] + + Args: + options: Options for this invocation. + client: The client instance requesting this invocation. This client will be used for any sub-invokes that occur. + """ + @abstractmethod + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[Any]: + ... + + @abstractmethod + async def get_file(self, options: GetFileOptions) -> Result[Union[str, bytes]]: + ... + + @abstractmethod + def get_manifest(self) -> Result[AnyWrapManifest]: + ... + + + +WrapperCache = Dict[str, Wrapper] diff --git a/packages/polywrap-wasm/typings/polywrap_core/uri_resolution/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/uri_resolution/__init__.pyi new file mode 100644 index 00000000..aacd9177 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/uri_resolution/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .uri_resolution_context import * + diff --git a/packages/polywrap-wasm/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi b/packages/polywrap-wasm/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi new file mode 100644 index 00000000..bd999afc --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi @@ -0,0 +1,41 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Set +from ..types import IUriResolutionContext, IUriResolutionStep, Uri + +class UriResolutionContext(IUriResolutionContext): + resolving_uri_set: Set[Uri] + resolution_path: List[Uri] + history: List[IUriResolutionStep] + __slots__ = ... + def __init__(self, resolving_uri_set: Optional[Set[Uri]] = ..., resolution_path: Optional[List[Uri]] = ..., history: Optional[List[IUriResolutionStep]] = ...) -> None: + ... + + def is_resolving(self, uri: Uri) -> bool: + ... + + def start_resolving(self, uri: Uri) -> None: + ... + + def stop_resolving(self, uri: Uri) -> None: + ... + + def track_step(self, step: IUriResolutionStep) -> None: + ... + + def get_history(self) -> List[IUriResolutionStep]: + ... + + def get_resolution_path(self) -> List[Uri]: + ... + + def create_sub_history_context(self) -> UriResolutionContext: + ... + + def create_sub_context(self) -> UriResolutionContext: + ... + + + diff --git a/packages/polywrap-wasm/typings/polywrap_core/utils/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/utils/__init__.pyi new file mode 100644 index 00000000..b2a379f8 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/utils/__init__.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from .get_env_from_uri_history import * +from .init_wrapper import * +from .instance_of import * +from .maybe_async import * + diff --git a/packages/polywrap-wasm/typings/polywrap_core/utils/get_env_from_uri_history.pyi b/packages/polywrap-wasm/typings/polywrap_core/utils/get_env_from_uri_history.pyi new file mode 100644 index 00000000..b75c0458 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/utils/get_env_from_uri_history.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Dict, List, Union +from ..types import Client, Uri + +def get_env_from_uri_history(uri_history: List[Uri], client: Client) -> Union[Dict[str, Any], None]: + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_core/utils/init_wrapper.pyi b/packages/polywrap-wasm/typings/polywrap_core/utils/init_wrapper.pyi new file mode 100644 index 00000000..87c450a0 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/utils/init_wrapper.pyi @@ -0,0 +1,10 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any +from ..types import Wrapper + +async def init_wrapper(packageOrWrapper: Any) -> Wrapper: + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_core/utils/instance_of.pyi b/packages/polywrap-wasm/typings/polywrap_core/utils/instance_of.pyi new file mode 100644 index 00000000..84ac59e0 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/utils/instance_of.pyi @@ -0,0 +1,9 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any + +def instance_of(obj: Any, cls: Any): # -> bool: + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_core/utils/maybe_async.pyi b/packages/polywrap-wasm/typings/polywrap_core/utils/maybe_async.pyi new file mode 100644 index 00000000..e6e6f0be --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/utils/maybe_async.pyi @@ -0,0 +1,12 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Any, Awaitable, Callable, Optional, Union + +def is_coroutine(test: Optional[Union[Awaitable[Any], Any]] = ...) -> bool: + ... + +async def execute_maybe_async_function(func: Callable[..., Any], *args: Any) -> Any: + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_manifest/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_manifest/__init__.pyi new file mode 100644 index 00000000..fa27423a --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_manifest/__init__.pyi @@ -0,0 +1,7 @@ +""" +This type stub file was generated by pyright. +""" + +from .deserialize import * +from .manifest import * + diff --git a/packages/polywrap-wasm/typings/polywrap_manifest/deserialize.pyi b/packages/polywrap-wasm/typings/polywrap_manifest/deserialize.pyi new file mode 100644 index 00000000..5fd1f32c --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_manifest/deserialize.pyi @@ -0,0 +1,16 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import Optional +from polywrap_result import Result +from .manifest import * + +""" +This file was automatically generated by scripts/templates/deserialize.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/deserialize.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +def deserialize_wrap_manifest(manifest: bytes, options: Optional[DeserializeManifestOptions] = ...) -> Result[AnyWrapManifest]: + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_manifest/manifest.pyi b/packages/polywrap-wasm/typings/polywrap_manifest/manifest.pyi new file mode 100644 index 00000000..b5a88605 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_manifest/manifest.pyi @@ -0,0 +1,44 @@ +""" +This type stub file was generated by pyright. +""" + +from dataclasses import dataclass +from enum import Enum +from .wrap_0_1 import Abi as WrapAbi_0_1_0_1, WrapManifest as WrapManifest_0_1 + +""" +This file was automatically generated by scripts/templates/__init__.py.jinja2. +DO NOT MODIFY IT BY HAND. Instead, modify scripts/templates/__init__.py.jinja2, +and run python ./scripts/generate.py to regenerate this file. +""" +@dataclass(slots=True, kw_only=True) +class DeserializeManifestOptions: + no_validate: Optional[bool] = ... + + +@dataclass(slots=True, kw_only=True) +class serializeManifestOptions: + no_validate: Optional[bool] = ... + + +class WrapManifestVersions(Enum): + VERSION_0_1 = ... + def __new__(cls, value: int, *aliases: str) -> WrapManifestVersions: + ... + + + +class WrapManifestAbiVersions(Enum): + VERSION_0_1 = ... + + +class WrapAbiVersions(Enum): + VERSION_0_1 = ... + + +AnyWrapManifest = WrapManifest_0_1 +AnyWrapAbi = WrapAbi_0_1_0_1 +WrapManifest = ... +WrapAbi = WrapAbi_0_1_0_1 +latest_wrap_manifest_version = ... +latest_wrap_abi_version = ... diff --git a/packages/polywrap-wasm/typings/polywrap_manifest/wrap_0_1.pyi b/packages/polywrap-wasm/typings/polywrap_manifest/wrap_0_1.pyi new file mode 100644 index 00000000..90b68065 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_manifest/wrap_0_1.pyi @@ -0,0 +1,209 @@ +""" +This type stub file was generated by pyright. +""" + +from enum import Enum +from typing import List, Optional +from pydantic import BaseModel + +class Version(Enum): + """ + WRAP Standard Version + """ + VERSION_0_1_0 = ... + VERSION_0_1 = ... + + +class Type(Enum): + """ + Wrapper Package Type + """ + WASM = ... + INTERFACE = ... + PLUGIN = ... + + +class Env(BaseModel): + required: Optional[bool] = ... + + +class GetImplementations(BaseModel): + enabled: bool + ... + + +class CapabilityDefinition(BaseModel): + get_implementations: Optional[GetImplementations] = ... + + +class ImportedDefinition(BaseModel): + uri: str + namespace: str + native_type: str = ... + + +class WithKind(BaseModel): + kind: float + ... + + +class WithComment(BaseModel): + comment: Optional[str] = ... + + +class GenericDefinition(WithKind): + type: str + name: Optional[str] = ... + required: Optional[bool] = ... + + +class ScalarType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + BOOLEAN = ... + BYTES = ... + BIG_INT = ... + BIG_NUMBER = ... + JSON = ... + + +class ScalarDefinition(GenericDefinition): + type: ScalarType + ... + + +class MapKeyType(Enum): + U_INT = ... + U_INT8 = ... + U_INT16 = ... + U_INT32 = ... + INT = ... + INT8 = ... + INT16 = ... + INT32 = ... + STRING = ... + + +class ObjectRef(GenericDefinition): + ... + + +class EnumRef(GenericDefinition): + ... + + +class UnresolvedObjectOrEnumRef(GenericDefinition): + ... + + +class ImportedModuleRef(BaseModel): + type: Optional[str] = ... + + +class InterfaceImplementedDefinition(GenericDefinition): + ... + + +class EnumDefinition(GenericDefinition, WithComment): + constants: Optional[List[str]] = ... + + +class InterfaceDefinition(GenericDefinition, ImportedDefinition): + capabilities: Optional[CapabilityDefinition] = ... + + +class ImportedEnumDefinition(EnumDefinition, ImportedDefinition): + ... + + +class WrapManifest(BaseModel): + class Config: + extra = ... + + + version: Version = ... + type: Type = ... + name: str = ... + abi: Abi = ... + + +class Abi(BaseModel): + version: Optional[str] = ... + object_types: Optional[List[ObjectDefinition]] = ... + module_type: Optional[ModuleDefinition] = ... + enum_types: Optional[List[EnumDefinition]] = ... + interface_types: Optional[List[InterfaceDefinition]] = ... + imported_object_types: Optional[List[ImportedObjectDefinition]] = ... + imported_module_types: Optional[List[ImportedModuleDefinition]] = ... + imported_enum_types: Optional[List[ImportedEnumDefinition]] = ... + imported_env_types: Optional[List[ImportedEnvDefinition]] = ... + env_type: Optional[EnvDefinition] = ... + + +class ObjectDefinition(GenericDefinition, WithComment): + properties: Optional[List[PropertyDefinition]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class ModuleDefinition(GenericDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + imports: Optional[List[ImportedModuleRef]] = ... + interfaces: Optional[List[InterfaceImplementedDefinition]] = ... + + +class MethodDefinition(GenericDefinition, WithComment): + arguments: Optional[List[PropertyDefinition]] = ... + env: Optional[Env] = ... + return_: Optional[PropertyDefinition] = ... + + +class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): + methods: Optional[List[MethodDefinition]] = ... + is_interface: Optional[bool] = ... + + +class AnyDefinition(GenericDefinition): + array: Optional[ArrayDefinition] = ... + scalar: Optional[ScalarDefinition] = ... + map: Optional[MapDefinition] = ... + object: Optional[ObjectRef] = ... + enum: Optional[EnumRef] = ... + unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = ... + + +class EnvDefinition(ObjectDefinition): + ... + + +class ImportedObjectDefinition(ObjectDefinition, ImportedDefinition, WithComment): + ... + + +class PropertyDefinition(WithComment, AnyDefinition): + ... + + +class ArrayDefinition(AnyDefinition): + item: Optional[GenericDefinition] = ... + + +class MapKeyDefinition(AnyDefinition): + type: Optional[MapKeyType] = ... + + +class MapDefinition(AnyDefinition, WithComment): + key: Optional[MapKeyDefinition] = ... + value: Optional[GenericDefinition] = ... + + +class ImportedEnvDefinition(ImportedObjectDefinition): + ... + + diff --git a/packages/polywrap-wasm/typings/polywrap_msgpack/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_msgpack/__init__.pyi new file mode 100644 index 00000000..205bd701 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_msgpack/__init__.pyi @@ -0,0 +1,74 @@ +""" +This type stub file was generated by pyright. +""" + +import msgpack +from enum import Enum +from typing import Any, Dict, List, Set +from msgpack.exceptions import UnpackValueError + +""" +polywrap-msgpack adds ability to encode/decode to/from msgpack format. + +It provides msgpack_encode and msgpack_decode functions +which allows user to encode and decode to/from msgpack bytes + +It also defines the default Extension types and extension hook for +custom extension types defined by wrap standard +""" +class ExtensionTypes(Enum): + """Wrap msgpack extension types.""" + GENERIC_MAP = ... + + +def ext_hook(code: int, data: bytes) -> Any: + """Extension hook for extending the msgpack supported types. + + Args: + code (int): extension type code (>0 & <256) + data (bytes): msgpack deserializable data as payload + + Raises: + UnpackValueError: when given invalid extension type code + + Returns: + Any: decoded object + """ + ... + +def sanitize(value: Any) -> Any: + """Sanitizes the value into msgpack encoder compatible format. + + Args: + value: any valid python value + + Raises: + ValueError: when dict key isn't string + + Returns: + Any: msgpack compatible sanitized value + """ + ... + +def msgpack_encode(value: Any) -> bytes: + """Encode any python object into msgpack bytes. + + Args: + value: any valid python object + + Returns: + bytes: encoded msgpack value + """ + ... + +def msgpack_decode(val: bytes) -> Any: + """Decode msgpack bytes into a valid python object. + + Args: + val: msgpack encoded bytes + + Returns: + Any: python object + """ + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_result/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_result/__init__.pyi new file mode 100644 index 00000000..d704a49f --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_result/__init__.pyi @@ -0,0 +1,322 @@ +""" +This type stub file was generated by pyright. +""" + +import inspect +import sys +import types +from __future__ import annotations +from typing import Any, Callable, Generic, NoReturn, ParamSpec, TypeVar, Union, cast, overload +from typing_extensions import ParamSpec + +""" +A simple Rust like Result type for Python 3. + +This project has been forked from the https://github.com/rustedpy/result. +""" +if sys.version_info[: 2] >= (3, 10): + ... +else: + ... +T = TypeVar("T", covariant=True) +U = TypeVar("U") +F = TypeVar("F") +P = ... +R = TypeVar("R") +TBE = TypeVar("TBE", bound=BaseException) +class Ok(Generic[T]): + """ + A value that indicates success and which stores arbitrary data for the return value. + """ + _value: T + __match_args__ = ... + __slots__ = ... + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, value: T) -> None: + ... + + def __init__(self, value: Any = ...) -> None: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> T: + """ + Return the value. + """ + ... + + def err(self) -> None: + """ + Return `None`. + """ + ... + + @property + def value(self) -> T: + """ + Return the inner value. + """ + ... + + def expect(self, _message: str) -> T: + """ + Return the value. + """ + ... + + def expect_err(self, message: str) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap(self) -> T: + """ + Return the value. + """ + ... + + def unwrap_err(self) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap_or(self, _default: U) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_raise(self) -> T: + """ + Return the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + The contained result is `Ok`, so return `Ok` with original value mapped to + a new value using the passed in function. + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return the original value mapped to a new + value using the passed in function. + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return original value mapped to + a new value using the passed in `op` function. + """ + ... + + def map_err(self, op: Callable[[Exception], F]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Ok`, so return the result of `op` with the + original value passed in + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + + +class Err: + """ + A value that signifies failure and which stores arbitrary data for the error. + """ + __match_args__ = ... + __slots__ = ... + def __init__(self, value: Exception) -> None: + ... + + @classmethod + def from_str(cls, value: str) -> Err: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> None: + """ + Return `None`. + """ + ... + + def err(self) -> Exception: + """ + Return the error. + """ + ... + + @property + def value(self) -> Exception: + """ + Return the inner value. + """ + ... + + def expect(self, message: str) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def expect_err(self, _message: str) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap(self) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def unwrap_err(self) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap_or(self, default: U) -> U: + """ + Return `default`. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + The contained result is ``Err``, so return the result of applying + ``op`` to the error value. + """ + ... + + def unwrap_or_raise(self) -> NoReturn: + """ + The contained result is ``Err``, so raise the exception with the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + Return `Err` with the same value + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + Return the default value + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + Return the result of the default operation + """ + ... + + def map_err(self, op: Callable[[Exception], Exception]) -> Result[T]: + """ + The contained result is `Err`, so return `Err` with original error mapped to + a new value using the passed in function. + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Err`, so return `Err` with the original value + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Err`, so return the result of `op` with the + original value passed in + """ + ... + + + +Result = Union[Ok[T], Err] +class UnwrapError(Exception): + """ + Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + + The original ``Result`` can be accessed via the ``.result`` attribute, but + this is not intended for regular use, as type information is lost: + ``UnwrapError`` doesn't know about both ``T`` and ``E``, since it's raised + from ``Ok()`` or ``Err()`` which only knows about either ``T`` or ``E``, + not both. + """ + _result: Result[Any] + def __init__(self, result: Result[Any], message: str) -> None: + ... + + @property + def result(self) -> Result[Any]: + """ + Returns the original result. + """ + ... + + + From 008f2c864ea1b96ff8a76071c5982ea9be31bd7a Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Fri, 9 Dec 2022 18:14:40 +0400 Subject: [PATCH 4/8] fix: issues --- .../polywrap-client/tests/test_bignumber.py | 54 ++++++------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/packages/polywrap-client/tests/test_bignumber.py b/packages/polywrap-client/tests/test_bignumber.py index 2f8d30ae..cbb85604 100644 --- a/packages/polywrap-client/tests/test_bignumber.py +++ b/packages/polywrap-client/tests/test_bignumber.py @@ -5,72 +5,52 @@ from polywrap_client import PolywrapClient from polywrap_core import Uri, InvokerOptions + async def test_invoke_bignumber_1arg_and_1prop(): client = PolywrapClient() uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') - args = { "arg1": "123", # The base number + args = { + "arg1": "123", # The base number "obj": { - "prop1": "1000", # multiply the base number by this factor - } + "prop1": "1000", # multiply the base number by this factor + }, } options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False) result = await client.invoke(options) assert result.unwrap() == "123000" + async def test_invoke_bignumber_with_1arg_and_2props(): client = PolywrapClient() uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') - args = { - "arg1": "123123", - "obj": { - "prop1": "1000", - "prop2": "4" - } - } + args = {"arg1": "123123", "obj": {"prop1": "1000", "prop2": "4"}} options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False) result = await client.invoke(options) - assert result.unwrap() == str(123123*1000*4) + assert result.unwrap() == str(123123 * 1000 * 4) + async def test_invoke_bignumber_with_2args_and_1prop(): client = PolywrapClient() uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') - args = { - "arg1": "123123", - "obj": { - "prop1": "1000", - "prop2": "444" - } - } + args = {"arg1": "123123", "obj": {"prop1": "1000", "prop2": "444"}} options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False) result = await client.invoke(options) - assert result.unwrap() == str(123123*1000*444) + assert result.unwrap() == str(123123 * 1000 * 444) + async def test_invoke_bignumber_with_2args_and_2props(): client = PolywrapClient() uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') - args = { - "arg1": "123123", - "arg2": "555", - "obj": { - "prop1": "1000", - "prop2": "4" - } - } + args = {"arg1": "123123", "arg2": "555", "obj": {"prop1": "1000", "prop2": "4"}} options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False) result = await client.invoke(options) - assert result.unwrap() == str(123123*555*1000*4) + assert result.unwrap() == str(123123 * 555 * 1000 * 4) + async def test_invoke_bignumber_with_2args_and_2props_floats(): client = PolywrapClient() uri = Uri(f'fs/{Path(__file__).parent.joinpath("cases", "big-number").absolute()}') - args = { - "arg1": "123.123", - "arg2": "55.5", - "obj": { - "prop1": "10.001", - "prop2": "4" - } - } + args = {"arg1": "123.123", "arg2": "55.5", "obj": {"prop1": "10.001", "prop2": "4"}} options = InvokerOptions(uri=uri, method="method", args=args, encode_result=False) result = await client.invoke(options) - assert result.unwrap() == str(123.123*55.5*10.001*4) \ No newline at end of file + assert result.unwrap() == str(123.123 * 55.5 * 10.001 * 4) From 04ec85f587c47b118070bdf9de62199358565d32 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Sat, 10 Dec 2022 10:47:02 +0400 Subject: [PATCH 5/8] fix: typechecks --- .../polywrap_manifest/deserialize.py | 15 +- .../polywrap_manifest/manifest.py | 4 +- .../polywrap_manifest/wrap_0_1.py | 100 +++--- .../polywrap-manifest/scripts/generate.py | 28 ++ packages/polywrap-manifest/tox.ini | 4 + .../typings/polywrap_msgpack/__init__.pyi | 74 ++++ .../typings/polywrap_result/__init__.pyi | 322 ++++++++++++++++++ 7 files changed, 486 insertions(+), 61 deletions(-) create mode 100644 packages/polywrap-manifest/typings/polywrap_msgpack/__init__.pyi create mode 100644 packages/polywrap-manifest/typings/polywrap_result/__init__.pyi diff --git a/packages/polywrap-manifest/polywrap_manifest/deserialize.py b/packages/polywrap-manifest/polywrap_manifest/deserialize.py index d7454efa..70604cef 100644 --- a/packages/polywrap-manifest/polywrap_manifest/deserialize.py +++ b/packages/polywrap-manifest/polywrap_manifest/deserialize.py @@ -7,7 +7,7 @@ from typing import Optional from polywrap_msgpack import msgpack_decode -from polywrap_result import Err, Ok, Result +from polywrap_result import Ok, Err, Result from pydantic import ValidationError from .manifest import * @@ -28,19 +28,16 @@ def _deserialize_wrap_manifest( decoded_manifest = msgpack_decode(manifest) if not decoded_manifest.get("version"): raise ValueError("Expected manifest version to be defined!") - + no_validate = options and options.no_validate manifest_version = WrapManifestVersions(decoded_manifest["version"]) match manifest_version.value: case "0.1": if no_validate: - from .manifest import Version, WrapAbi_0_1_0_1 - + from .manifest import WrapAbi_0_1_0_1, Version decoded_manifest["version"] = Version(decoded_manifest["version"]) - decoded_manifest["abi"] = WrapAbi_0_1_0_1.construct( - **decoded_manifest["abi"] - ) - WrapManifest_0_1.construct(**decoded_manifest) + decoded_manifest["abi"] = WrapAbi_0_1_0_1.construct(**decoded_manifest["abi"]) + WrapManifest_0_1.construct(**decoded_manifest) return WrapManifest_0_1(**decoded_manifest) case _: - raise ValueError(f"Invalid wrap manifest version: {manifest_version}") + raise ValueError(f"Invalid wrap manifest version: {manifest_version}") \ No newline at end of file diff --git a/packages/polywrap-manifest/polywrap_manifest/manifest.py b/packages/polywrap-manifest/polywrap_manifest/manifest.py index fbb04376..82bc28a4 100644 --- a/packages/polywrap-manifest/polywrap_manifest/manifest.py +++ b/packages/polywrap-manifest/polywrap_manifest/manifest.py @@ -7,8 +7,8 @@ from dataclasses import dataclass from enum import Enum -from .wrap_0_1 import Abi as WrapAbi_0_1_0_1 from .wrap_0_1 import WrapManifest as WrapManifest_0_1 +from .wrap_0_1 import Abi as WrapAbi_0_1_0_1 from .wrap_0_1 import * @@ -49,4 +49,4 @@ class WrapAbiVersions(Enum): WrapAbi = WrapAbi_0_1_0_1 latest_wrap_manifest_version = "0.1" -latest_wrap_abi_version = "0.1" +latest_wrap_abi_version = "0.1" \ No newline at end of file diff --git a/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py b/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py index 0bd619d2..bd508fb0 100644 --- a/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py +++ b/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py @@ -1,11 +1,11 @@ # generated by datamodel-codegen: # filename: https://raw.githubusercontent.com/polywrap/wrap/master/manifest/wrap.info/0.1.json -# timestamp: 2022-10-27T09:34:19+00:00 +# timestamp: 2022-12-10T06:45:37+00:00 from __future__ import annotations from enum import Enum -from typing import List, Optional +from typing import Union, List, Optional from pydantic import BaseModel, Extra, Field @@ -15,8 +15,8 @@ class Version(Enum): WRAP Standard Version """ - VERSION_0_1_0 = "0.1.0" - VERSION_0_1 = "0.1" + VERSION_0_1_0 = '0.1.0' + VERSION_0_1 = '0.1' class Type(Enum): @@ -24,9 +24,9 @@ class Type(Enum): Wrapper Package Type """ - WASM = "wasm" - INTERFACE = "interface" - PLUGIN = "plugin" + WASM = 'wasm' + INTERFACE = 'interface' + PLUGIN = 'plugin' class Env(BaseModel): @@ -39,14 +39,14 @@ class GetImplementations(BaseModel): class CapabilityDefinition(BaseModel): get_implementations: Optional[GetImplementations] = Field( - None, alias="getImplementations" + None, alias='getImplementations' ) class ImportedDefinition(BaseModel): uri: str namespace: str - native_type: str = Field(..., alias="nativeType") + native_type: str = Field(..., alias='nativeType') class WithKind(BaseModel): @@ -58,26 +58,26 @@ class WithComment(BaseModel): class GenericDefinition(WithKind): - type: str + type: Union[str, Enum, None] name: Optional[str] = None required: Optional[bool] = None class ScalarType(Enum): - U_INT = "UInt" - U_INT8 = "UInt8" - U_INT16 = "UInt16" - U_INT32 = "UInt32" - INT = "Int" - INT8 = "Int8" - INT16 = "Int16" - INT32 = "Int32" - STRING = "String" - BOOLEAN = "Boolean" - BYTES = "Bytes" - BIG_INT = "BigInt" - BIG_NUMBER = "BigNumber" - JSON = "JSON" + U_INT = 'UInt' + U_INT8 = 'UInt8' + U_INT16 = 'UInt16' + U_INT32 = 'UInt32' + INT = 'Int' + INT8 = 'Int8' + INT16 = 'Int16' + INT32 = 'Int32' + STRING = 'String' + BOOLEAN = 'Boolean' + BYTES = 'Bytes' + BIG_INT = 'BigInt' + BIG_NUMBER = 'BigNumber' + JSON = 'JSON' class ScalarDefinition(GenericDefinition): @@ -85,15 +85,15 @@ class ScalarDefinition(GenericDefinition): class MapKeyType(Enum): - U_INT = "UInt" - U_INT8 = "UInt8" - U_INT16 = "UInt16" - U_INT32 = "UInt32" - INT = "Int" - INT8 = "Int8" - INT16 = "Int16" - INT32 = "Int32" - STRING = "String" + U_INT = 'UInt' + U_INT8 = 'UInt8' + U_INT16 = 'UInt16' + U_INT32 = 'UInt32' + INT = 'Int' + INT8 = 'Int8' + INT16 = 'Int16' + INT32 = 'Int32' + STRING = 'String' class ObjectRef(GenericDefinition): @@ -132,33 +132,33 @@ class WrapManifest(BaseModel): class Config: extra = Extra.forbid - version: Version = Field(..., description="WRAP Standard Version") - type: Type = Field(..., description="Wrapper Package Type") - name: str = Field(..., description="Wrapper Name", regex="^[a-zA-Z0-9\\-\\_]+$") - abi: Abi = Field(..., description="Information of modules") + version: Version = Field(..., description='WRAP Standard Version') + type: Type = Field(..., description='Wrapper Package Type') + name: str = Field(..., description='Wrapper Name', regex='^[a-zA-Z0-9\\-\\_]+$') + abi: Abi = Field(..., description='Information of modules') class Abi(BaseModel): - version: Optional[str] = Field(None, description="ABI Version") - object_types: Optional[List[ObjectDefinition]] = Field(None, alias="objectTypes") - module_type: Optional[ModuleDefinition] = Field(None, alias="moduleType") - enum_types: Optional[List[EnumDefinition]] = Field(None, alias="enumTypes") + version: Optional[str] = Field(None, description='ABI Version') + object_types: Optional[List[ObjectDefinition]] = Field(None, alias='objectTypes') + module_type: Optional[ModuleDefinition] = Field(None, alias='moduleType') + enum_types: Optional[List[EnumDefinition]] = Field(None, alias='enumTypes') interface_types: Optional[List[InterfaceDefinition]] = Field( - None, alias="interfaceTypes" + None, alias='interfaceTypes' ) imported_object_types: Optional[List[ImportedObjectDefinition]] = Field( - None, alias="importedObjectTypes" + None, alias='importedObjectTypes' ) imported_module_types: Optional[List[ImportedModuleDefinition]] = Field( - None, alias="importedModuleTypes" + None, alias='importedModuleTypes' ) imported_enum_types: Optional[List[ImportedEnumDefinition]] = Field( - None, alias="importedEnumTypes" + None, alias='importedEnumTypes' ) imported_env_types: Optional[List[ImportedEnvDefinition]] = Field( - None, alias="importedEnvTypes" + None, alias='importedEnvTypes' ) - env_type: Optional[EnvDefinition] = Field(None, alias="envType") + env_type: Optional[EnvDefinition] = Field(None, alias='envType') class ObjectDefinition(GenericDefinition, WithComment): @@ -175,12 +175,12 @@ class ModuleDefinition(GenericDefinition, WithComment): class MethodDefinition(GenericDefinition, WithComment): arguments: Optional[List[PropertyDefinition]] = None env: Optional[Env] = None - return_: Optional[PropertyDefinition] = Field(None, alias="return") + return_: Optional[PropertyDefinition] = Field(None, alias='return') class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): methods: Optional[List[MethodDefinition]] = None - is_interface: Optional[bool] = Field(None, alias="isInterface") + is_interface: Optional[bool] = Field(None, alias='isInterface') class AnyDefinition(GenericDefinition): @@ -190,7 +190,7 @@ class AnyDefinition(GenericDefinition): object: Optional[ObjectRef] = None enum: Optional[EnumRef] = None unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = Field( - None, alias="unresolvedObjectOrEnum" + None, alias='unresolvedObjectOrEnum' ) diff --git a/packages/polywrap-manifest/scripts/generate.py b/packages/polywrap-manifest/scripts/generate.py index 6e6e7d2b..0456cd60 100644 --- a/packages/polywrap-manifest/scripts/generate.py +++ b/packages/polywrap-manifest/scripts/generate.py @@ -1,3 +1,5 @@ +import re + from dataclasses import dataclass from pathlib import Path from typing import List, Set @@ -50,6 +52,30 @@ def render_deserialize(versions: List[ManifestVersion]) -> None: f.write(rendered) +def render_wrap(path: Path) -> None: + with path.open("r+") as f: + content = f.read() + + # Import Union from typing + content = content.replace("from typing import ", "from typing import Union, ") + + generic_def_pattern = re.compile(r"class GenericDefinition\(WithKind\):\s*type: str") + generic_def_match = generic_def_pattern.search(content) + + if not generic_def_match: + raise ValueError("Could not find GenericDefinition class in wrap.py") + + generic_def_span = generic_def_match.span() + + generic_def = content[generic_def_span[0]:generic_def_span[1]] + + updated_generic_def = generic_def.replace("str", "Union[str, Enum, None]") + content = content.replace(generic_def, updated_generic_def) + + f.seek(0) + f.write(content) + + def main(): res = requests.get( "https://raw.githubusercontent.com/polywrap/wrap/master/manifest/wrap.info/versions.json" @@ -98,6 +124,8 @@ def main(): use_schema_description=True, output=output, ) + + render_wrap(output) latest_version: ManifestVersion = versions[-1] diff --git a/packages/polywrap-manifest/tox.ini b/packages/polywrap-manifest/tox.ini index c680b728..ebf60873 100644 --- a/packages/polywrap-manifest/tox.ini +++ b/packages/polywrap-manifest/tox.ini @@ -6,6 +6,10 @@ envlist = py310 commands = pytest tests/ +[testenv:codegen] +commands = + python scripts/generate.py + [testenv:lint] commands = isort --check-only polywrap_manifest diff --git a/packages/polywrap-manifest/typings/polywrap_msgpack/__init__.pyi b/packages/polywrap-manifest/typings/polywrap_msgpack/__init__.pyi new file mode 100644 index 00000000..205bd701 --- /dev/null +++ b/packages/polywrap-manifest/typings/polywrap_msgpack/__init__.pyi @@ -0,0 +1,74 @@ +""" +This type stub file was generated by pyright. +""" + +import msgpack +from enum import Enum +from typing import Any, Dict, List, Set +from msgpack.exceptions import UnpackValueError + +""" +polywrap-msgpack adds ability to encode/decode to/from msgpack format. + +It provides msgpack_encode and msgpack_decode functions +which allows user to encode and decode to/from msgpack bytes + +It also defines the default Extension types and extension hook for +custom extension types defined by wrap standard +""" +class ExtensionTypes(Enum): + """Wrap msgpack extension types.""" + GENERIC_MAP = ... + + +def ext_hook(code: int, data: bytes) -> Any: + """Extension hook for extending the msgpack supported types. + + Args: + code (int): extension type code (>0 & <256) + data (bytes): msgpack deserializable data as payload + + Raises: + UnpackValueError: when given invalid extension type code + + Returns: + Any: decoded object + """ + ... + +def sanitize(value: Any) -> Any: + """Sanitizes the value into msgpack encoder compatible format. + + Args: + value: any valid python value + + Raises: + ValueError: when dict key isn't string + + Returns: + Any: msgpack compatible sanitized value + """ + ... + +def msgpack_encode(value: Any) -> bytes: + """Encode any python object into msgpack bytes. + + Args: + value: any valid python object + + Returns: + bytes: encoded msgpack value + """ + ... + +def msgpack_decode(val: bytes) -> Any: + """Decode msgpack bytes into a valid python object. + + Args: + val: msgpack encoded bytes + + Returns: + Any: python object + """ + ... + diff --git a/packages/polywrap-manifest/typings/polywrap_result/__init__.pyi b/packages/polywrap-manifest/typings/polywrap_result/__init__.pyi new file mode 100644 index 00000000..d704a49f --- /dev/null +++ b/packages/polywrap-manifest/typings/polywrap_result/__init__.pyi @@ -0,0 +1,322 @@ +""" +This type stub file was generated by pyright. +""" + +import inspect +import sys +import types +from __future__ import annotations +from typing import Any, Callable, Generic, NoReturn, ParamSpec, TypeVar, Union, cast, overload +from typing_extensions import ParamSpec + +""" +A simple Rust like Result type for Python 3. + +This project has been forked from the https://github.com/rustedpy/result. +""" +if sys.version_info[: 2] >= (3, 10): + ... +else: + ... +T = TypeVar("T", covariant=True) +U = TypeVar("U") +F = TypeVar("F") +P = ... +R = TypeVar("R") +TBE = TypeVar("TBE", bound=BaseException) +class Ok(Generic[T]): + """ + A value that indicates success and which stores arbitrary data for the return value. + """ + _value: T + __match_args__ = ... + __slots__ = ... + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, value: T) -> None: + ... + + def __init__(self, value: Any = ...) -> None: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> T: + """ + Return the value. + """ + ... + + def err(self) -> None: + """ + Return `None`. + """ + ... + + @property + def value(self) -> T: + """ + Return the inner value. + """ + ... + + def expect(self, _message: str) -> T: + """ + Return the value. + """ + ... + + def expect_err(self, message: str) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap(self) -> T: + """ + Return the value. + """ + ... + + def unwrap_err(self) -> NoReturn: + """ + Raise an UnwrapError since this type is `Ok` + """ + ... + + def unwrap_or(self, _default: U) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + Return the value. + """ + ... + + def unwrap_or_raise(self) -> T: + """ + Return the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + The contained result is `Ok`, so return `Ok` with original value mapped to + a new value using the passed in function. + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return the original value mapped to a new + value using the passed in function. + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + The contained result is `Ok`, so return original value mapped to + a new value using the passed in `op` function. + """ + ... + + def map_err(self, op: Callable[[Exception], F]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Ok`, so return the result of `op` with the + original value passed in + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Ok`, so return `Ok` with the original value + """ + ... + + + +class Err: + """ + A value that signifies failure and which stores arbitrary data for the error. + """ + __match_args__ = ... + __slots__ = ... + def __init__(self, value: Exception) -> None: + ... + + @classmethod + def from_str(cls, value: str) -> Err: + ... + + def __repr__(self) -> str: + ... + + def __eq__(self, other: Any) -> bool: + ... + + def __ne__(self, other: Any) -> bool: + ... + + def __hash__(self) -> int: + ... + + def is_ok(self) -> bool: + ... + + def is_err(self) -> bool: + ... + + def ok(self) -> None: + """ + Return `None`. + """ + ... + + def err(self) -> Exception: + """ + Return the error. + """ + ... + + @property + def value(self) -> Exception: + """ + Return the inner value. + """ + ... + + def expect(self, message: str) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def expect_err(self, _message: str) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap(self) -> NoReturn: + """ + Raises an `UnwrapError`. + """ + ... + + def unwrap_err(self) -> Exception: + """ + Return the inner value + """ + ... + + def unwrap_or(self, default: U) -> U: + """ + Return `default`. + """ + ... + + def unwrap_or_else(self, op: Callable[[Exception], T]) -> T: + """ + The contained result is ``Err``, so return the result of applying + ``op`` to the error value. + """ + ... + + def unwrap_or_raise(self) -> NoReturn: + """ + The contained result is ``Err``, so raise the exception with the value. + """ + ... + + def map(self, op: Callable[[T], U]) -> Result[U]: + """ + Return `Err` with the same value + """ + ... + + def map_or(self, default: U, op: Callable[[T], U]) -> U: + """ + Return the default value + """ + ... + + def map_or_else(self, default_op: Callable[[], U], op: Callable[[T], U]) -> U: + """ + Return the result of the default operation + """ + ... + + def map_err(self, op: Callable[[Exception], Exception]) -> Result[T]: + """ + The contained result is `Err`, so return `Err` with original error mapped to + a new value using the passed in function. + """ + ... + + def and_then(self, op: Callable[[T], Result[U]]) -> Result[U]: + """ + The contained result is `Err`, so return `Err` with the original value + """ + ... + + def or_else(self, op: Callable[[Exception], Result[T]]) -> Result[T]: + """ + The contained result is `Err`, so return the result of `op` with the + original value passed in + """ + ... + + + +Result = Union[Ok[T], Err] +class UnwrapError(Exception): + """ + Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + + The original ``Result`` can be accessed via the ``.result`` attribute, but + this is not intended for regular use, as type information is lost: + ``UnwrapError`` doesn't know about both ``T`` and ``E``, since it's raised + from ``Ok()`` or ``Err()`` which only knows about either ``T`` or ``E``, + not both. + """ + _result: Result[Any] + def __init__(self, result: Result[Any], message: str) -> None: + ... + + @property + def result(self) -> Result[Any]: + """ + Returns the original result. + """ + ... + + + From 0c17e9b5e10dcb3f0f2b6109a362a4ae051f3eee Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Sat, 10 Dec 2022 10:47:46 +0400 Subject: [PATCH 6/8] fix: lintings --- .../polywrap_manifest/deserialize.py | 15 +-- .../polywrap_manifest/manifest.py | 4 +- .../polywrap_manifest/wrap_0_1.py | 96 +++++++++---------- 3 files changed, 59 insertions(+), 56 deletions(-) diff --git a/packages/polywrap-manifest/polywrap_manifest/deserialize.py b/packages/polywrap-manifest/polywrap_manifest/deserialize.py index 70604cef..d7454efa 100644 --- a/packages/polywrap-manifest/polywrap_manifest/deserialize.py +++ b/packages/polywrap-manifest/polywrap_manifest/deserialize.py @@ -7,7 +7,7 @@ from typing import Optional from polywrap_msgpack import msgpack_decode -from polywrap_result import Ok, Err, Result +from polywrap_result import Err, Ok, Result from pydantic import ValidationError from .manifest import * @@ -28,16 +28,19 @@ def _deserialize_wrap_manifest( decoded_manifest = msgpack_decode(manifest) if not decoded_manifest.get("version"): raise ValueError("Expected manifest version to be defined!") - + no_validate = options and options.no_validate manifest_version = WrapManifestVersions(decoded_manifest["version"]) match manifest_version.value: case "0.1": if no_validate: - from .manifest import WrapAbi_0_1_0_1, Version + from .manifest import Version, WrapAbi_0_1_0_1 + decoded_manifest["version"] = Version(decoded_manifest["version"]) - decoded_manifest["abi"] = WrapAbi_0_1_0_1.construct(**decoded_manifest["abi"]) - WrapManifest_0_1.construct(**decoded_manifest) + decoded_manifest["abi"] = WrapAbi_0_1_0_1.construct( + **decoded_manifest["abi"] + ) + WrapManifest_0_1.construct(**decoded_manifest) return WrapManifest_0_1(**decoded_manifest) case _: - raise ValueError(f"Invalid wrap manifest version: {manifest_version}") \ No newline at end of file + raise ValueError(f"Invalid wrap manifest version: {manifest_version}") diff --git a/packages/polywrap-manifest/polywrap_manifest/manifest.py b/packages/polywrap-manifest/polywrap_manifest/manifest.py index 82bc28a4..fbb04376 100644 --- a/packages/polywrap-manifest/polywrap_manifest/manifest.py +++ b/packages/polywrap-manifest/polywrap_manifest/manifest.py @@ -7,8 +7,8 @@ from dataclasses import dataclass from enum import Enum -from .wrap_0_1 import WrapManifest as WrapManifest_0_1 from .wrap_0_1 import Abi as WrapAbi_0_1_0_1 +from .wrap_0_1 import WrapManifest as WrapManifest_0_1 from .wrap_0_1 import * @@ -49,4 +49,4 @@ class WrapAbiVersions(Enum): WrapAbi = WrapAbi_0_1_0_1 latest_wrap_manifest_version = "0.1" -latest_wrap_abi_version = "0.1" \ No newline at end of file +latest_wrap_abi_version = "0.1" diff --git a/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py b/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py index bd508fb0..98ea60fa 100644 --- a/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py +++ b/packages/polywrap-manifest/polywrap_manifest/wrap_0_1.py @@ -5,7 +5,7 @@ from __future__ import annotations from enum import Enum -from typing import Union, List, Optional +from typing import List, Optional, Union from pydantic import BaseModel, Extra, Field @@ -15,8 +15,8 @@ class Version(Enum): WRAP Standard Version """ - VERSION_0_1_0 = '0.1.0' - VERSION_0_1 = '0.1' + VERSION_0_1_0 = "0.1.0" + VERSION_0_1 = "0.1" class Type(Enum): @@ -24,9 +24,9 @@ class Type(Enum): Wrapper Package Type """ - WASM = 'wasm' - INTERFACE = 'interface' - PLUGIN = 'plugin' + WASM = "wasm" + INTERFACE = "interface" + PLUGIN = "plugin" class Env(BaseModel): @@ -39,14 +39,14 @@ class GetImplementations(BaseModel): class CapabilityDefinition(BaseModel): get_implementations: Optional[GetImplementations] = Field( - None, alias='getImplementations' + None, alias="getImplementations" ) class ImportedDefinition(BaseModel): uri: str namespace: str - native_type: str = Field(..., alias='nativeType') + native_type: str = Field(..., alias="nativeType") class WithKind(BaseModel): @@ -64,20 +64,20 @@ class GenericDefinition(WithKind): class ScalarType(Enum): - U_INT = 'UInt' - U_INT8 = 'UInt8' - U_INT16 = 'UInt16' - U_INT32 = 'UInt32' - INT = 'Int' - INT8 = 'Int8' - INT16 = 'Int16' - INT32 = 'Int32' - STRING = 'String' - BOOLEAN = 'Boolean' - BYTES = 'Bytes' - BIG_INT = 'BigInt' - BIG_NUMBER = 'BigNumber' - JSON = 'JSON' + U_INT = "UInt" + U_INT8 = "UInt8" + U_INT16 = "UInt16" + U_INT32 = "UInt32" + INT = "Int" + INT8 = "Int8" + INT16 = "Int16" + INT32 = "Int32" + STRING = "String" + BOOLEAN = "Boolean" + BYTES = "Bytes" + BIG_INT = "BigInt" + BIG_NUMBER = "BigNumber" + JSON = "JSON" class ScalarDefinition(GenericDefinition): @@ -85,15 +85,15 @@ class ScalarDefinition(GenericDefinition): class MapKeyType(Enum): - U_INT = 'UInt' - U_INT8 = 'UInt8' - U_INT16 = 'UInt16' - U_INT32 = 'UInt32' - INT = 'Int' - INT8 = 'Int8' - INT16 = 'Int16' - INT32 = 'Int32' - STRING = 'String' + U_INT = "UInt" + U_INT8 = "UInt8" + U_INT16 = "UInt16" + U_INT32 = "UInt32" + INT = "Int" + INT8 = "Int8" + INT16 = "Int16" + INT32 = "Int32" + STRING = "String" class ObjectRef(GenericDefinition): @@ -132,33 +132,33 @@ class WrapManifest(BaseModel): class Config: extra = Extra.forbid - version: Version = Field(..., description='WRAP Standard Version') - type: Type = Field(..., description='Wrapper Package Type') - name: str = Field(..., description='Wrapper Name', regex='^[a-zA-Z0-9\\-\\_]+$') - abi: Abi = Field(..., description='Information of modules') + version: Version = Field(..., description="WRAP Standard Version") + type: Type = Field(..., description="Wrapper Package Type") + name: str = Field(..., description="Wrapper Name", regex="^[a-zA-Z0-9\\-\\_]+$") + abi: Abi = Field(..., description="Information of modules") class Abi(BaseModel): - version: Optional[str] = Field(None, description='ABI Version') - object_types: Optional[List[ObjectDefinition]] = Field(None, alias='objectTypes') - module_type: Optional[ModuleDefinition] = Field(None, alias='moduleType') - enum_types: Optional[List[EnumDefinition]] = Field(None, alias='enumTypes') + version: Optional[str] = Field(None, description="ABI Version") + object_types: Optional[List[ObjectDefinition]] = Field(None, alias="objectTypes") + module_type: Optional[ModuleDefinition] = Field(None, alias="moduleType") + enum_types: Optional[List[EnumDefinition]] = Field(None, alias="enumTypes") interface_types: Optional[List[InterfaceDefinition]] = Field( - None, alias='interfaceTypes' + None, alias="interfaceTypes" ) imported_object_types: Optional[List[ImportedObjectDefinition]] = Field( - None, alias='importedObjectTypes' + None, alias="importedObjectTypes" ) imported_module_types: Optional[List[ImportedModuleDefinition]] = Field( - None, alias='importedModuleTypes' + None, alias="importedModuleTypes" ) imported_enum_types: Optional[List[ImportedEnumDefinition]] = Field( - None, alias='importedEnumTypes' + None, alias="importedEnumTypes" ) imported_env_types: Optional[List[ImportedEnvDefinition]] = Field( - None, alias='importedEnvTypes' + None, alias="importedEnvTypes" ) - env_type: Optional[EnvDefinition] = Field(None, alias='envType') + env_type: Optional[EnvDefinition] = Field(None, alias="envType") class ObjectDefinition(GenericDefinition, WithComment): @@ -175,12 +175,12 @@ class ModuleDefinition(GenericDefinition, WithComment): class MethodDefinition(GenericDefinition, WithComment): arguments: Optional[List[PropertyDefinition]] = None env: Optional[Env] = None - return_: Optional[PropertyDefinition] = Field(None, alias='return') + return_: Optional[PropertyDefinition] = Field(None, alias="return") class ImportedModuleDefinition(GenericDefinition, ImportedDefinition, WithComment): methods: Optional[List[MethodDefinition]] = None - is_interface: Optional[bool] = Field(None, alias='isInterface') + is_interface: Optional[bool] = Field(None, alias="isInterface") class AnyDefinition(GenericDefinition): @@ -190,7 +190,7 @@ class AnyDefinition(GenericDefinition): object: Optional[ObjectRef] = None enum: Optional[EnumRef] = None unresolved_object_or_enum: Optional[UnresolvedObjectOrEnumRef] = Field( - None, alias='unresolvedObjectOrEnum' + None, alias="unresolvedObjectOrEnum" ) From ed032aca65c0cff3107ef5433c7cffc6ef54a1c1 Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Sat, 10 Dec 2022 12:32:11 +0400 Subject: [PATCH 7/8] feat: add build_clean_uri_history --- .../polywrap-client/polywrap_client/client.py | 10 +-- .../uri_resolution/uri_resolution_context.pyi | 4 +- .../typings/polywrap_core/utils/__init__.pyi | 1 + .../utils/build_clean_uri_history.pyi | 16 ++++ .../polywrap_core/utils/instance_of.pyi | 2 +- .../polywrap_core/utils/__init__.py | 1 + .../utils/build_clean_uri_history.py | 74 +++++++++++++++++++ .../helpers/__init__.py | 2 + 8 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi create mode 100644 packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py diff --git a/packages/polywrap-client/polywrap_client/client.py b/packages/polywrap-client/polywrap_client/client.py index 2ac5601c..e89cc991 100644 --- a/packages/polywrap-client/polywrap_client/client.py +++ b/packages/polywrap-client/polywrap_client/client.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json from dataclasses import dataclass from textwrap import dedent from typing import Any, Dict, List, Optional, Union, cast @@ -13,12 +14,13 @@ InvokerOptions, IUriResolutionContext, IUriResolver, + IWrapPackage, TryResolveUriOptions, Uri, - IWrapPackage, UriPackageOrWrapper, UriResolutionContext, Wrapper, + build_clean_uri_history, ) from polywrap_manifest import AnyWrapManifest from polywrap_msgpack import msgpack_decode, msgpack_encode @@ -96,12 +98,11 @@ async def load_wrapper( if result.is_err(): return cast(Err, result) if result.is_ok() and result.ok is None: - # FIXME: add resolution stack return Err.from_str( dedent( f""" Error resolving URI "{uri.uri}" - Resolution Stack: NotImplemented + Resolution Stack: {json.dumps(build_clean_uri_history(resolution_context.get_history()), indent=2)} """ ) ) @@ -109,13 +110,12 @@ async def load_wrapper( uri_package_or_wrapper = result.unwrap() if isinstance(uri_package_or_wrapper, Uri): - # FIXME: add resolution stack return Err.from_str( dedent( f""" Error resolving URI "{uri.uri}" URI not found - Resolution Stack: NotImplemented + Resolution Stack: {json.dumps(build_clean_uri_history(resolution_context.get_history()), indent=2)} """ ) ) diff --git a/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi b/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi index bd999afc..9fdb4d44 100644 --- a/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi +++ b/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi @@ -2,14 +2,14 @@ This type stub file was generated by pyright. """ -from typing import List, Optional, Set +from typing import List, Optional, Set, Tuple from ..types import IUriResolutionContext, IUriResolutionStep, Uri class UriResolutionContext(IUriResolutionContext): resolving_uri_set: Set[Uri] resolution_path: List[Uri] history: List[IUriResolutionStep] - __slots__ = ... + __slots__: Tuple[str] = ... def __init__(self, resolving_uri_set: Optional[Set[Uri]] = ..., resolution_path: Optional[List[Uri]] = ..., history: Optional[List[IUriResolutionStep]] = ...) -> None: ... diff --git a/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi index b2a379f8..18572147 100644 --- a/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi +++ b/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi @@ -4,6 +4,7 @@ This type stub file was generated by pyright. from .get_env_from_uri_history import * from .init_wrapper import * +from .build_clean_uri_history import * from .instance_of import * from .maybe_async import * diff --git a/packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi b/packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi new file mode 100644 index 00000000..5d910736 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi @@ -0,0 +1,16 @@ +from typing import List, Optional, Union + +from ..types import IUriResolutionStep + + +CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] + + +def build_clean_uri_history( + history: List[IUriResolutionStep], depth: Optional[int] = ... +) -> CleanResolutionStep: + ... + + +def _build_clean_history_step(step: IUriResolutionStep) -> str: + ... \ No newline at end of file diff --git a/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi b/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi index 84ac59e0..e5b71021 100644 --- a/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi +++ b/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi @@ -4,6 +4,6 @@ This type stub file was generated by pyright. from typing import Any -def instance_of(obj: Any, cls: Any): # -> bool: +def instance_of(obj: Any, cls: Any) -> bool: ... diff --git a/packages/polywrap-core/polywrap_core/utils/__init__.py b/packages/polywrap-core/polywrap_core/utils/__init__.py index 64c02568..ed5d0a4f 100644 --- a/packages/polywrap-core/polywrap_core/utils/__init__.py +++ b/packages/polywrap-core/polywrap_core/utils/__init__.py @@ -2,3 +2,4 @@ from .init_wrapper import * from .instance_of import * from .maybe_async import * +from .build_clean_uri_history import * diff --git a/packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py b/packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py new file mode 100644 index 00000000..6a58e0ec --- /dev/null +++ b/packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py @@ -0,0 +1,74 @@ +import traceback +from typing import List, Optional, Union + +from polywrap_core import Uri, IWrapPackage +from ..types import IUriResolutionStep + + +CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] + + +def build_clean_uri_history( + history: List[IUriResolutionStep], depth: Optional[int] = None +) -> CleanResolutionStep: + clean_history: CleanResolutionStep = [] + + if depth is not None: + depth -= 1 + + if not history: + return clean_history + + for step in history: + clean_history.append(_build_clean_history_step(step)) + + if ( + not step.sub_history + or len(step.sub_history) == 0 + or (depth is not None and depth < 0) + ): + continue + + sub_history = build_clean_uri_history(step.sub_history, depth) + if len(sub_history) > 0: + clean_history.append(sub_history) + + return clean_history + + +def _build_clean_history_step(step: IUriResolutionStep) -> str: + if step.result.is_err(): + formatted_exc = traceback.format_tb(step.result.unwrap_err().__traceback__) + return ( + f"{step.source_uri} => {step.description} => error ({''.join(formatted_exc)})" + if step.description + else f"{step.source_uri} => error ({''.join(formatted_exc)})" + ) + + uri_package_or_wrapper = step.result.unwrap() + + if isinstance(uri_package_or_wrapper, Uri): + if step.source_uri == uri_package_or_wrapper: + return ( + f"{step.source_uri} => {step.description}" + if step.description + else f"{step.source_uri}" + ) + else: + return ( + f"{step.source_uri} => {step.description} => uri ({uri_package_or_wrapper.uri})" + if step.description + else f"{step.source_uri} => uri ({uri_package_or_wrapper})" + ) + elif isinstance(uri_package_or_wrapper, IWrapPackage): + return ( + f"{step.source_uri} => {step.description} => package ({uri_package_or_wrapper})" + if step.description + else f"{step.source_uri} => package ({uri_package_or_wrapper})" + ) + else: + return ( + f"{step.source_uri} => {step.description} => wrapper ({uri_package_or_wrapper})" + if step.description + else f"{step.source_uri} => wrapper ({uri_package_or_wrapper})" + ) diff --git a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py index cac650ff..f35acacf 100644 --- a/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py +++ b/packages/polywrap-uri-resolvers/polywrap_uri_resolvers/helpers/__init__.py @@ -1 +1,3 @@ from .resolver_like_to_resolver import * +from .get_uri_resolution_path import * +from .resolver_with_loop_guard import * From 99a0f02dce8c45b6d9dd836e99565643c48c6e5a Mon Sep 17 00:00:00 2001 From: Niraj Kamdar Date: Sat, 10 Dec 2022 12:41:49 +0400 Subject: [PATCH 8/8] feat: update polywrap-core --- .../typings/polywrap_core/__init__.pyi | 1 + .../polywrap_core/algorithms/__init__.pyi | 6 ++++++ .../algorithms/build_clean_uri_history.pyi | 11 ++++++++++ .../typings/polywrap_core/types/__init__.pyi | 2 +- .../uri_resolution/uri_resolution_context.pyi | 4 ++-- .../typings/polywrap_core/utils/__init__.pyi | 1 - .../utils/build_clean_uri_history.pyi | 16 -------------- .../polywrap_core/utils/instance_of.pyi | 2 +- .../polywrap-core/polywrap_core/__init__.py | 1 + .../polywrap_core/algorithms/__init__.py | 1 + .../build_clean_uri_history.py | 3 +-- .../polywrap_core/utils/__init__.py | 1 - .../typings/polywrap_core/__init__.pyi | 1 + .../polywrap_core/algorithms/__init__.pyi | 6 ++++++ .../algorithms/build_clean_uri_history.pyi | 11 ++++++++++ .../typings/polywrap_core/types/__init__.pyi | 5 ++--- .../typings/polywrap_core/types/client.pyi | 2 +- .../typings/polywrap_core/types/invoke.pyi | 2 +- .../polywrap_core/types/uri_package.pyi | 15 ------------- .../types/uri_package_wrapper.pyi | 6 +++--- .../polywrap_core/types/uri_wrapper.pyi | 15 ------------- .../polywrap_core/types/wasm_package.pyi | 2 +- .../typings/polywrap_core/types/wrapper.pyi | 6 +++--- .../polywrap_core/uri_resolution/__init__.pyi | 1 - .../uri_resolution/uri_resolution_result.pyi | 21 ------------------- .../typings/polywrap_core/__init__.pyi | 1 + .../polywrap_core/algorithms/__init__.pyi | 6 ++++++ .../algorithms/build_clean_uri_history.pyi | 11 ++++++++++ .../typings/polywrap_core/types/__init__.pyi | 1 + .../typings/polywrap_core/__init__.pyi | 1 + .../polywrap_core/algorithms/__init__.pyi | 6 ++++++ .../algorithms/build_clean_uri_history.pyi | 11 ++++++++++ .../typings/polywrap_core/types/__init__.pyi | 1 + 33 files changed, 92 insertions(+), 88 deletions(-) create mode 100644 packages/polywrap-client/typings/polywrap_core/algorithms/__init__.pyi create mode 100644 packages/polywrap-client/typings/polywrap_core/algorithms/build_clean_uri_history.pyi delete mode 100644 packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi create mode 100644 packages/polywrap-core/polywrap_core/algorithms/__init__.py rename packages/polywrap-core/polywrap_core/{utils => algorithms}/build_clean_uri_history.py (96%) create mode 100644 packages/polywrap-plugin/typings/polywrap_core/algorithms/__init__.pyi create mode 100644 packages/polywrap-plugin/typings/polywrap_core/algorithms/build_clean_uri_history.pyi delete mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi delete mode 100644 packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi delete mode 100644 packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/__init__.pyi create mode 100644 packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/build_clean_uri_history.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/algorithms/__init__.pyi create mode 100644 packages/polywrap-wasm/typings/polywrap_core/algorithms/build_clean_uri_history.pyi diff --git a/packages/polywrap-client/typings/polywrap_core/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/__init__.pyi index 0f0cde3d..2a0b0261 100644 --- a/packages/polywrap-client/typings/polywrap_core/__init__.pyi +++ b/packages/polywrap-client/typings/polywrap_core/__init__.pyi @@ -3,6 +3,7 @@ This type stub file was generated by pyright. """ from .types import * +from .algorithms import * from .uri_resolution import * from .utils import * diff --git a/packages/polywrap-client/typings/polywrap_core/algorithms/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/algorithms/__init__.pyi new file mode 100644 index 00000000..1cf24efd --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/algorithms/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .build_clean_uri_history import * + diff --git a/packages/polywrap-client/typings/polywrap_core/algorithms/build_clean_uri_history.pyi b/packages/polywrap-client/typings/polywrap_core/algorithms/build_clean_uri_history.pyi new file mode 100644 index 00000000..1f0fc934 --- /dev/null +++ b/packages/polywrap-client/typings/polywrap_core/algorithms/build_clean_uri_history.pyi @@ -0,0 +1,11 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Union +from ..types import IUriResolutionStep + +CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] +def build_clean_uri_history(history: List[IUriResolutionStep], depth: Optional[int] = ...) -> CleanResolutionStep: + ... + diff --git a/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi index 30e5f011..e1c26d58 100644 --- a/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi +++ b/packages/polywrap-client/typings/polywrap_core/types/__init__.pyi @@ -5,8 +5,8 @@ This type stub file was generated by pyright. from .client import * from .file_reader import * from .invoke import * -from .env import * from .uri import * +from .env import * from .uri_package_wrapper import * from .uri_resolution_context import * from .uri_resolution_step import * diff --git a/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi b/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi index 9fdb4d44..bd999afc 100644 --- a/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi +++ b/packages/polywrap-client/typings/polywrap_core/uri_resolution/uri_resolution_context.pyi @@ -2,14 +2,14 @@ This type stub file was generated by pyright. """ -from typing import List, Optional, Set, Tuple +from typing import List, Optional, Set from ..types import IUriResolutionContext, IUriResolutionStep, Uri class UriResolutionContext(IUriResolutionContext): resolving_uri_set: Set[Uri] resolution_path: List[Uri] history: List[IUriResolutionStep] - __slots__: Tuple[str] = ... + __slots__ = ... def __init__(self, resolving_uri_set: Optional[Set[Uri]] = ..., resolution_path: Optional[List[Uri]] = ..., history: Optional[List[IUriResolutionStep]] = ...) -> None: ... diff --git a/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi b/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi index 18572147..b2a379f8 100644 --- a/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi +++ b/packages/polywrap-client/typings/polywrap_core/utils/__init__.pyi @@ -4,7 +4,6 @@ This type stub file was generated by pyright. from .get_env_from_uri_history import * from .init_wrapper import * -from .build_clean_uri_history import * from .instance_of import * from .maybe_async import * diff --git a/packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi b/packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi deleted file mode 100644 index 5d910736..00000000 --- a/packages/polywrap-client/typings/polywrap_core/utils/build_clean_uri_history.pyi +++ /dev/null @@ -1,16 +0,0 @@ -from typing import List, Optional, Union - -from ..types import IUriResolutionStep - - -CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] - - -def build_clean_uri_history( - history: List[IUriResolutionStep], depth: Optional[int] = ... -) -> CleanResolutionStep: - ... - - -def _build_clean_history_step(step: IUriResolutionStep) -> str: - ... \ No newline at end of file diff --git a/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi b/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi index e5b71021..84ac59e0 100644 --- a/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi +++ b/packages/polywrap-client/typings/polywrap_core/utils/instance_of.pyi @@ -4,6 +4,6 @@ This type stub file was generated by pyright. from typing import Any -def instance_of(obj: Any, cls: Any) -> bool: +def instance_of(obj: Any, cls: Any): # -> bool: ... diff --git a/packages/polywrap-core/polywrap_core/__init__.py b/packages/polywrap-core/polywrap_core/__init__.py index 617a9dc3..b6120076 100644 --- a/packages/polywrap-core/polywrap_core/__init__.py +++ b/packages/polywrap-core/polywrap_core/__init__.py @@ -1,3 +1,4 @@ from .types import * +from .algorithms import * from .uri_resolution import * from .utils import * diff --git a/packages/polywrap-core/polywrap_core/algorithms/__init__.py b/packages/polywrap-core/polywrap_core/algorithms/__init__.py new file mode 100644 index 00000000..964835ec --- /dev/null +++ b/packages/polywrap-core/polywrap_core/algorithms/__init__.py @@ -0,0 +1 @@ +from .build_clean_uri_history import * \ No newline at end of file diff --git a/packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py b/packages/polywrap-core/polywrap_core/algorithms/build_clean_uri_history.py similarity index 96% rename from packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py rename to packages/polywrap-core/polywrap_core/algorithms/build_clean_uri_history.py index 6a58e0ec..af8eff3c 100644 --- a/packages/polywrap-core/polywrap_core/utils/build_clean_uri_history.py +++ b/packages/polywrap-core/polywrap_core/algorithms/build_clean_uri_history.py @@ -1,8 +1,7 @@ import traceback from typing import List, Optional, Union -from polywrap_core import Uri, IWrapPackage -from ..types import IUriResolutionStep +from ..types import Uri, IWrapPackage, IUriResolutionStep CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] diff --git a/packages/polywrap-core/polywrap_core/utils/__init__.py b/packages/polywrap-core/polywrap_core/utils/__init__.py index ed5d0a4f..64c02568 100644 --- a/packages/polywrap-core/polywrap_core/utils/__init__.py +++ b/packages/polywrap-core/polywrap_core/utils/__init__.py @@ -2,4 +2,3 @@ from .init_wrapper import * from .instance_of import * from .maybe_async import * -from .build_clean_uri_history import * diff --git a/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi index 0f0cde3d..2a0b0261 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/__init__.pyi @@ -3,6 +3,7 @@ This type stub file was generated by pyright. """ from .types import * +from .algorithms import * from .uri_resolution import * from .utils import * diff --git a/packages/polywrap-plugin/typings/polywrap_core/algorithms/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/algorithms/__init__.pyi new file mode 100644 index 00000000..1cf24efd --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/algorithms/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .build_clean_uri_history import * + diff --git a/packages/polywrap-plugin/typings/polywrap_core/algorithms/build_clean_uri_history.pyi b/packages/polywrap-plugin/typings/polywrap_core/algorithms/build_clean_uri_history.pyi new file mode 100644 index 00000000..1f0fc934 --- /dev/null +++ b/packages/polywrap-plugin/typings/polywrap_core/algorithms/build_clean_uri_history.pyi @@ -0,0 +1,11 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Union +from ..types import IUriResolutionStep + +CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] +def build_clean_uri_history(history: List[IUriResolutionStep], depth: Optional[int] = ...) -> CleanResolutionStep: + ... + diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi index 284e1b79..e1c26d58 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/types/__init__.pyi @@ -6,14 +6,13 @@ from .client import * from .file_reader import * from .invoke import * from .uri import * -from .uri_package import * +from .env import * from .uri_package_wrapper import * from .uri_resolution_context import * from .uri_resolution_step import * from .uri_resolver import * from .uri_resolver_handler import * -from .uri_wrapper import * -from .wrap_package import * from .wasm_package import * +from .wrap_package import * from .wrapper import * diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi index 3e1ecf67..d1a2ab03 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/types/client.pyi @@ -7,9 +7,9 @@ from dataclasses import dataclass from typing import Dict, List, Optional, Union from polywrap_manifest import AnyWrapManifest, DeserializeManifestOptions from polywrap_result import Result +from .env import Env from .invoke import Invoker from .uri import Uri -from .env import Env from .uri_resolver import IUriResolver from .uri_resolver_handler import UriResolverHandler diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi index 2a070a90..59c615a5 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/types/invoke.pyi @@ -6,8 +6,8 @@ from abc import ABC, abstractmethod from dataclasses import dataclass from typing import Any, Dict, List, Optional, Union from polywrap_result import Result -from .uri import Uri from .env import Env +from .uri import Uri from .uri_resolution_context import IUriResolutionContext @dataclass(slots=True, kw_only=True) diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi deleted file mode 100644 index ea321ac0..00000000 --- a/packages/polywrap-plugin/typings/polywrap_core/types/uri_package.pyi +++ /dev/null @@ -1,15 +0,0 @@ -""" -This type stub file was generated by pyright. -""" - -from dataclasses import dataclass -from .uri import Uri -from .wrap_package import IWrapPackage - -@dataclass(slots=True, kw_only=True) -class UriPackage: - uri: Uri - package: IWrapPackage - ... - - diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi index ef3413de..619b7e14 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/types/uri_package_wrapper.pyi @@ -4,7 +4,7 @@ This type stub file was generated by pyright. from typing import Union from .uri import Uri -from .uri_package import UriPackage -from .uri_wrapper import UriWrapper +from .wrap_package import IWrapPackage +from .wrapper import Wrapper -UriPackageOrWrapper = Union[Uri, UriWrapper, UriPackage] +UriPackageOrWrapper = Union[Uri, Wrapper, IWrapPackage] diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi deleted file mode 100644 index 408529a8..00000000 --- a/packages/polywrap-plugin/typings/polywrap_core/types/uri_wrapper.pyi +++ /dev/null @@ -1,15 +0,0 @@ -""" -This type stub file was generated by pyright. -""" - -from dataclasses import dataclass -from .uri import Uri -from .wrapper import Wrapper - -@dataclass(slots=True, kw_only=True) -class UriWrapper: - uri: Uri - wrapper: Wrapper - ... - - diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi index a7744aa1..4de7f1f7 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/types/wasm_package.pyi @@ -8,7 +8,7 @@ from .wrap_package import IWrapPackage class IWasmPackage(IWrapPackage, ABC): @abstractmethod - async def get_wasm_module() -> Result[bytes]: + async def get_wasm_module(self) -> Result[bytes]: ... diff --git a/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi b/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi index cba4d900..4a05539f 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/types/wrapper.pyi @@ -3,11 +3,11 @@ This type stub file was generated by pyright. """ from abc import abstractmethod -from typing import Dict, Union +from typing import Any, Dict, Union from polywrap_manifest import AnyWrapManifest from polywrap_result import Result from .client import GetFileOptions -from .invoke import Invocable, InvocableResult, InvokeOptions, Invoker +from .invoke import Invocable, InvokeOptions, Invoker class Wrapper(Invocable): """ @@ -18,7 +18,7 @@ class Wrapper(Invocable): client: The client instance requesting this invocation. This client will be used for any sub-invokes that occur. """ @abstractmethod - async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[InvocableResult]: + async def invoke(self, options: InvokeOptions, invoker: Invoker) -> Result[Any]: ... @abstractmethod diff --git a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi index a4101f84..aacd9177 100644 --- a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi +++ b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/__init__.pyi @@ -3,5 +3,4 @@ This type stub file was generated by pyright. """ from .uri_resolution_context import * -from .uri_resolution_result import * diff --git a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi b/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi deleted file mode 100644 index c73c4fe1..00000000 --- a/packages/polywrap-plugin/typings/polywrap_core/uri_resolution/uri_resolution_result.pyi +++ /dev/null @@ -1,21 +0,0 @@ -""" -This type stub file was generated by pyright. -""" - -from typing import List, Optional -from polywrap_result import Result -from ..types import IUriResolutionStep, IWrapPackage, Uri, UriPackageOrWrapper, Wrapper - -class UriResolutionResult: - result: Result[UriPackageOrWrapper] - history: Optional[List[IUriResolutionStep]] - @staticmethod - def ok(uri: Uri, package: Optional[IWrapPackage] = ..., wrapper: Optional[Wrapper] = ...) -> Result[UriPackageOrWrapper]: - ... - - @staticmethod - def err(error: Exception) -> Result[UriPackageOrWrapper]: - ... - - - diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi index 0f0cde3d..2a0b0261 100644 --- a/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/__init__.pyi @@ -3,6 +3,7 @@ This type stub file was generated by pyright. """ from .types import * +from .algorithms import * from .uri_resolution import * from .utils import * diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/__init__.pyi new file mode 100644 index 00000000..1cf24efd --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .build_clean_uri_history import * + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/build_clean_uri_history.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/build_clean_uri_history.pyi new file mode 100644 index 00000000..1f0fc934 --- /dev/null +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/algorithms/build_clean_uri_history.pyi @@ -0,0 +1,11 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Union +from ..types import IUriResolutionStep + +CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] +def build_clean_uri_history(history: List[IUriResolutionStep], depth: Optional[int] = ...) -> CleanResolutionStep: + ... + diff --git a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi index 17a9261d..e1c26d58 100644 --- a/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi +++ b/packages/polywrap-uri-resolvers/typings/polywrap_core/types/__init__.pyi @@ -6,6 +6,7 @@ from .client import * from .file_reader import * from .invoke import * from .uri import * +from .env import * from .uri_package_wrapper import * from .uri_resolution_context import * from .uri_resolution_step import * diff --git a/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi index 0f0cde3d..2a0b0261 100644 --- a/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi +++ b/packages/polywrap-wasm/typings/polywrap_core/__init__.pyi @@ -3,6 +3,7 @@ This type stub file was generated by pyright. """ from .types import * +from .algorithms import * from .uri_resolution import * from .utils import * diff --git a/packages/polywrap-wasm/typings/polywrap_core/algorithms/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/algorithms/__init__.pyi new file mode 100644 index 00000000..1cf24efd --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/algorithms/__init__.pyi @@ -0,0 +1,6 @@ +""" +This type stub file was generated by pyright. +""" + +from .build_clean_uri_history import * + diff --git a/packages/polywrap-wasm/typings/polywrap_core/algorithms/build_clean_uri_history.pyi b/packages/polywrap-wasm/typings/polywrap_core/algorithms/build_clean_uri_history.pyi new file mode 100644 index 00000000..1f0fc934 --- /dev/null +++ b/packages/polywrap-wasm/typings/polywrap_core/algorithms/build_clean_uri_history.pyi @@ -0,0 +1,11 @@ +""" +This type stub file was generated by pyright. +""" + +from typing import List, Optional, Union +from ..types import IUriResolutionStep + +CleanResolutionStep = List[Union[str, "CleanResolutionStep"]] +def build_clean_uri_history(history: List[IUriResolutionStep], depth: Optional[int] = ...) -> CleanResolutionStep: + ... + diff --git a/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi b/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi index 17a9261d..e1c26d58 100644 --- a/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi +++ b/packages/polywrap-wasm/typings/polywrap_core/types/__init__.pyi @@ -6,6 +6,7 @@ from .client import * from .file_reader import * from .invoke import * from .uri import * +from .env import * from .uri_package_wrapper import * from .uri_resolution_context import * from .uri_resolution_step import *