figpack 0.3.18__tar.gz → 0.3.20__tar.gz
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.
- {figpack-0.3.18/figpack.egg-info → figpack-0.3.20}/PKG-INFO +1 -1
- {figpack-0.3.18 → figpack-0.3.20}/figpack/__init__.py +1 -1
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_upload_bundle.py +216 -75
- {figpack-0.3.18 → figpack-0.3.20/figpack.egg-info}/PKG-INFO +1 -1
- {figpack-0.3.18 → figpack-0.3.20}/pyproject.toml +1 -1
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_upload_bundle.py +17 -11
- {figpack-0.3.18 → figpack-0.3.20}/LICENSE +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/MANIFEST.in +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/README.md +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/cli.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/__init__.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_bundle_utils.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_figure_utils.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_file_handler.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_patch_figure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_revert_patch_figure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_save_figure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_server_manager.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_show_view.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_view_figure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_zarr_consolidate.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/config.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/extension_view.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/figpack_extension.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/figpack_view.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/core/zarr.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/extensions.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/index-CSMGUquF.js +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/index-GPjx4QpG.css +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/neurosift-logo-CLsuwLMO.png +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/index.html +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/utils/__init__.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Box.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/CaptionedView.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/DataFrame.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Gallery.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/GalleryItem.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Iframe.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Image.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/LayoutItem.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Markdown.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MatplotlibFigure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MountainLayout.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MountainLayoutItem.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MultiChannelTimeseries.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/PlotlyExtension.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/__init__.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/_plotly_extension.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/plotly_view.js +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Spectrogram.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Splitter.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/TabLayout.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/TabLayoutItem.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/TimeseriesGraph.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/VerticalLayout.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/VerticalLayoutItem.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack/views/__init__.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack-serve/worker/container/app.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/SOURCES.txt +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/dependency_links.txt +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/entry_points.txt +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/requires.txt +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/top_level.txt +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/setup.cfg +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_box.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_cli.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_core.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_dataframe.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_extension_system.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_figpack_view.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_file_handler.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_gallery.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_image.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_markdown.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_matplotlib_figure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_multichannel_timeseries.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_plotly_figure.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_server_manager.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_spectrogram.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_splitter.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_tablayout.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_timeseries_graph.py +0 -0
- {figpack-0.3.18 → figpack-0.3.20}/tests/test_view_figure.py +0 -0
|
@@ -15,17 +15,17 @@ from .config import FIGPACK_API_BASE_URL, FIGPACK_BUCKET
|
|
|
15
15
|
thisdir = pathlib.Path(__file__).parent.resolve()
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
"""
|
|
20
|
-
Get signed URLs for a batch of files
|
|
18
|
+
MAX_WORKERS_FOR_UPLOAD = 16
|
|
21
19
|
|
|
22
|
-
Args:
|
|
23
|
-
figure_url: The figure URL
|
|
24
|
-
files_batch: List of tuples (relative_path, file_path)
|
|
25
|
-
api_key: API key for authentication
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
def _get_upload_info(figure_url: str, files_batch: list, api_key: str) -> dict:
|
|
22
|
+
"""
|
|
23
|
+
Get upload info for a batch of files from the API.
|
|
24
|
+
|
|
25
|
+
Returns a dict with:
|
|
26
|
+
- "mode": "server-signed" or "client-signed"
|
|
27
|
+
- For server-signed: "signedUrls" mapping relative_path -> signed_url
|
|
28
|
+
- For client-signed: "bucket" info and "files" mapping relative_path -> S3 key
|
|
29
29
|
"""
|
|
30
30
|
# Prepare batch request
|
|
31
31
|
files_data = []
|
|
@@ -51,26 +51,89 @@ def _get_batch_signed_urls(figure_url: str, files_batch: list, api_key: str) ->
|
|
|
51
51
|
try:
|
|
52
52
|
error_data = response.json()
|
|
53
53
|
error_msg = error_data.get("message", "Unknown error")
|
|
54
|
-
except:
|
|
54
|
+
except Exception:
|
|
55
55
|
error_msg = f"HTTP {response.status_code}"
|
|
56
|
-
raise Exception(f"Failed to get
|
|
56
|
+
raise Exception(f"Failed to get upload info for batch: {error_msg}")
|
|
57
57
|
|
|
58
58
|
response_data = response.json()
|
|
59
59
|
if not response_data.get("success"):
|
|
60
60
|
raise Exception(
|
|
61
|
-
f"Failed to get
|
|
61
|
+
f"Failed to get upload info for batch: {response_data.get('message', 'Unknown error')}"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return response_data
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _get_upload_mode(figure_url: str, files_batch: list, api_key: str) -> dict:
|
|
68
|
+
"""
|
|
69
|
+
Get upload info and determine upload mode for a batch.
|
|
70
|
+
|
|
71
|
+
Returns the raw response_data dict from the API.
|
|
72
|
+
"""
|
|
73
|
+
return _get_upload_info(figure_url, files_batch, api_key)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _upload_batch_client_signed(
|
|
77
|
+
response_data: dict, files_batch: list, max_workers: int = MAX_WORKERS_FOR_UPLOAD
|
|
78
|
+
) -> int:
|
|
79
|
+
"""
|
|
80
|
+
Upload a batch of files directly using boto3 (client-signed mode).
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
response_data: The response from _get_upload_info containing bucket info and keys
|
|
84
|
+
files_batch: List of tuples (relative_path, file_path)
|
|
85
|
+
max_workers: Number of concurrent upload threads
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
int: Number of files uploaded
|
|
89
|
+
"""
|
|
90
|
+
try:
|
|
91
|
+
import boto3
|
|
92
|
+
except ImportError:
|
|
93
|
+
raise ImportError(
|
|
94
|
+
"boto3 is required for uploading to buckets with client-managed credentials. "
|
|
95
|
+
"Install it with: pip install boto3"
|
|
62
96
|
)
|
|
63
97
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
98
|
+
bucket_info = response_data.get("bucket", {})
|
|
99
|
+
native_bucket_name = bucket_info["nativeBucketName"]
|
|
100
|
+
region = bucket_info.get("region", "us-east-1")
|
|
101
|
+
|
|
102
|
+
files_info = response_data.get("files", [])
|
|
103
|
+
if not files_info:
|
|
104
|
+
raise Exception("No files returned for client-signed batch")
|
|
105
|
+
|
|
106
|
+
# Build key lookup from API response
|
|
107
|
+
key_map = {f["relativePath"]: f["key"] for f in files_info}
|
|
108
|
+
|
|
109
|
+
s3_client = boto3.client("s3", region_name=region)
|
|
110
|
+
|
|
111
|
+
def _upload_one(rel_path: str, file_path: pathlib.Path) -> str:
|
|
112
|
+
key = key_map.get(rel_path)
|
|
113
|
+
if not key:
|
|
114
|
+
raise Exception(f"No S3 key returned for {rel_path}")
|
|
115
|
+
content_type = _determine_content_type(rel_path)
|
|
116
|
+
with open(file_path, "rb") as f:
|
|
117
|
+
s3_client.put_object(
|
|
118
|
+
Bucket=native_bucket_name,
|
|
119
|
+
Key=key,
|
|
120
|
+
Body=f,
|
|
121
|
+
ContentType=content_type,
|
|
122
|
+
)
|
|
123
|
+
return rel_path
|
|
124
|
+
|
|
125
|
+
uploaded = 0
|
|
126
|
+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
127
|
+
future_to_file = {}
|
|
128
|
+
for rel_path, file_path in files_batch:
|
|
129
|
+
future = executor.submit(_upload_one, rel_path, file_path)
|
|
130
|
+
future_to_file[future] = rel_path
|
|
67
131
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
signed_urls_map[item["relativePath"]] = item["signedUrl"]
|
|
132
|
+
for future in as_completed(future_to_file):
|
|
133
|
+
future.result() # raises on error
|
|
134
|
+
uploaded += 1
|
|
72
135
|
|
|
73
|
-
return
|
|
136
|
+
return uploaded
|
|
74
137
|
|
|
75
138
|
|
|
76
139
|
def _upload_single_file_with_signed_url(
|
|
@@ -102,11 +165,11 @@ def _upload_single_file_with_signed_url(
|
|
|
102
165
|
signed_url, data=f, headers={"Content-Type": content_type}
|
|
103
166
|
)
|
|
104
167
|
|
|
105
|
-
if upload_response.
|
|
168
|
+
if 200 <= upload_response.status_code < 300:
|
|
106
169
|
return relative_path
|
|
107
170
|
|
|
108
171
|
last_exception = Exception(
|
|
109
|
-
f"Failed to upload {relative_path} to signed URL: HTTP {upload_response.status_code}"
|
|
172
|
+
f"Failed to upload {relative_path} to signed URL: HTTP {upload_response.status_code} - {upload_response.text[:500]}"
|
|
110
173
|
)
|
|
111
174
|
except Exception as e:
|
|
112
175
|
last_exception = e
|
|
@@ -125,9 +188,6 @@ def _upload_single_file_with_signed_url(
|
|
|
125
188
|
raise last_exception
|
|
126
189
|
|
|
127
190
|
|
|
128
|
-
MAX_WORKERS_FOR_UPLOAD = 16
|
|
129
|
-
|
|
130
|
-
|
|
131
191
|
def _create_or_get_figure(
|
|
132
192
|
api_key: Optional[str],
|
|
133
193
|
total_files: Optional[int] = None,
|
|
@@ -197,7 +257,10 @@ def _create_or_get_figure(
|
|
|
197
257
|
|
|
198
258
|
def _finalize_figure(figure_url: str, api_key: str) -> dict:
|
|
199
259
|
"""
|
|
200
|
-
Finalize a figure upload
|
|
260
|
+
Finalize a figure upload.
|
|
261
|
+
|
|
262
|
+
If the bucket uses client-managed credentials, this will also upload
|
|
263
|
+
figpack.json to S3 using boto3.
|
|
201
264
|
|
|
202
265
|
Returns:
|
|
203
266
|
dict: Figure information from the API
|
|
@@ -219,7 +282,7 @@ def _finalize_figure(figure_url: str, api_key: str) -> dict:
|
|
|
219
282
|
try:
|
|
220
283
|
error_data = response.json()
|
|
221
284
|
error_msg = error_data.get("message", "Unknown error")
|
|
222
|
-
except:
|
|
285
|
+
except Exception:
|
|
223
286
|
error_msg = f"HTTP {response.status_code}"
|
|
224
287
|
raise Exception(f"Failed to finalize figure {figure_url}: {error_msg}")
|
|
225
288
|
|
|
@@ -229,9 +292,53 @@ def _finalize_figure(figure_url: str, api_key: str) -> dict:
|
|
|
229
292
|
f"Failed to finalize figure {figure_url}: {response_data.get('message', 'Unknown error')}"
|
|
230
293
|
)
|
|
231
294
|
|
|
295
|
+
# If the server returned figpackJson, upload it client-side
|
|
296
|
+
figpack_json = response_data.get("figpackJson")
|
|
297
|
+
bucket_info = response_data.get("bucket")
|
|
298
|
+
if figpack_json and bucket_info:
|
|
299
|
+
_upload_figpack_json_client_side(figure_url, figpack_json, bucket_info)
|
|
300
|
+
|
|
232
301
|
return response_data
|
|
233
302
|
|
|
234
303
|
|
|
304
|
+
def _upload_figpack_json_client_side(
|
|
305
|
+
figure_url: str, figpack_json: dict, bucket_info: dict
|
|
306
|
+
) -> None:
|
|
307
|
+
"""
|
|
308
|
+
Upload figpack.json to S3 using boto3 (for client-managed credential buckets).
|
|
309
|
+
"""
|
|
310
|
+
try:
|
|
311
|
+
import boto3
|
|
312
|
+
except ImportError:
|
|
313
|
+
raise ImportError(
|
|
314
|
+
"boto3 is required for uploading to buckets with client-managed credentials. "
|
|
315
|
+
"Install it with: pip install boto3"
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
native_bucket_name = bucket_info["nativeBucketName"]
|
|
319
|
+
region = bucket_info.get("region", "us-east-1")
|
|
320
|
+
bucket_base_url = bucket_info["bucketBaseUrl"]
|
|
321
|
+
|
|
322
|
+
# Derive the S3 key for figpack.json
|
|
323
|
+
prefix = f"{bucket_base_url}/"
|
|
324
|
+
figure_url_clean = figure_url
|
|
325
|
+
if figure_url_clean.endswith("/index.html"):
|
|
326
|
+
figure_url_clean = figure_url_clean[: -len("/index.html")]
|
|
327
|
+
if not figure_url_clean.startswith(prefix):
|
|
328
|
+
raise Exception(
|
|
329
|
+
f"Figure URL {figure_url_clean} does not start with bucket base URL {prefix}"
|
|
330
|
+
)
|
|
331
|
+
key = figure_url_clean[len(prefix) :] + "/figpack.json"
|
|
332
|
+
|
|
333
|
+
s3_client = boto3.client("s3", region_name=region)
|
|
334
|
+
s3_client.put_object(
|
|
335
|
+
Bucket=native_bucket_name,
|
|
336
|
+
Key=key,
|
|
337
|
+
Body=json.dumps(figpack_json, indent=2),
|
|
338
|
+
ContentType="application/json",
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
|
|
235
342
|
def _upload_bundle(
|
|
236
343
|
tmpdir: str,
|
|
237
344
|
api_key: Optional[str],
|
|
@@ -299,6 +406,13 @@ def _upload_bundle(
|
|
|
299
406
|
uploaded_count = 0
|
|
300
407
|
count_lock = threading.Lock()
|
|
301
408
|
|
|
409
|
+
# Determine upload mode from the first batch
|
|
410
|
+
first_batch = files_to_upload[:20]
|
|
411
|
+
response_data = _get_upload_mode(
|
|
412
|
+
figure_url, first_batch, api_key if api_key else ""
|
|
413
|
+
)
|
|
414
|
+
upload_mode = response_data.get("mode", "server-signed")
|
|
415
|
+
|
|
302
416
|
# Process files in batches of 20
|
|
303
417
|
batch_size = 20
|
|
304
418
|
for i in range(0, total_files_to_upload, batch_size):
|
|
@@ -310,47 +424,67 @@ def _upload_bundle(
|
|
|
310
424
|
f"Processing batch {batch_num}/{total_batches} ({len(batch)} files)..."
|
|
311
425
|
)
|
|
312
426
|
|
|
313
|
-
#
|
|
314
|
-
|
|
315
|
-
|
|
427
|
+
# For the first batch, reuse the response_data we already fetched
|
|
428
|
+
if i == 0:
|
|
429
|
+
batch_response = response_data
|
|
430
|
+
else:
|
|
431
|
+
batch_response = _get_upload_mode(
|
|
316
432
|
figure_url, batch, api_key if api_key else ""
|
|
317
433
|
)
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if rel_path in signed_urls_map:
|
|
328
|
-
future = executor.submit(
|
|
329
|
-
_upload_single_file_with_signed_url,
|
|
330
|
-
rel_path,
|
|
331
|
-
file_path,
|
|
332
|
-
signed_urls_map[rel_path],
|
|
434
|
+
|
|
435
|
+
if upload_mode == "client-signed":
|
|
436
|
+
# Direct boto3 upload
|
|
437
|
+
try:
|
|
438
|
+
count = _upload_batch_client_signed(batch_response, batch)
|
|
439
|
+
with count_lock:
|
|
440
|
+
uploaded_count += count
|
|
441
|
+
print(
|
|
442
|
+
f"Uploaded {uploaded_count}/{total_files_to_upload} files"
|
|
333
443
|
)
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
#
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
444
|
+
except Exception as e:
|
|
445
|
+
print(f"Failed to upload batch {batch_num}: {e}")
|
|
446
|
+
raise
|
|
447
|
+
else:
|
|
448
|
+
# Server-signed mode: use presigned URLs
|
|
449
|
+
signed_urls_data = batch_response.get("signedUrls", [])
|
|
450
|
+
if not signed_urls_data:
|
|
451
|
+
raise Exception(f"No signed URLs returned for batch {batch_num}")
|
|
452
|
+
signed_urls_map = {
|
|
453
|
+
item["relativePath"]: item["signedUrl"] for item in signed_urls_data
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
# Upload files in this batch in parallel
|
|
457
|
+
with ThreadPoolExecutor(max_workers=MAX_WORKERS_FOR_UPLOAD) as executor:
|
|
458
|
+
# Submit upload tasks for this batch
|
|
459
|
+
future_to_file = {}
|
|
460
|
+
for rel_path, file_path in batch:
|
|
461
|
+
if rel_path in signed_urls_map:
|
|
462
|
+
future = executor.submit(
|
|
463
|
+
_upload_single_file_with_signed_url,
|
|
464
|
+
rel_path,
|
|
465
|
+
file_path,
|
|
466
|
+
signed_urls_map[rel_path],
|
|
349
467
|
)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
468
|
+
future_to_file[future] = rel_path
|
|
469
|
+
else:
|
|
470
|
+
print(f"Warning: No signed URL found for {rel_path}")
|
|
471
|
+
|
|
472
|
+
# Process completed uploads for this batch
|
|
473
|
+
for future in as_completed(future_to_file):
|
|
474
|
+
relative_path = future_to_file[future]
|
|
475
|
+
try:
|
|
476
|
+
future.result()
|
|
477
|
+
|
|
478
|
+
# Thread-safe progress update
|
|
479
|
+
with count_lock:
|
|
480
|
+
uploaded_count += 1
|
|
481
|
+
print(
|
|
482
|
+
f"Uploaded {uploaded_count}/{total_files_to_upload}: {relative_path}"
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
except Exception as e:
|
|
486
|
+
print(f"Failed to upload {relative_path}: {e}")
|
|
487
|
+
raise
|
|
354
488
|
|
|
355
489
|
# Create manifest for finalization
|
|
356
490
|
print("Creating manifest...")
|
|
@@ -385,20 +519,27 @@ def _upload_bundle(
|
|
|
385
519
|
try:
|
|
386
520
|
# Use batch API for manifest
|
|
387
521
|
manifest_batch = [("manifest.json", temp_file_path)]
|
|
388
|
-
|
|
522
|
+
batch_response = _get_upload_mode(
|
|
389
523
|
figure_url, manifest_batch, api_key if api_key else ""
|
|
390
524
|
)
|
|
525
|
+
mode = batch_response.get("mode", "server-signed")
|
|
391
526
|
|
|
392
|
-
if "
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
527
|
+
if mode == "client-signed":
|
|
528
|
+
_upload_batch_client_signed(batch_response, manifest_batch)
|
|
529
|
+
else:
|
|
530
|
+
signed_urls_data = batch_response.get("signedUrls", [])
|
|
531
|
+
signed_urls_map = {
|
|
532
|
+
item["relativePath"]: item["signedUrl"] for item in signed_urls_data
|
|
533
|
+
}
|
|
534
|
+
if "manifest.json" not in signed_urls_map:
|
|
535
|
+
raise Exception("No signed URL returned for manifest.json")
|
|
536
|
+
|
|
537
|
+
_upload_single_file_with_signed_url(
|
|
538
|
+
"manifest.json",
|
|
539
|
+
temp_file_path,
|
|
540
|
+
signed_urls_map["manifest.json"],
|
|
541
|
+
num_retries=4,
|
|
542
|
+
)
|
|
402
543
|
finally:
|
|
403
544
|
# Clean up temporary file
|
|
404
545
|
temp_file_path.unlink(missing_ok=True)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "figpack"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.20"
|
|
8
8
|
description = "A Python package for creating shareable, interactive visualizations in the browser"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -7,13 +7,13 @@ from figpack.core._upload_bundle import (
|
|
|
7
7
|
_create_or_get_figure,
|
|
8
8
|
_determine_content_type,
|
|
9
9
|
_finalize_figure,
|
|
10
|
-
|
|
10
|
+
_get_upload_mode,
|
|
11
11
|
_upload_bundle,
|
|
12
12
|
_upload_single_file_with_signed_url,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
def
|
|
16
|
+
def test_get_upload_mode(tmp_path):
|
|
17
17
|
# Create temporary test files
|
|
18
18
|
file1 = tmp_path / "test1.txt"
|
|
19
19
|
file2 = tmp_path / "test2.txt"
|
|
@@ -31,6 +31,7 @@ def test_get_batch_signed_urls(tmp_path):
|
|
|
31
31
|
mock_response.ok = True
|
|
32
32
|
mock_response.json.return_value = {
|
|
33
33
|
"success": True,
|
|
34
|
+
"mode": "server-signed",
|
|
34
35
|
"signedUrls": [
|
|
35
36
|
{"relativePath": "path1.txt", "signedUrl": "signed-url-1"},
|
|
36
37
|
{"relativePath": "path2.txt", "signedUrl": "signed-url-2"},
|
|
@@ -39,9 +40,10 @@ def test_get_batch_signed_urls(tmp_path):
|
|
|
39
40
|
|
|
40
41
|
with mock.patch("requests.post") as mock_post:
|
|
41
42
|
mock_post.return_value = mock_response
|
|
42
|
-
result =
|
|
43
|
+
result = _get_upload_mode(figure_url, files_batch, api_key)
|
|
43
44
|
|
|
44
|
-
assert result ==
|
|
45
|
+
assert result["mode"] == "server-signed"
|
|
46
|
+
assert len(result["signedUrls"]) == 2
|
|
45
47
|
|
|
46
48
|
# Verify proper API call
|
|
47
49
|
mock_post.assert_called_once()
|
|
@@ -52,16 +54,16 @@ def test_get_batch_signed_urls(tmp_path):
|
|
|
52
54
|
assert len(called_payload["files"]) == 2
|
|
53
55
|
|
|
54
56
|
|
|
55
|
-
def
|
|
57
|
+
def test_get_upload_mode_http_error():
|
|
56
58
|
with mock.patch("requests.post") as mock_post:
|
|
57
59
|
mock_post.return_value.ok = False
|
|
58
60
|
mock_post.return_value.status_code = 500
|
|
59
61
|
|
|
60
|
-
with pytest.raises(Exception, match="Failed to get
|
|
61
|
-
|
|
62
|
+
with pytest.raises(Exception, match="Failed to get upload info for batch"):
|
|
63
|
+
_get_upload_mode("test-url", [], "test-key")
|
|
62
64
|
|
|
63
65
|
|
|
64
|
-
def
|
|
66
|
+
def test_get_upload_mode_api_error(tmp_path):
|
|
65
67
|
# Create test file
|
|
66
68
|
test_file = tmp_path / "test.txt"
|
|
67
69
|
test_file.write_text("test content")
|
|
@@ -74,9 +76,9 @@ def test_get_batch_signed_urls_api_error(tmp_path):
|
|
|
74
76
|
with mock.patch("requests.post") as mock_post:
|
|
75
77
|
mock_post.return_value = mock_response
|
|
76
78
|
with pytest.raises(
|
|
77
|
-
Exception, match="Failed to get
|
|
79
|
+
Exception, match="Failed to get upload info for batch: API error message"
|
|
78
80
|
):
|
|
79
|
-
|
|
81
|
+
_get_upload_mode("test-url", files_batch, "test-key")
|
|
80
82
|
|
|
81
83
|
|
|
82
84
|
def test_upload_single_file_with_signed_url(tmp_path):
|
|
@@ -86,6 +88,7 @@ def test_upload_single_file_with_signed_url(tmp_path):
|
|
|
86
88
|
|
|
87
89
|
with mock.patch("requests.put") as mock_put:
|
|
88
90
|
mock_put.return_value.ok = True
|
|
91
|
+
mock_put.return_value.status_code = 200
|
|
89
92
|
|
|
90
93
|
result = _upload_single_file_with_signed_url(
|
|
91
94
|
"test.txt", test_file, "signed-url", num_retries=2
|
|
@@ -107,7 +110,7 @@ def test_upload_single_file_with_retry(tmp_path):
|
|
|
107
110
|
# First attempt fails, second succeeds
|
|
108
111
|
mock_put.side_effect = [
|
|
109
112
|
mock.Mock(ok=False, status_code=500),
|
|
110
|
-
mock.Mock(ok=True),
|
|
113
|
+
mock.Mock(ok=True, status_code=200),
|
|
111
114
|
]
|
|
112
115
|
|
|
113
116
|
result = _upload_single_file_with_signed_url(
|
|
@@ -204,6 +207,7 @@ def test_upload_bundle(tmp_path):
|
|
|
204
207
|
mock_batch_files_response.ok = True
|
|
205
208
|
mock_batch_files_response.json.return_value = {
|
|
206
209
|
"success": True,
|
|
210
|
+
"mode": "server-signed",
|
|
207
211
|
"signedUrls": [
|
|
208
212
|
{"relativePath": str(file1.name), "signedUrl": "signed-url-1"},
|
|
209
213
|
{"relativePath": str(file2.name), "signedUrl": "signed-url-2"},
|
|
@@ -215,6 +219,7 @@ def test_upload_bundle(tmp_path):
|
|
|
215
219
|
mock_batch_manifest_response.ok = True
|
|
216
220
|
mock_batch_manifest_response.json.return_value = {
|
|
217
221
|
"success": True,
|
|
222
|
+
"mode": "server-signed",
|
|
218
223
|
"signedUrls": [
|
|
219
224
|
{"relativePath": "manifest.json", "signedUrl": "signed-url-manifest"},
|
|
220
225
|
],
|
|
@@ -222,6 +227,7 @@ def test_upload_bundle(tmp_path):
|
|
|
222
227
|
|
|
223
228
|
mock_upload_response = mock.Mock()
|
|
224
229
|
mock_upload_response.ok = True
|
|
230
|
+
mock_upload_response.status_code = 200
|
|
225
231
|
|
|
226
232
|
mock_finalize_response = mock.Mock()
|
|
227
233
|
mock_finalize_response.ok = True
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/neurosift-logo-CLsuwLMO.png
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|