Skip to content

Commit dd2819e

Browse files
committed
changes
1 parent 55ce9f5 commit dd2819e

3 files changed

Lines changed: 39 additions & 114 deletions

File tree

tests/unit/test_deploy.py

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -126,96 +126,20 @@ def test_deploy_as_static_space_uploads_resolved_frontend(tmp_path, monkeypatch)
126126
),
127127
)
128128

129-
deploy.deploy_as_static_space(
130-
"abidlabs/static-space",
131-
None,
132-
"demo-project",
133-
frontend_dir=frontend_dir,
134-
)
135-
136-
assert any(
137-
call["folder_path"] == str(frontend_dir) for call in fake_api.uploaded_folders
138-
)
139-
140-
141-
def test_deploy_as_static_space_does_not_embed_hf_token(tmp_path, monkeypatch):
142-
frontend_dir = tmp_path / "custom-static"
143-
frontend_dir.mkdir()
144-
(frontend_dir / "index.html").write_text("<!doctype html>")
145-
146-
fake_api = _FakeHfApi()
147-
monkeypatch.setattr(deploy.huggingface_hub, "HfApi", lambda: fake_api)
148-
monkeypatch.setattr(deploy.huggingface_hub, "create_repo", lambda *a, **k: None)
149-
monkeypatch.setattr(
150-
deploy,
151-
"resolve_frontend_dir",
152-
lambda frontend_dir=None, announce=False: ResolvedFrontend(
153-
path=frontend_dir.resolve(),
154-
source="argument",
155-
is_custom=True,
156-
),
157-
)
158-
159-
deploy.deploy_as_static_space(
160-
"abidlabs/static-space",
161-
None,
162-
"demo-project",
163-
bucket_id="abidlabs/static-bucket",
164-
private=False,
165-
hf_token="hf_should_not_be_serialized",
166-
frontend_dir=frontend_dir,
167-
)
168-
169-
config_upload = next(
170-
item for item in fake_api.uploaded_files if item["path_in_repo"] == "config.json"
171-
)
172-
config = json.loads(config_upload["payload"])
173-
assert "hf_token" not in config
174-
175-
176-
def test_deploy_as_static_space_rejects_private(monkeypatch):
177-
monkeypatch.setattr(
178-
deploy.huggingface_hub,
179-
"HfApi",
180-
lambda: pytest.fail("HfApi should not be constructed"),
181-
)
182-
183-
with pytest.raises(ValueError, match="private static Trackio Space"):
129+
with pytest.warns(UserWarning, match="private=True is ignored"):
184130
deploy.deploy_as_static_space(
185131
"abidlabs/static-space",
186132
None,
187133
"demo-project",
188134
private=True,
189-
hf_token="hf_should_not_be_used",
135+
frontend_dir=frontend_dir,
190136
)
191137

192-
193-
def test_sync_static_rejects_private_before_network(monkeypatch):
194-
monkeypatch.setattr(
195-
deploy.huggingface_hub,
196-
"HfApi",
197-
lambda: pytest.fail("HfApi should not be constructed"),
138+
assert any(
139+
call["folder_path"] == str(frontend_dir) for call in fake_api.uploaded_folders
198140
)
199-
200-
with pytest.raises(ValueError, match="private static Trackio Space"):
201-
deploy.sync(
202-
project="demo-project",
203-
space_id="abidlabs/static-space",
204-
sdk="static",
205-
private=True,
206-
)
207-
208-
209-
def test_freeze_rejects_private_before_network(monkeypatch):
210-
monkeypatch.setattr(
211-
deploy.huggingface_hub,
212-
"HfApi",
213-
lambda: pytest.fail("HfApi should not be constructed"),
141+
config_upload = next(
142+
item for item in fake_api.uploaded_files if item["path_in_repo"] == "config.json"
214143
)
215-
216-
with pytest.raises(ValueError, match="private static Trackio Space"):
217-
deploy.freeze(
218-
space_id="abidlabs/source-space",
219-
project="demo-project",
220-
private=True,
221-
)
144+
config = json.loads(config_upload["payload"])
145+
assert config["private"] is False

trackio/deploy.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tempfile
88
import threading
99
import time
10+
import warnings
1011
from collections import Counter
1112
from importlib.resources import files
1213
from pathlib import Path
@@ -50,17 +51,6 @@
5051
_RESET = "\033[0m"
5152

5253

53-
def _raise_if_private_static_requested(action: str, private: bool | None) -> None:
54-
if private is True:
55-
raise ValueError(
56-
f"Cannot {action} a private static Trackio Space. Static Spaces run "
57-
"entirely in the browser, so reading private datasets or buckets would "
58-
"require exposing a Hugging Face token to viewers. Use sdk='gradio' for "
59-
"a private dashboard, or omit private=True to create a public static "
60-
"snapshot."
61-
)
62-
63-
6454
def raise_if_space_is_frozen_for_logging(space_id: str) -> None:
6555
try:
6656
info = huggingface_hub.HfApi().space_info(space_id)
@@ -913,7 +903,14 @@ def deploy_as_static_space(
913903
if on_spaces():
914904
return
915905

916-
_raise_if_private_static_requested("deploy", private)
906+
if private is True:
907+
warnings.warn(
908+
"private=True is ignored for static Trackio Spaces. Static Spaces run "
909+
"entirely in the browser, so their snapshot data must be public. Use "
910+
"sdk='gradio' for a private dashboard.",
911+
stacklevel=2,
912+
)
913+
private = False
917914
hf_api = huggingface_hub.HfApi()
918915

919916
try:
@@ -1049,8 +1046,14 @@ def sync(
10491046
"""
10501047
if sdk not in ("gradio", "static"):
10511048
raise ValueError(f"sdk must be 'gradio' or 'static', got '{sdk}'")
1052-
if sdk == "static":
1053-
_raise_if_private_static_requested("sync", private)
1049+
if sdk == "static" and private is True:
1050+
warnings.warn(
1051+
"private=True is ignored for static Trackio Spaces. Static Spaces run "
1052+
"entirely in the browser, so their snapshot data must be public. Use "
1053+
"sdk='gradio' for a private dashboard.",
1054+
stacklevel=2,
1055+
)
1056+
private = False
10541057
bucket_id_was_explicit = bucket_id is not None
10551058

10561059
if space_id is None:
@@ -1184,7 +1187,14 @@ def freeze(
11841187
Returns:
11851188
`str`: The Space ID of the newly created static Space.
11861189
"""
1187-
_raise_if_private_static_requested("freeze", private)
1190+
if private is True:
1191+
warnings.warn(
1192+
"private=True is ignored for frozen static Trackio Spaces. Static Spaces "
1193+
"run entirely in the browser, so their snapshot data must be public. Use "
1194+
"a Gradio Space if the frozen dashboard must stay private.",
1195+
stacklevel=2,
1196+
)
1197+
private = False
11881198
space_id, _, _ = preprocess_space_and_dataset_ids(space_id, None, None)
11891199

11901200
try:

trackio/frontend/src/lib/staticApi.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ function resolveUrl(filename) {
1515
return `https://huggingface.co/datasets/${config.dataset_id}/resolve/main/${filename}`;
1616
}
1717

18-
function authHeaders() {
19-
return {};
20-
}
21-
2218
export async function initialize(cfg) {
2319
config = cfg;
2420
}
@@ -38,28 +34,25 @@ export function getReadOnlySource() {
3834

3935
async function getMetricsData() {
4036
if (metricsData) return metricsData;
41-
metricsData = await readParquet(resolveUrl("metrics.parquet"), authHeaders());
37+
metricsData = await readParquet(resolveUrl("metrics.parquet"));
4238
return metricsData;
4339
}
4440

4541
async function getSystemData() {
4642
if (systemData) return systemData;
47-
systemData = await readParquet(
48-
resolveUrl("aux/system_metrics.parquet"),
49-
authHeaders(),
50-
);
43+
systemData = await readParquet(resolveUrl("aux/system_metrics.parquet"));
5144
return systemData;
5245
}
5346

5447
async function getConfigsData() {
5548
if (configsData) return configsData;
56-
configsData = await readParquet(resolveUrl("aux/configs.parquet"), authHeaders());
49+
configsData = await readParquet(resolveUrl("aux/configs.parquet"));
5750
return configsData;
5851
}
5952

6053
async function getRunsJson() {
6154
if (runsData) return runsData;
62-
const resp = await fetch(resolveUrl("runs.json"), { headers: authHeaders() });
55+
const resp = await fetch(resolveUrl("runs.json"));
6356
if (!resp.ok) {
6457
runsData = [];
6558
return runsData;
@@ -70,7 +63,7 @@ async function getRunsJson() {
7063

7164
async function getSettingsJson() {
7265
if (settingsData) return settingsData;
73-
const resp = await fetch(resolveUrl("settings.json"), { headers: authHeaders() });
66+
const resp = await fetch(resolveUrl("settings.json"));
7467
if (!resp.ok) {
7568
settingsData = {};
7669
return settingsData;
@@ -432,7 +425,6 @@ export async function getProjectFiles() {
432425
if (config.bucket_id) {
433426
const resp = await fetch(
434427
`https://huggingface.co/api/buckets/${config.bucket_id}/tree?prefix=media/files/&recursive=true`,
435-
{ headers: authHeaders() },
436428
);
437429
if (!resp.ok) {
438430
fileListData = [];
@@ -450,7 +442,6 @@ export async function getProjectFiles() {
450442

451443
const resp = await fetch(
452444
`https://huggingface.co/api/datasets/${config.dataset_id}`,
453-
{ headers: authHeaders() },
454445
);
455446
if (!resp.ok) {
456447
fileListData = [];
@@ -494,7 +485,7 @@ export async function fetchMediaBlob(path) {
494485
const url = resolveUrl(`media/${relative}`);
495486
if (blobCache.has(url)) return blobCache.get(url);
496487

497-
const resp = await fetch(url, { headers: authHeaders() });
488+
const resp = await fetch(url);
498489
if (!resp.ok) return url;
499490
const blob = await resp.blob();
500491
const blobUrl = URL.createObjectURL(blob);

0 commit comments

Comments
 (0)