|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from abc import abstractmethod |
| 4 | +from collections.abc import Mapping, Sized |
| 5 | +from typing import ( |
| 6 | + Any, |
| 7 | + List, |
| 8 | + Literal, |
| 9 | + Protocol, |
| 10 | + TypedDict, |
| 11 | + runtime_checkable, |
| 12 | +) |
| 13 | + |
| 14 | +MatchingType = Literal["any", "exact", "none"] |
| 15 | +"""Directions for how environments are considered for selection. |
| 16 | +
|
| 17 | + - any: The image may be selected by Connect if not defined in the bundle manifest. |
| 18 | + - exact: The image must be defined in the bundle manifest |
| 19 | + - none: Never use this environment |
| 20 | +""" |
| 21 | + |
| 22 | + |
| 23 | +class Installation(TypedDict): |
| 24 | + """Interpreter installation in an execution environment.""" |
| 25 | + |
| 26 | + path: str |
| 27 | + """The absolute path to the interpreter's executable.""" |
| 28 | + |
| 29 | + version: str |
| 30 | + """The semantic version of the interpreter.""" |
| 31 | + |
| 32 | + |
| 33 | +class Installations(TypedDict): |
| 34 | + """Interpreter installations in an execution environment.""" |
| 35 | + |
| 36 | + installations: List[Installation] |
| 37 | + """Interpreter installations in an execution environment.""" |
| 38 | + |
| 39 | + |
| 40 | +class Environment(Mapping[str, Any]): |
| 41 | + @abstractmethod |
| 42 | + def destroy(self) -> None: |
| 43 | + """Destroy the environment. |
| 44 | +
|
| 45 | + Warnings |
| 46 | + -------- |
| 47 | + This operation is irreversible. |
| 48 | +
|
| 49 | + Note |
| 50 | + ---- |
| 51 | + This action requires administrator privileges. |
| 52 | + """ |
| 53 | + |
| 54 | + @abstractmethod |
| 55 | + def update( |
| 56 | + self, |
| 57 | + *, |
| 58 | + title: str, |
| 59 | + description: str | None = ..., |
| 60 | + matching: MatchingType | None = ..., |
| 61 | + supervisor: str | None = ..., |
| 62 | + python: Installations | None = ..., |
| 63 | + quarto: Installations | None = ..., |
| 64 | + r: Installations | None = ..., |
| 65 | + tensorflow: Installations | None = ..., |
| 66 | + ) -> None: |
| 67 | + """Update the environment. |
| 68 | +
|
| 69 | + Parameters |
| 70 | + ---------- |
| 71 | + title : str |
| 72 | + A human-readable title. |
| 73 | + description : str | None, optional, not required |
| 74 | + A human-readable description. |
| 75 | + matching : MatchingType, optional, not required |
| 76 | + Directions for how the environment is considered for selection |
| 77 | + supervisor : str | None, optional, not required |
| 78 | + Path to the supervisor script. |
| 79 | + python : Installations, optional, not required |
| 80 | + The Python installations available in this environment |
| 81 | + quarto : Installations, optional, not required |
| 82 | + The Quarto installations available in this environment |
| 83 | + r : Installations, optional, not required |
| 84 | + The R installations available in this environment |
| 85 | + tensorflow : Installations, optional, not required |
| 86 | + The Tensorflow installations available in this environment |
| 87 | +
|
| 88 | + Note |
| 89 | + ---- |
| 90 | + This action requires administrator privileges. |
| 91 | + """ |
| 92 | + |
| 93 | + |
| 94 | +@runtime_checkable |
| 95 | +class Environments(Sized, Protocol): |
| 96 | + def create( |
| 97 | + self, |
| 98 | + *, |
| 99 | + title: str, |
| 100 | + name: str, |
| 101 | + cluster_name: str | Literal["Kubernetes"], |
| 102 | + matching: MatchingType = "any", |
| 103 | + description: str | None = ..., |
| 104 | + supervisor: str | None = ..., |
| 105 | + python: Installations | None = ..., |
| 106 | + quarto: Installations | None = ..., |
| 107 | + r: Installations | None = ..., |
| 108 | + tensorflow: Installations | None = ..., |
| 109 | + ) -> Environment: |
| 110 | + """Create an environment. |
| 111 | +
|
| 112 | + Parameters |
| 113 | + ---------- |
| 114 | + title : str |
| 115 | + A human-readable title. |
| 116 | + name : str |
| 117 | + The container image name used for execution in this environment. |
| 118 | + cluster_name : str | Literal["Kubernetes"] |
| 119 | + The cluster identifier for this environment. Defaults to "Kubernetes" when Off-Host-Execution is enabled. |
| 120 | + description : str, optional |
| 121 | + A human-readable description. |
| 122 | + matching : MatchingType |
| 123 | + Directions for how the environment is considered for selection, by default is "any". |
| 124 | + supervisor : str, optional |
| 125 | + Path to the supervisor script |
| 126 | + python : Installations, optional |
| 127 | + The Python installations available in this environment |
| 128 | + quarto : Installations, optional |
| 129 | + The Quarto installations available in this environment |
| 130 | + r : Installations, optional |
| 131 | + The R installations available in this environment |
| 132 | + tensorflow : Installations, optional |
| 133 | + The Tensorflow installations available in this environment |
| 134 | +
|
| 135 | + Returns |
| 136 | + ------- |
| 137 | + Environment |
| 138 | +
|
| 139 | + Note |
| 140 | + ---- |
| 141 | + This action requires administrator privileges. |
| 142 | + """ |
| 143 | + ... |
| 144 | + |
| 145 | + def find(self, guid: str, /) -> Environment: ... |
| 146 | + |
| 147 | + def find_by( |
| 148 | + self, |
| 149 | + *, |
| 150 | + id: str = ..., # noqa: A002 |
| 151 | + guid: str = ..., |
| 152 | + created_time: str = ..., |
| 153 | + updated_time: str = ..., |
| 154 | + title: str = ..., |
| 155 | + name: str = ..., |
| 156 | + description: str | None = ..., |
| 157 | + cluster_name: str | Literal["Kubernetes"] = ..., |
| 158 | + environment_type: str | Literal["Kubernetes"] = ..., |
| 159 | + matching: MatchingType = ..., |
| 160 | + supervisor: str | None = ..., |
| 161 | + python: Installations | None = ..., |
| 162 | + quarto: Installations | None = ..., |
| 163 | + r: Installations | None = ..., |
| 164 | + tensorflow: Installations | None = ..., |
| 165 | + ) -> Environment | None: |
| 166 | + """Find the first record matching the specified conditions. |
| 167 | +
|
| 168 | + There is no implied ordering, so if order matters, you should specify it yourself. |
| 169 | +
|
| 170 | + Parameters |
| 171 | + ---------- |
| 172 | + id : str |
| 173 | + The numerical identifier. |
| 174 | + guid : str |
| 175 | + The unique identifier. |
| 176 | + created_time : str |
| 177 | + The timestamp (RFC3339) when the environment was created. |
| 178 | + updated_time : str |
| 179 | + The timestamp (RFC3339) when the environment was updated. |
| 180 | + title : str |
| 181 | + A human-readable title. |
| 182 | + name : str |
| 183 | + The container image name used for execution in this environment. |
| 184 | + description : str, optional |
| 185 | + A human-readable description. |
| 186 | + cluster_name : str | Literal["Kubernetes"] |
| 187 | + The cluster identifier for this environment. Defaults to "Kubernetes" when Off-Host-Execution is enabled. |
| 188 | + environment_type : str | Literal["Kubernetes"] |
| 189 | + The cluster environment type. Defaults to "Kubernetes" when Off-Host-Execution is enabled. |
| 190 | + matching : MatchingType |
| 191 | + Directions for how the environment is considered for selection. |
| 192 | + supervisor : str, optional |
| 193 | + Path to the supervisor script |
| 194 | + python : Installations, optional |
| 195 | + The Python installations available in this environment |
| 196 | + quarto : Installations, optional |
| 197 | + The Quarto installations available in this environment |
| 198 | + r : Installations, optional |
| 199 | + The R installations available in this environment |
| 200 | + tensorflow : Installations, optional |
| 201 | + The Tensorflow installations available in this environment |
| 202 | +
|
| 203 | + Returns |
| 204 | + ------- |
| 205 | + Environment | None |
| 206 | +
|
| 207 | + Note |
| 208 | + ---- |
| 209 | + This action requires administrator or publisher privileges. |
| 210 | + """ |
| 211 | + ... |
0 commit comments