def __init__(self, serialized_runtime_env=None, proto_runtime_env: ProtoRuntimeEnv = None): if serialized_runtime_env: self._proto_runtime_env = json_format.Parse( serialized_runtime_env, ProtoRuntimeEnv()) elif proto_runtime_env: self._proto_runtime_env = proto_runtime_env else: self._proto_runtime_env = ProtoRuntimeEnv()
def build_proto_runtime_env(self): proto_runtime_env = ProtoRuntimeEnv() # set working_dir proto_runtime_env.working_dir = self.working_dir() # set working_dir uri working_dir_uri = self.working_dir_uri() if working_dir_uri is not None: proto_runtime_env.uris.working_dir_uri = working_dir_uri # set py_modules py_modules_uris = self.py_modules_uris() if py_modules_uris: proto_runtime_env.python_runtime_env.py_modules.extend(py_modules_uris) # set py_modules uris proto_runtime_env.uris.py_modules_uris.extend(py_modules_uris) # set env_vars env_vars = self.env_vars() proto_runtime_env.env_vars.update(env_vars.items()) # set extensions for extensions_field in RuntimeEnv.extensions_fields: if extensions_field in self: proto_runtime_env.extensions[extensions_field] = str( self[extensions_field] ) self._build_proto_pip_runtime_env(proto_runtime_env) self._build_proto_conda_runtime_env(proto_runtime_env) self._build_proto_container_runtime_env(proto_runtime_env) self._build_proto_plugin_runtime_env(proto_runtime_env) return proto_runtime_env
def from_dict(cls, runtime_env_dict: Dict[str, Any], conda_get_uri_fn) -> "RuntimeEnv": proto_runtime_env = ProtoRuntimeEnv() proto_runtime_env.py_modules.extend( runtime_env_dict.get("py_modules", [])) proto_runtime_env.working_dir = runtime_env_dict.get("working_dir", "") if "working_dir" in runtime_env_dict: proto_runtime_env.uris.working_dir_uri = runtime_env_dict[ "working_dir"] if "py_modules" in runtime_env_dict: for uri in runtime_env_dict["py_modules"]: proto_runtime_env.uris.py_modules_uris.append(uri) if "conda" or "pip" in runtime_env_dict: uri = conda_get_uri_fn(runtime_env_dict) if uri is not None: proto_runtime_env.uris.conda_uri = uri env_vars = runtime_env_dict.get("env_vars", {}) proto_runtime_env.env_vars.update(env_vars.items()) if "_ray_release" in runtime_env_dict: proto_runtime_env.extensions["_ray_release"] = str( runtime_env_dict["_ray_release"]) if "_ray_commit" in runtime_env_dict: proto_runtime_env.extensions["_ray_commit"] = str( runtime_env_dict["_ray_commit"]) if "_inject_current_ray" in runtime_env_dict: proto_runtime_env.extensions["_inject_current_ray"] = str( runtime_env_dict["_inject_current_ray"]) _build_proto_pip_runtime_env(runtime_env_dict, proto_runtime_env) _build_proto_conda_runtime_env(runtime_env_dict, proto_runtime_env) _build_proto_container_runtime_env(runtime_env_dict, proto_runtime_env) _build_proto_plugin_runtime_env(runtime_env_dict, proto_runtime_env) return cls(proto_runtime_env=proto_runtime_env)
def _proto_runtime_env(self): if self.__proto_runtime_env: return self.__proto_runtime_env proto_runtime_env = ProtoRuntimeEnv() proto_runtime_env.working_dir = self.get("working_dir", "") if "working_dir" in self: proto_runtime_env.uris.working_dir_uri = self["working_dir"] if "py_modules" in self: proto_runtime_env.python_runtime_env.py_modules.extend( self["py_modules"]) for uri in self["py_modules"]: proto_runtime_env.uris.py_modules_uris.append(uri) if "conda" in self: uri = get_conda_uri(self) if uri is not None: proto_runtime_env.uris.conda_uri = uri if "pip" in self: uri = get_pip_uri(self) if uri is not None: proto_runtime_env.uris.pip_uri = uri env_vars = self.get("env_vars", {}) proto_runtime_env.env_vars.update(env_vars.items()) if "_ray_release" in self: proto_runtime_env.extensions["_ray_release"] = str( self["_ray_release"]) if "_ray_commit" in self: proto_runtime_env.extensions["_ray_commit"] = str( self["_ray_commit"]) if "_inject_current_ray" in self: proto_runtime_env.extensions["_inject_current_ray"] = str( self["_inject_current_ray"]) _build_proto_pip_runtime_env(self, proto_runtime_env) _build_proto_conda_runtime_env(self, proto_runtime_env) _build_proto_container_runtime_env(self, proto_runtime_env) _build_proto_plugin_runtime_env(self, proto_runtime_env) self.__proto_runtime_env = proto_runtime_env return self.__proto_runtime_env
def deserialize(cls, serialized_runtime_env: str) -> "RuntimeEnv": # noqa: F821 proto_runtime_env = json_format.Parse(serialized_runtime_env, ProtoRuntimeEnv()) return cls.from_proto(proto_runtime_env)