Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ celerybeat.pid
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""This package contains modules related to client config builder."""

from .polywrap_client_config_builder import *
from .types import *
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""This module contains the base configure class for the client config builder."""
from abc import ABC

from ..types import BuilderConfig, ClientConfigBuilder


class BaseConfigure(ClientConfigBuilder):
class BaseConfigure(ClientConfigBuilder, ABC):
"""BaseConfigure is the base configure class for the client config builder.

Attributes:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
"""This module contains the env configure class for the client config builder."""
from typing import Dict, List, Union
from abc import ABC
from typing import Any, Dict, List, Union

from polywrap_core import Env, Uri
from polywrap_core import Uri

from ..types import ClientConfigBuilder
from ..types import BuilderConfig, ClientConfigBuilder


class EnvConfigure(ClientConfigBuilder):
class EnvConfigure(ClientConfigBuilder, ABC):
"""Allows configuring the environment variables."""

def get_env(self, uri: Uri) -> Union[Env, None]:
config: BuilderConfig

def get_env(self, uri: Uri) -> Union[Any, None]:
"""Return the env for the given uri."""
return self.config.envs.get(uri)

def get_envs(self) -> Dict[Uri, Env]:
def get_envs(self) -> Dict[Uri, Any]:
"""Return the envs from the builder's config."""
return self.config.envs

def set_env(self, uri: Uri, env: Env) -> ClientConfigBuilder:
def set_env(self, uri: Uri, env: Any) -> ClientConfigBuilder:
"""Set the env by uri in the builder's config, overiding any existing values."""
self.config.envs[uri] = env
return self

def set_envs(self, uri_envs: Dict[Uri, Env]) -> ClientConfigBuilder:
def set_envs(self, uri_envs: Dict[Uri, Any]) -> ClientConfigBuilder:
"""Set the envs in the builder's config, overiding any existing values."""
self.config.envs.update(uri_envs)
return self

def add_env(self, uri: Uri, env: Env) -> ClientConfigBuilder:
def add_env(self, uri: Uri, env: Any) -> ClientConfigBuilder:
"""Add an env for the given uri.

If an Env is already associated with the uri, it is modified.
If an Any is already associated with the uri, it is modified.
"""
if self.config.envs.get(uri):
for key in self.config.envs[uri]:
Expand All @@ -39,7 +42,7 @@ def add_env(self, uri: Uri, env: Env) -> ClientConfigBuilder:
self.config.envs[uri] = env
return self

def add_envs(self, uri_envs: Dict[Uri, Env]) -> ClientConfigBuilder:
def add_envs(self, uri_envs: Dict[Uri, Any]) -> ClientConfigBuilder:
"""Add a list of envs to the builder's config."""
for uri, env in uri_envs.items():
self.add_env(uri, env)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""This module contains the interface configure class for the client config builder."""
from abc import ABC
from typing import Dict, List, Union

from polywrap_core import Uri

from ..types import ClientConfigBuilder
from ..types import BuilderConfig, ClientConfigBuilder


class InterfaceConfigure(ClientConfigBuilder):
class InterfaceConfigure(ClientConfigBuilder, ABC):
"""Allows configuring the interface-implementations."""

config: BuilderConfig

def get_interfaces(self) -> Dict[Uri, List[Uri]]:
"""Return all registered interface and its implementations\
from the builder's config."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
"""This module contains the package configure class for the client config builder."""
from abc import ABC
from typing import Dict, List, Union

from polywrap_core import Uri, UriPackageOrWrapper, WrapPackage
from polywrap_core import Uri, WrapPackage

from ..types import ClientConfigBuilder
from ..types import BuilderConfig, ClientConfigBuilder


class PackageConfigure(ClientConfigBuilder):
class PackageConfigure(ClientConfigBuilder, ABC):
"""Allows configuring the WRAP packages."""

def get_package(self, uri: Uri) -> Union[WrapPackage[UriPackageOrWrapper], None]:
config: BuilderConfig

def get_package(self, uri: Uri) -> Union[WrapPackage, None]:
"""Return the package for the given uri."""
return self.config.packages.get(uri)

def get_packages(self) -> Dict[Uri, WrapPackage[UriPackageOrWrapper]]:
def get_packages(self) -> Dict[Uri, WrapPackage]:
"""Return the packages from the builder's config."""
return self.config.packages

def set_package(
self, uri: Uri, package: WrapPackage[UriPackageOrWrapper]
) -> ClientConfigBuilder:
def set_package(self, uri: Uri, package: WrapPackage) -> ClientConfigBuilder:
"""Set the package by uri in the builder's config, overiding any existing values."""
self.config.packages[uri] = package
return self

def set_packages(
self, uri_packages: Dict[Uri, WrapPackage[UriPackageOrWrapper]]
) -> ClientConfigBuilder:
def set_packages(self, uri_packages: Dict[Uri, WrapPackage]) -> ClientConfigBuilder:
"""Set the packages in the builder's config, overiding any existing values."""
self.config.packages.update(uri_packages)
return self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""This module contains the redirect configure class for the client config builder."""
from abc import ABC
from typing import Dict, List, Union

from polywrap_core import Uri

from ..types import ClientConfigBuilder
from ..types import BuilderConfig, ClientConfigBuilder


class RedirectConfigure(ClientConfigBuilder):
class RedirectConfigure(ClientConfigBuilder, ABC):
"""Allows configuring the URI redirects."""

config: BuilderConfig

def get_redirect(self, uri: Uri) -> Union[Uri, None]:
"""Return the redirect for the given uri."""
return self.config.redirects.get(uri)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""This module contains the resolver configure class for the client config builder."""
from abc import ABC
from typing import List

from polywrap_core import UriResolver

from ..types import ClientConfigBuilder
from ..types import BuilderConfig, ClientConfigBuilder


class ResolverConfigure(ClientConfigBuilder):
class ResolverConfigure(ClientConfigBuilder, ABC):
"""Allows configuring the URI resolvers."""

config: BuilderConfig

def get_resolvers(self) -> List[UriResolver]:
"""Return the resolvers from the builder's config."""
return self.config.resolvers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
"""This module contains the wrapper configure class for the client config builder."""
from abc import ABC
from typing import Dict, List, Union

from polywrap_core import Uri, UriPackageOrWrapper, Wrapper
from polywrap_core import Uri, Wrapper

from ..types import ClientConfigBuilder
from ..types import BuilderConfig, ClientConfigBuilder


class WrapperConfigure(ClientConfigBuilder):
class WrapperConfigure(ClientConfigBuilder, ABC):
"""Allows configuring the wrappers."""

def get_wrapper(self, uri: Uri) -> Union[Wrapper[UriPackageOrWrapper], None]:
config: BuilderConfig

def get_wrapper(self, uri: Uri) -> Union[Wrapper, None]:
"""Return the set wrapper for the given uri."""
return self.config.wrappers.get(uri)

def get_wrappers(self) -> Dict[Uri, Wrapper[UriPackageOrWrapper]]:
def get_wrappers(self) -> Dict[Uri, Wrapper]:
"""Return the wrappers from the builder's config."""
return self.config.wrappers

def set_wrapper(
self, uri: Uri, wrapper: Wrapper[UriPackageOrWrapper]
) -> ClientConfigBuilder:
def set_wrapper(self, uri: Uri, wrapper: Wrapper) -> ClientConfigBuilder:
"""Set the wrapper by uri in the builder's config, overiding any existing values."""
self.config.wrappers[uri] = wrapper
return self

def set_wrappers(
self, uri_wrappers: Dict[Uri, Wrapper[UriPackageOrWrapper]]
) -> ClientConfigBuilder:
def set_wrappers(self, uri_wrappers: Dict[Uri, Wrapper]) -> ClientConfigBuilder:
"""Set the wrappers in the builder's config, overiding any existing values."""
self.config.wrappers.update(uri_wrappers)
return self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""This module provides a simple builder for building a ClientConfig object."""
# pylint: disable=too-many-ancestors

from typing import Optional
from typing import Optional, cast

from polywrap_core import ClientConfig
from polywrap_core import ClientConfig, UriPackage, UriWrapper
from polywrap_uri_resolvers import (
ExtendableUriResolver,
InMemoryWrapperCache,
PackageToWrapperResolver,
InMemoryResolutionResultCache,
RecursiveResolver,
RequestSynchronizerResolver,
ResolutionResultCacheResolver,
StaticResolver,
StaticResolverLike,
UriResolverAggregator,
WrapperCacheResolver,
)

from .configures import (
Expand Down Expand Up @@ -51,30 +50,33 @@ def __init__(self):
self.config = BuilderConfig(
envs={}, interfaces={}, resolvers=[], wrappers={}, packages={}, redirects={}
)
super().__init__()

def build(self, options: Optional[BuildOptions] = None) -> ClientConfig:
"""Build the ClientConfig object from the builder's config."""
static_resolver_like = cast(StaticResolverLike, self.config.redirects)

for uri, wrapper in self.config.wrappers.items():
static_resolver_like[uri] = UriWrapper(uri=uri, wrapper=wrapper)

for uri, package in self.config.packages.items():
static_resolver_like[uri] = UriPackage(uri=uri, package=package)

resolver = (
options.resolver
if options and options.resolver
else RecursiveResolver(
RequestSynchronizerResolver(
WrapperCacheResolver(
PackageToWrapperResolver(
UriResolverAggregator(
[
StaticResolver(self.config.redirects),
StaticResolver(self.config.wrappers),
StaticResolver(self.config.packages),
*self.config.resolvers,
ExtendableUriResolver(),
]
)
),
options.wrapper_cache
if options and options.wrapper_cache
else InMemoryWrapperCache(),
)
ResolutionResultCacheResolver(
UriResolverAggregator(
[
StaticResolver(static_resolver_like),
*self.config.resolvers,
ExtendableUriResolver(),
]
),
options.resolution_result_cache
if options and options.resolution_result_cache
else InMemoryResolutionResultCache(),
)
)
)
Expand All @@ -84,3 +86,6 @@ def build(self, options: Optional[BuildOptions] = None) -> ClientConfig:
interfaces=self.config.interfaces,
resolver=resolver,
)


__all__ = ["PolywrapClientConfigBuilder"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
from typing import Optional

from polywrap_core import UriResolver
from polywrap_uri_resolvers import WrapperCache
from polywrap_uri_resolvers import ResolutionResultCache


@dataclass(slots=True, kw_only=True)
class BuildOptions:
"""BuildOptions defines the options for build method of the client config builder.

Attributes:
wrapper_cache: The wrapper cache.
resolution_result_cache: The Resolution Result Cache.
resolver: The URI resolver.
"""

wrapper_cache: Optional[WrapperCache] = None
resolution_result_cache: Optional[ResolutionResultCache] = None
resolver: Optional[UriResolver] = None


__all__ = ["BuildOptions"]
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
"""This module contains the BuilderConfig class."""
from dataclasses import dataclass
from typing import Dict, List
from typing import Any, Dict, List

from polywrap_core import (
Env,
Uri,
UriPackageOrWrapper,
UriResolver,
WrapPackage,
Wrapper,
)
from polywrap_core import Uri, UriResolver, WrapPackage, Wrapper


@dataclass(slots=True, kw_only=True)
class BuilderConfig:
"""BuilderConfig defines the internal configuration for the client config builder.

Attributes:
envs (Dict[Uri, Env]): The environment variables for the wrappers.
envs (Dict[Uri, Any]): The environment variables for the wrappers.
interfaces (Dict[Uri, List[Uri]]): The interfaces and their implementations.
wrappers (Dict[Uri, Wrapper[UriPackageOrWrapper]]): The wrappers.
packages (Dict[Uri, WrapPackage[UriPackageOrWrapper]]): The WRAP packages.
wrappers (Dict[Uri, Wrapper]): The wrappers.
packages (Dict[Uri, WrapPackage]): The WRAP packages.
resolvers (List[UriResolver]): The URI resolvers.
redirects (Dict[Uri, Uri]): The URI redirects.
"""

envs: Dict[Uri, Env]
envs: Dict[Uri, Any]
interfaces: Dict[Uri, List[Uri]]
wrappers: Dict[Uri, Wrapper[UriPackageOrWrapper]]
packages: Dict[Uri, WrapPackage[UriPackageOrWrapper]]
wrappers: Dict[Uri, Wrapper]
packages: Dict[Uri, WrapPackage]
resolvers: List[UriResolver]
redirects: Dict[Uri, Uri]


__all__ = ["BuilderConfig"]
Loading