This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Adam Wierzbicki <awierzbicki@golem.network>
- Loading branch information
Showing
6 changed files
with
264 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
from typing import ( | ||
Any, | ||
Dict, | ||
Optional, | ||
Tuple | ||
) | ||
|
||
from twisted.internet.defer import Deferred | ||
|
||
from golem.envs import ( | ||
CounterId, | ||
CounterUsage, | ||
EnvConfig, | ||
EnvEventListener, | ||
EnvEventType, | ||
Environment, | ||
EnvStatus, | ||
EnvSupportStatus, | ||
Prerequisites, | ||
Runtime, | ||
RuntimeEventListener, | ||
RuntimeEventType, | ||
RuntimeInput, | ||
RuntimeOutput, | ||
RuntimePayload, | ||
RuntimeStatus | ||
) | ||
|
||
|
||
class RuntimeWrapper(Runtime): | ||
""" A no-op wrapper which proxies all calls to the wrapped Runtime. | ||
Base class for implementing other wrappers. """ | ||
|
||
def __init__(self, runtime: Runtime) -> None: | ||
self._runtime = runtime | ||
|
||
def prepare(self) -> Deferred: | ||
return self._runtime.prepare() | ||
|
||
def clean_up(self) -> Deferred: | ||
return self._runtime.clean_up() | ||
|
||
def start(self) -> Deferred: | ||
return self._runtime.start() | ||
|
||
def wait_until_stopped(self) -> Deferred: | ||
return self._runtime.wait_until_stopped() | ||
|
||
def stop(self) -> Deferred: | ||
return self._runtime.stop() | ||
|
||
def status(self) -> RuntimeStatus: | ||
return self._runtime.status() | ||
|
||
def stdin(self, encoding: Optional[str] = None) -> RuntimeInput: | ||
return self._runtime.stdin(encoding) | ||
|
||
def stdout(self, encoding: Optional[str] = None) -> RuntimeOutput: | ||
return self._runtime.stdout(encoding) | ||
|
||
def stderr(self, encoding: Optional[str] = None) -> RuntimeOutput: | ||
return self._runtime.stderr(encoding) | ||
|
||
def get_port_mapping(self, port: int) -> Tuple[str, int]: | ||
return self._runtime.get_port_mapping(port) | ||
|
||
def usage_counters(self) -> Dict[CounterId, CounterUsage]: | ||
return self._runtime.usage_counters() | ||
|
||
def listen( | ||
self, | ||
event_type: RuntimeEventType, | ||
listener: RuntimeEventListener | ||
) -> None: | ||
self._runtime.listen(event_type, listener) | ||
|
||
|
||
class EnvironmentWrapper(Environment): | ||
|
||
def __init__(self, env: Environment) -> None: | ||
self._env = env | ||
|
||
@classmethod | ||
def supported(cls) -> EnvSupportStatus: | ||
# This method should not be called on a wrapped environment. | ||
raise AttributeError('Method not supported on a wrapped environment') | ||
|
||
def status(self) -> EnvStatus: | ||
return self._env.status() | ||
|
||
def prepare(self) -> Deferred: | ||
return self._env.prepare() | ||
|
||
def clean_up(self) -> Deferred: | ||
return self._env.clean_up() | ||
|
||
def run_benchmark(self) -> Deferred: | ||
return self._env.run_benchmark() | ||
|
||
def parse_prerequisites( | ||
self, prerequisites_dict: Dict[str, Any] | ||
) -> Prerequisites: | ||
return self._env.parse_prerequisites(prerequisites_dict) | ||
|
||
def install_prerequisites(self, prerequisites: Prerequisites) -> Deferred: | ||
return self._env.install_prerequisites(prerequisites) | ||
|
||
def parse_config(self, config_dict: Dict[str, Any]) -> EnvConfig: | ||
return self._env.parse_config(config_dict) | ||
|
||
def config(self) -> EnvConfig: | ||
return self._env.config() | ||
|
||
def update_config(self, config: EnvConfig) -> None: | ||
self._env.update_config(config) | ||
|
||
def listen( | ||
self, | ||
event_type: EnvEventType, | ||
listener: EnvEventListener | ||
) -> None: | ||
self._env.listen(event_type, listener) | ||
|
||
def runtime( | ||
self, | ||
payload: RuntimePayload, | ||
config: Optional[EnvConfig] = None | ||
) -> Runtime: | ||
return self._env.runtime(payload, config) |
Oops, something went wrong.