antioch-py 2.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of antioch-py might be problematic. Click here for more details.
- antioch/__init__.py +0 -0
- antioch/message.py +87 -0
- antioch/module/__init__.py +53 -0
- antioch/module/clock.py +62 -0
- antioch/module/execution.py +278 -0
- antioch/module/input.py +127 -0
- antioch/module/module.py +218 -0
- antioch/module/node.py +357 -0
- antioch/module/token.py +42 -0
- antioch/session/__init__.py +150 -0
- antioch/session/ark.py +504 -0
- antioch/session/asset.py +65 -0
- antioch/session/error.py +80 -0
- antioch/session/record.py +158 -0
- antioch/session/scene.py +1521 -0
- antioch/session/session.py +220 -0
- antioch/session/task.py +323 -0
- antioch/session/views/__init__.py +40 -0
- antioch/session/views/animation.py +189 -0
- antioch/session/views/articulation.py +245 -0
- antioch/session/views/basis_curve.py +186 -0
- antioch/session/views/camera.py +92 -0
- antioch/session/views/collision.py +75 -0
- antioch/session/views/geometry.py +74 -0
- antioch/session/views/ground_plane.py +63 -0
- antioch/session/views/imu.py +73 -0
- antioch/session/views/joint.py +64 -0
- antioch/session/views/light.py +175 -0
- antioch/session/views/pir_sensor.py +140 -0
- antioch/session/views/radar.py +73 -0
- antioch/session/views/rigid_body.py +282 -0
- antioch/session/views/xform.py +119 -0
- antioch_py-2.0.6.dist-info/METADATA +115 -0
- antioch_py-2.0.6.dist-info/RECORD +99 -0
- antioch_py-2.0.6.dist-info/WHEEL +5 -0
- antioch_py-2.0.6.dist-info/entry_points.txt +2 -0
- antioch_py-2.0.6.dist-info/top_level.txt +2 -0
- common/__init__.py +0 -0
- common/ark/__init__.py +60 -0
- common/ark/ark.py +128 -0
- common/ark/hardware.py +121 -0
- common/ark/kinematics.py +31 -0
- common/ark/module.py +85 -0
- common/ark/node.py +94 -0
- common/ark/scheduler.py +439 -0
- common/ark/sim.py +33 -0
- common/assets/__init__.py +3 -0
- common/constants.py +47 -0
- common/core/__init__.py +52 -0
- common/core/agent.py +296 -0
- common/core/auth.py +305 -0
- common/core/registry.py +331 -0
- common/core/task.py +36 -0
- common/message/__init__.py +59 -0
- common/message/annotation.py +89 -0
- common/message/array.py +500 -0
- common/message/base.py +517 -0
- common/message/camera.py +91 -0
- common/message/color.py +139 -0
- common/message/frame.py +50 -0
- common/message/image.py +171 -0
- common/message/imu.py +14 -0
- common/message/joint.py +47 -0
- common/message/log.py +31 -0
- common/message/pir.py +16 -0
- common/message/point.py +109 -0
- common/message/point_cloud.py +63 -0
- common/message/pose.py +148 -0
- common/message/quaternion.py +273 -0
- common/message/radar.py +58 -0
- common/message/types.py +37 -0
- common/message/vector.py +786 -0
- common/rome/__init__.py +9 -0
- common/rome/client.py +430 -0
- common/rome/error.py +16 -0
- common/session/__init__.py +54 -0
- common/session/environment.py +31 -0
- common/session/sim.py +240 -0
- common/session/views/__init__.py +263 -0
- common/session/views/animation.py +73 -0
- common/session/views/articulation.py +184 -0
- common/session/views/basis_curve.py +102 -0
- common/session/views/camera.py +147 -0
- common/session/views/collision.py +59 -0
- common/session/views/geometry.py +102 -0
- common/session/views/ground_plane.py +41 -0
- common/session/views/imu.py +66 -0
- common/session/views/joint.py +81 -0
- common/session/views/light.py +96 -0
- common/session/views/pir_sensor.py +115 -0
- common/session/views/radar.py +82 -0
- common/session/views/rigid_body.py +236 -0
- common/session/views/viewport.py +21 -0
- common/session/views/xform.py +39 -0
- common/utils/__init__.py +4 -0
- common/utils/comms.py +571 -0
- common/utils/logger.py +123 -0
- common/utils/time.py +42 -0
- common/utils/usd.py +12 -0
common/rome/__init__.py
ADDED
common/rome/client.py
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Generator, overload
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
import requests
|
|
7
|
+
from requests import Response
|
|
8
|
+
from tqdm.auto import tqdm
|
|
9
|
+
|
|
10
|
+
from common.ark import ArkReference, AssetReference
|
|
11
|
+
from common.core.task import TaskCompletion, TaskOutcome
|
|
12
|
+
from common.rome.error import RomeAuthError, RomeError, RomeNetworkError
|
|
13
|
+
|
|
14
|
+
DOWNLOAD_CHUNK_SIZE = 8 * 1024 * 1024 # 8MB
|
|
15
|
+
UPLOAD_CHUNK_SIZE = 1024 # 1KB
|
|
16
|
+
FILE_TRANSFER_UNIT_DIVISOR = 1024
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class RomeClient:
|
|
20
|
+
"""
|
|
21
|
+
Client for interacting with Rome (Antioch's cloud API).
|
|
22
|
+
|
|
23
|
+
Handles task completion, artifact uploads/downloads, and registry operations for Arks and Assets.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, api_url: str, token: str):
|
|
27
|
+
"""
|
|
28
|
+
Initialize the Rome client.
|
|
29
|
+
|
|
30
|
+
:param api_url: Base URL for Rome API.
|
|
31
|
+
:param token: Authentication token.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
self._api_url = api_url
|
|
35
|
+
self._token = token
|
|
36
|
+
|
|
37
|
+
def complete_task(
|
|
38
|
+
self,
|
|
39
|
+
ark_name: str,
|
|
40
|
+
ark_version: str,
|
|
41
|
+
ark_hash: str,
|
|
42
|
+
task_start_time: datetime,
|
|
43
|
+
task_complete_time: datetime,
|
|
44
|
+
outcome: TaskOutcome,
|
|
45
|
+
result: dict | None = None,
|
|
46
|
+
) -> str:
|
|
47
|
+
"""
|
|
48
|
+
Complete a task by creating an entry in Antioch's database.
|
|
49
|
+
|
|
50
|
+
:param ark_name: Name of the Ark.
|
|
51
|
+
:param ark_version: Version of the Ark.
|
|
52
|
+
:param ark_hash: Hash of the Ark.
|
|
53
|
+
:param task_start_time: Task start time.
|
|
54
|
+
:param task_complete_time: Task completion time.
|
|
55
|
+
:param outcome: Task outcome (success or failure).
|
|
56
|
+
:param result: Optional task result dictionary.
|
|
57
|
+
:return: The task ID.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
payload = TaskCompletion(
|
|
61
|
+
ark_name=ark_name,
|
|
62
|
+
ark_version=ark_version,
|
|
63
|
+
ark_hash=ark_hash,
|
|
64
|
+
task_start_time=task_start_time,
|
|
65
|
+
task_complete_time=task_complete_time,
|
|
66
|
+
outcome=outcome,
|
|
67
|
+
result=result,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
response = self._send_request("POST", "/tasks/complete", json=payload.model_dump(mode="json"))
|
|
71
|
+
return response["task_id"]
|
|
72
|
+
|
|
73
|
+
def upload_mcap(self, task_id: str, mcap_path: str, show_progress: bool = True) -> None:
|
|
74
|
+
"""
|
|
75
|
+
Upload MCAP file to Rome's cloud storage using streaming.
|
|
76
|
+
|
|
77
|
+
:param task_id: Unique task identifier.
|
|
78
|
+
:param mcap_path: Path to the MCAP file.
|
|
79
|
+
:param show_progress: Show upload progress bar.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
self._upload_file(
|
|
83
|
+
endpoint="/tasks/upload_mcap",
|
|
84
|
+
task_id=task_id,
|
|
85
|
+
file_path=mcap_path,
|
|
86
|
+
content_type="application/octet-stream",
|
|
87
|
+
show_progress=show_progress,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
def upload_bundle(self, task_id: str, bundle_path: str, show_progress: bool = True) -> None:
|
|
91
|
+
"""
|
|
92
|
+
Upload bundle tar.gz file to Rome's cloud storage using streaming.
|
|
93
|
+
|
|
94
|
+
:param task_id: Unique task identifier.
|
|
95
|
+
:param bundle_path: Path to the bundle tar.gz file.
|
|
96
|
+
:param show_progress: Show upload progress bar.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
self._upload_file(
|
|
100
|
+
endpoint="/tasks/upload_bundle",
|
|
101
|
+
task_id=task_id,
|
|
102
|
+
file_path=bundle_path,
|
|
103
|
+
content_type="application/gzip",
|
|
104
|
+
show_progress=show_progress,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def download_mcap(self, task_id: str, output_path: str, show_progress: bool = True, overwrite: bool = False) -> str:
|
|
108
|
+
"""
|
|
109
|
+
Download MCAP file from Rome's cloud storage.
|
|
110
|
+
|
|
111
|
+
:param task_id: Unique task identifier.
|
|
112
|
+
:param output_path: Path where the file should be saved.
|
|
113
|
+
:param show_progress: Show download progress bar.
|
|
114
|
+
:param overwrite: Overwrite existing file.
|
|
115
|
+
:return: Path to the downloaded MCAP file.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
if not output_path.endswith(".mcap"):
|
|
119
|
+
raise ValueError("Output path must end with .mcap")
|
|
120
|
+
|
|
121
|
+
return self._download_file(
|
|
122
|
+
endpoint="/tasks/download-mcap",
|
|
123
|
+
output_path=output_path,
|
|
124
|
+
params={"task_id": task_id},
|
|
125
|
+
show_progress=show_progress,
|
|
126
|
+
overwrite=overwrite,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
def download_bundle(self, task_id: str, output_path: str, show_progress: bool = True, overwrite: bool = False) -> str:
|
|
130
|
+
"""
|
|
131
|
+
Download bundle tar.gz file from Rome's cloud storage.
|
|
132
|
+
|
|
133
|
+
:param task_id: Unique task identifier.
|
|
134
|
+
:param output_path: Path where the file should be saved.
|
|
135
|
+
:param show_progress: Show download progress bar.
|
|
136
|
+
:param overwrite: Overwrite existing file.
|
|
137
|
+
:return: Path to the downloaded bundle file.
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
if not output_path.endswith(".tar.gz"):
|
|
141
|
+
raise ValueError("Output path must end with .tar.gz")
|
|
142
|
+
|
|
143
|
+
return self._download_file(
|
|
144
|
+
endpoint="/tasks/download-bundle",
|
|
145
|
+
output_path=output_path,
|
|
146
|
+
params={"task_id": task_id},
|
|
147
|
+
show_progress=show_progress,
|
|
148
|
+
overwrite=overwrite,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def list_arks(self) -> list[ArkReference]:
|
|
152
|
+
"""
|
|
153
|
+
List all Arks from Rome registry.
|
|
154
|
+
|
|
155
|
+
:return: List of ArkReference objects from remote registry.
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
response = self._send_request("GET", "/ark/list")
|
|
159
|
+
return [ArkReference(**ark) for ark in response.get("data", [])]
|
|
160
|
+
|
|
161
|
+
def get_ark(self, name: str, version: str) -> dict:
|
|
162
|
+
"""
|
|
163
|
+
Get Ark definition from Rome registry.
|
|
164
|
+
|
|
165
|
+
:param name: Name of the Ark.
|
|
166
|
+
:param version: Version of the Ark.
|
|
167
|
+
:return: Ark definition as dictionary.
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
response = self._send_request("GET", "/ark/get", json={"name": name, "version": version})
|
|
171
|
+
return response["ark"]
|
|
172
|
+
|
|
173
|
+
def download_ark_assets(self, name: str, version: str) -> bytes:
|
|
174
|
+
"""
|
|
175
|
+
Download Ark asset file from Rome registry.
|
|
176
|
+
|
|
177
|
+
:param name: Name of the Ark.
|
|
178
|
+
:param version: Version of the Ark.
|
|
179
|
+
:return: Asset file content as bytes.
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
response = self._send_request("GET", "/ark/download-assets", params={"name": name, "version": version}, return_content=True)
|
|
183
|
+
assert isinstance(response, bytes)
|
|
184
|
+
return response
|
|
185
|
+
|
|
186
|
+
def list_assets(self) -> list[AssetReference]:
|
|
187
|
+
"""
|
|
188
|
+
List all assets from Rome registry.
|
|
189
|
+
|
|
190
|
+
:return: List of AssetReference objects from remote registry.
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
response = self._send_request("GET", "/asset/list")
|
|
194
|
+
return [AssetReference(**asset) for asset in response.get("data", [])]
|
|
195
|
+
|
|
196
|
+
def get_asset_metadata(self, name: str, version: str) -> dict:
|
|
197
|
+
"""
|
|
198
|
+
Get metadata for a specific asset version.
|
|
199
|
+
|
|
200
|
+
:param name: Name of the asset.
|
|
201
|
+
:param version: Version of the asset.
|
|
202
|
+
:return: Asset metadata dictionary containing extension, file_size, and modified_time.
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
response = self._send_request("GET", "/asset/metadata", params={"name": name, "version": version})
|
|
206
|
+
return response["data"]
|
|
207
|
+
|
|
208
|
+
def download_asset(self, name: str, version: str, output_path: str, show_progress: bool = True) -> None:
|
|
209
|
+
"""
|
|
210
|
+
Download asset from Rome registry to local storage.
|
|
211
|
+
|
|
212
|
+
:param name: Name of the asset.
|
|
213
|
+
:param version: Version of the asset.
|
|
214
|
+
:param output_path: Path where the file should be saved.
|
|
215
|
+
:param show_progress: Show download progress bar.
|
|
216
|
+
"""
|
|
217
|
+
|
|
218
|
+
self._download_file(
|
|
219
|
+
endpoint="/asset/download",
|
|
220
|
+
output_path=output_path,
|
|
221
|
+
params={"name": name, "version": version},
|
|
222
|
+
show_progress=show_progress,
|
|
223
|
+
description=f"Downloading {name}:{version}",
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
@overload
|
|
227
|
+
def _send_request(
|
|
228
|
+
self,
|
|
229
|
+
method: str,
|
|
230
|
+
endpoint: str,
|
|
231
|
+
json: dict | None = None,
|
|
232
|
+
params: dict | None = None,
|
|
233
|
+
return_content: bool = False,
|
|
234
|
+
) -> dict: ...
|
|
235
|
+
|
|
236
|
+
@overload
|
|
237
|
+
def _send_request(
|
|
238
|
+
self,
|
|
239
|
+
method: str,
|
|
240
|
+
endpoint: str,
|
|
241
|
+
json: dict | None = None,
|
|
242
|
+
params: dict | None = None,
|
|
243
|
+
return_content: bool = True,
|
|
244
|
+
) -> bytes: ...
|
|
245
|
+
|
|
246
|
+
def _send_request(
|
|
247
|
+
self,
|
|
248
|
+
method: str,
|
|
249
|
+
endpoint: str,
|
|
250
|
+
json: dict | None = None,
|
|
251
|
+
params: dict | None = None,
|
|
252
|
+
return_content: bool = False,
|
|
253
|
+
) -> dict | bytes:
|
|
254
|
+
"""
|
|
255
|
+
Send a request to Rome API with standardized error handling.
|
|
256
|
+
|
|
257
|
+
:param method: HTTP method (GET, POST, etc.).
|
|
258
|
+
:param endpoint: API endpoint path.
|
|
259
|
+
:param json: Optional JSON payload.
|
|
260
|
+
:param params: Optional query parameters.
|
|
261
|
+
:param return_content: If True, return raw bytes content instead of JSON.
|
|
262
|
+
:return: Response JSON data or raw content bytes.
|
|
263
|
+
:raises RomeAuthError: If user is not authenticated.
|
|
264
|
+
:raises RomeError: If client error (4xx) occurs or JSON decode fails.
|
|
265
|
+
:raises RomeNetworkError: If network error or server error (5xx) occurs.
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
if not self._token:
|
|
269
|
+
raise RomeAuthError("User not authenticated")
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
url = f"{self._api_url}{endpoint}"
|
|
273
|
+
headers = {"Authorization": f"Bearer {self._token}", "Content-Type": "application/json"}
|
|
274
|
+
response = requests.request(method, url, json=json, params=params, headers=headers, timeout=30)
|
|
275
|
+
self._check_response_errors(response)
|
|
276
|
+
|
|
277
|
+
if return_content:
|
|
278
|
+
return response.content
|
|
279
|
+
|
|
280
|
+
try:
|
|
281
|
+
return response.json()
|
|
282
|
+
except requests.exceptions.JSONDecodeError as e:
|
|
283
|
+
raise RomeError(f"Invalid JSON response: {e}") from e
|
|
284
|
+
except requests.exceptions.RequestException as e:
|
|
285
|
+
raise RomeNetworkError(f"Network error: {e}") from e
|
|
286
|
+
|
|
287
|
+
def _download_file(
|
|
288
|
+
self,
|
|
289
|
+
endpoint: str,
|
|
290
|
+
output_path: str,
|
|
291
|
+
params: dict | None = None,
|
|
292
|
+
show_progress: bool = True,
|
|
293
|
+
overwrite: bool = True,
|
|
294
|
+
description: str | None = None,
|
|
295
|
+
) -> str:
|
|
296
|
+
"""
|
|
297
|
+
Download a file from Rome's cloud storage with streaming.
|
|
298
|
+
|
|
299
|
+
:param endpoint: API endpoint path.
|
|
300
|
+
:param output_path: Path where the file should be saved.
|
|
301
|
+
:param params: Optional query parameters.
|
|
302
|
+
:param show_progress: Show download progress bar.
|
|
303
|
+
:param overwrite: Overwrite existing file.
|
|
304
|
+
:param description: Optional description for progress bar.
|
|
305
|
+
:return: Path to the downloaded file.
|
|
306
|
+
:raises RuntimeError: If file exists and overwrite is False.
|
|
307
|
+
:raises RomeAuthError: If user is not authenticated.
|
|
308
|
+
:raises RomeError: If client error (4xx) occurs.
|
|
309
|
+
:raises RomeNetworkError: If network error or server error (5xx) occurs.
|
|
310
|
+
"""
|
|
311
|
+
|
|
312
|
+
if not overwrite and Path(output_path).exists():
|
|
313
|
+
raise RuntimeError(f"{output_path} already exists (pass overwrite=True to overwrite)")
|
|
314
|
+
if not self._token:
|
|
315
|
+
raise RomeAuthError("User not authenticated")
|
|
316
|
+
|
|
317
|
+
try:
|
|
318
|
+
url = f"{self._api_url}{endpoint}"
|
|
319
|
+
headers = {"Authorization": f"Bearer {self._token}"}
|
|
320
|
+
response = requests.get(url, params=params, headers=headers, stream=True, timeout=None)
|
|
321
|
+
self._check_response_errors(response)
|
|
322
|
+
|
|
323
|
+
with (
|
|
324
|
+
open(output_path, "wb") as f,
|
|
325
|
+
tqdm(
|
|
326
|
+
total=int(response.headers.get("content-length", 0)),
|
|
327
|
+
unit="B",
|
|
328
|
+
unit_scale=True,
|
|
329
|
+
unit_divisor=FILE_TRANSFER_UNIT_DIVISOR,
|
|
330
|
+
desc=description or f"Downloading {Path(output_path).name}",
|
|
331
|
+
disable=not show_progress,
|
|
332
|
+
) as pbar,
|
|
333
|
+
):
|
|
334
|
+
for chunk in response.iter_content(chunk_size=DOWNLOAD_CHUNK_SIZE):
|
|
335
|
+
if chunk:
|
|
336
|
+
f.write(chunk)
|
|
337
|
+
pbar.update(len(chunk))
|
|
338
|
+
|
|
339
|
+
return output_path
|
|
340
|
+
except requests.exceptions.RequestException as e:
|
|
341
|
+
raise RomeNetworkError(f"Network error: {e}") from e
|
|
342
|
+
|
|
343
|
+
def _upload_file_stream(self, file_path: Path, show_progress: bool = True) -> Generator[bytes, None, None]:
|
|
344
|
+
"""
|
|
345
|
+
Generator for streaming file upload with progress tracking.
|
|
346
|
+
|
|
347
|
+
:param file_path: Path to the file to upload.
|
|
348
|
+
:param show_progress: Show upload progress bar.
|
|
349
|
+
:return: Generator yielding file chunks as bytes.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
with (
|
|
353
|
+
tqdm(
|
|
354
|
+
total=file_path.stat().st_size,
|
|
355
|
+
unit="B",
|
|
356
|
+
unit_scale=True,
|
|
357
|
+
unit_divisor=FILE_TRANSFER_UNIT_DIVISOR,
|
|
358
|
+
desc=f"Uploading {file_path.name}",
|
|
359
|
+
disable=not show_progress,
|
|
360
|
+
) as pbar,
|
|
361
|
+
open(file_path, "rb") as f,
|
|
362
|
+
):
|
|
363
|
+
while data := f.read(UPLOAD_CHUNK_SIZE):
|
|
364
|
+
pbar.update(len(data))
|
|
365
|
+
yield data
|
|
366
|
+
|
|
367
|
+
def _upload_file(
|
|
368
|
+
self,
|
|
369
|
+
endpoint: str,
|
|
370
|
+
task_id: str,
|
|
371
|
+
file_path: str,
|
|
372
|
+
content_type: str,
|
|
373
|
+
show_progress: bool,
|
|
374
|
+
) -> None:
|
|
375
|
+
"""
|
|
376
|
+
Upload a file to Rome's cloud storage using streaming.
|
|
377
|
+
|
|
378
|
+
:param endpoint: API endpoint path.
|
|
379
|
+
:param task_id: Unique task identifier.
|
|
380
|
+
:param file_path: Path to the file to upload.
|
|
381
|
+
:param content_type: MIME type of the file.
|
|
382
|
+
:param show_progress: Show upload progress bar.
|
|
383
|
+
:raises RomeAuthError: If user is not authenticated.
|
|
384
|
+
:raises RomeError: If client error (4xx) occurs.
|
|
385
|
+
:raises RomeNetworkError: If network error or server error (5xx) occurs.
|
|
386
|
+
"""
|
|
387
|
+
|
|
388
|
+
if not self._token:
|
|
389
|
+
raise RomeAuthError("User not authenticated")
|
|
390
|
+
|
|
391
|
+
try:
|
|
392
|
+
url = f"{self._api_url}{endpoint}"
|
|
393
|
+
headers = {"Authorization": f"Bearer {self._token}", "Content-Type": content_type}
|
|
394
|
+
stream_data = self._upload_file_stream(Path(file_path), show_progress)
|
|
395
|
+
with httpx.Client(timeout=None) as client:
|
|
396
|
+
response = client.post(url, params={"task_id": task_id}, content=stream_data, headers=headers)
|
|
397
|
+
self._check_response_errors(response)
|
|
398
|
+
except httpx.HTTPError as e:
|
|
399
|
+
raise RomeNetworkError(f"Network error: {e}") from e
|
|
400
|
+
|
|
401
|
+
def _check_response_errors(self, response: Response | httpx.Response) -> None:
|
|
402
|
+
"""
|
|
403
|
+
Check response for HTTP errors and raise appropriate exceptions.
|
|
404
|
+
|
|
405
|
+
:param response: HTTP response object from requests or httpx.
|
|
406
|
+
:raises RomeError: If client error (4xx) occurs.
|
|
407
|
+
:raises RomeNetworkError: If server error (5xx) occurs.
|
|
408
|
+
"""
|
|
409
|
+
|
|
410
|
+
if response.status_code >= 400:
|
|
411
|
+
error_message = self._extract_error_message(response)
|
|
412
|
+
if response.status_code < 500:
|
|
413
|
+
raise RomeError(error_message)
|
|
414
|
+
raise RomeNetworkError(f"Server error: {error_message}")
|
|
415
|
+
|
|
416
|
+
def _extract_error_message(self, response: Response | httpx.Response) -> str:
|
|
417
|
+
"""
|
|
418
|
+
Extract error message from response JSON or return generic message.
|
|
419
|
+
|
|
420
|
+
:param response: HTTP response object from requests or httpx.
|
|
421
|
+
:return: Error message string from response or generic HTTP status message.
|
|
422
|
+
"""
|
|
423
|
+
|
|
424
|
+
try:
|
|
425
|
+
data = response.json()
|
|
426
|
+
if isinstance(data, dict) and "message" in data:
|
|
427
|
+
return data["message"]
|
|
428
|
+
except Exception:
|
|
429
|
+
pass
|
|
430
|
+
return f"HTTP {response.status_code}"
|
common/rome/error.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class RomeError(Exception):
|
|
2
|
+
"""
|
|
3
|
+
Base error for Rome API operations.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class RomeAuthError(RomeError):
|
|
8
|
+
"""
|
|
9
|
+
Authentication error when interacting with Rome API.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RomeNetworkError(RomeError):
|
|
14
|
+
"""
|
|
15
|
+
Network error when interacting with Rome API.
|
|
16
|
+
"""
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from common.session.sim import (
|
|
2
|
+
AddAsset,
|
|
3
|
+
GetLocalPose,
|
|
4
|
+
GetPrimAttribute,
|
|
5
|
+
GetWorldPose,
|
|
6
|
+
PrimAttributeValue,
|
|
7
|
+
PrimInfo,
|
|
8
|
+
QueryScene,
|
|
9
|
+
RpcCall,
|
|
10
|
+
RpcError,
|
|
11
|
+
RpcResponse,
|
|
12
|
+
SceneQueryResponse,
|
|
13
|
+
SceneTarget,
|
|
14
|
+
SetLocalPose,
|
|
15
|
+
SetPrimAttribute,
|
|
16
|
+
SetWorldPose,
|
|
17
|
+
SimulationInfo,
|
|
18
|
+
SimulationState,
|
|
19
|
+
SimulationTime,
|
|
20
|
+
Step,
|
|
21
|
+
ToggleUi,
|
|
22
|
+
)
|
|
23
|
+
from common.session.views.camera import DistortionModel
|
|
24
|
+
from common.session.views.geometry import GeometryType, MeshApproximation
|
|
25
|
+
from common.session.views.light import LightType
|
|
26
|
+
from common.session.views.rigid_body import BodyType
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"AddAsset",
|
|
30
|
+
"BodyType",
|
|
31
|
+
"DistortionModel",
|
|
32
|
+
"GeometryType",
|
|
33
|
+
"GetLocalPose",
|
|
34
|
+
"GetPrimAttribute",
|
|
35
|
+
"GetWorldPose",
|
|
36
|
+
"LightType",
|
|
37
|
+
"MeshApproximation",
|
|
38
|
+
"PrimAttributeValue",
|
|
39
|
+
"PrimInfo",
|
|
40
|
+
"QueryScene",
|
|
41
|
+
"RpcCall",
|
|
42
|
+
"RpcError",
|
|
43
|
+
"RpcResponse",
|
|
44
|
+
"SceneQueryResponse",
|
|
45
|
+
"SceneTarget",
|
|
46
|
+
"SetLocalPose",
|
|
47
|
+
"SetPrimAttribute",
|
|
48
|
+
"SetWorldPose",
|
|
49
|
+
"SimulationInfo",
|
|
50
|
+
"SimulationState",
|
|
51
|
+
"SimulationTime",
|
|
52
|
+
"Step",
|
|
53
|
+
"ToggleUi",
|
|
54
|
+
]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SessionEnvironment(str, Enum):
|
|
6
|
+
"""
|
|
7
|
+
The environment of Session.
|
|
8
|
+
|
|
9
|
+
:cvar ANTIOCH_CLOUD: The Antioch Cloud environment.
|
|
10
|
+
:cvar LOCAL: The local environment.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
ANTIOCH_CLOUD = "antioch_cloud"
|
|
14
|
+
LOCAL = "local"
|
|
15
|
+
|
|
16
|
+
def __str__(self) -> str:
|
|
17
|
+
return self.value
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def check(cls) -> "SessionEnvironment":
|
|
21
|
+
"""
|
|
22
|
+
Check the session environment by checking the KUBERNETES_SERVICE_HOST
|
|
23
|
+
environment variable.
|
|
24
|
+
|
|
25
|
+
:return: The session environment.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
if os.environ.get("KUBERNETES_SERVICE_HOST") is not None:
|
|
29
|
+
return cls.ANTIOCH_CLOUD
|
|
30
|
+
else:
|
|
31
|
+
return cls.LOCAL
|