|
24 | 24 |
|
25 | 25 | import trackio |
26 | 26 | from trackio.bucket_storage import create_bucket_if_not_exists, upload_project_to_bucket |
27 | | -from trackio.space_volumes import ( |
28 | | - attach_bucket_volume, |
29 | | -) |
30 | 27 | from trackio.sqlite_storage import SQLiteStorage |
31 | 28 | from trackio.utils import ( |
32 | 29 | MEDIA_DIR, |
@@ -233,14 +230,28 @@ def deploy_as_space( |
233 | 230 | if hf_token := huggingface_hub.utils.get_token(): |
234 | 231 | huggingface_hub.add_space_secret(space_id, "HF_TOKEN", hf_token) |
235 | 232 | if bucket_id is not None: |
236 | | - changed = attach_bucket_volume( |
237 | | - space_id, |
238 | | - bucket_id, |
239 | | - mount_path="/data", |
| 233 | + from huggingface_hub import Volume |
| 234 | + |
| 235 | + hf_api = huggingface_hub.HfApi() |
| 236 | + runtime = hf_api.get_space_runtime(space_id) |
| 237 | + existing = list(runtime.volumes) if runtime.volumes else [] |
| 238 | + already_mounted = any( |
| 239 | + v.type == "bucket" and v.source == bucket_id and v.mount_path == "/data" |
| 240 | + for v in existing |
240 | 241 | ) |
241 | | - huggingface_hub.add_space_variable(space_id, "TRACKIO_DIR", "/data/trackio") |
242 | | - if changed: |
| 242 | + if not already_mounted: |
| 243 | + non_bucket = [ |
| 244 | + v |
| 245 | + for v in existing |
| 246 | + if not (v.type == "bucket" and v.source == bucket_id) |
| 247 | + ] |
| 248 | + hf_api.set_space_volumes( |
| 249 | + space_id, |
| 250 | + non_bucket |
| 251 | + + [Volume(type="bucket", source=bucket_id, mount_path="/data")], |
| 252 | + ) |
243 | 253 | print(f"* Attached bucket {bucket_id} at '/data'") |
| 254 | + huggingface_hub.add_space_variable(space_id, "TRACKIO_DIR", "/data/trackio") |
244 | 255 | elif dataset_id is not None: |
245 | 256 | huggingface_hub.add_space_variable(space_id, "TRACKIO_DATASET_ID", dataset_id) |
246 | 257 | if logo_light_url := os.environ.get("TRACKIO_LOGO_LIGHT_URL"): |
|
0 commit comments