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.
Files changed (83) hide show
  1. {figpack-0.3.18/figpack.egg-info → figpack-0.3.20}/PKG-INFO +1 -1
  2. {figpack-0.3.18 → figpack-0.3.20}/figpack/__init__.py +1 -1
  3. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_upload_bundle.py +216 -75
  4. {figpack-0.3.18 → figpack-0.3.20/figpack.egg-info}/PKG-INFO +1 -1
  5. {figpack-0.3.18 → figpack-0.3.20}/pyproject.toml +1 -1
  6. {figpack-0.3.18 → figpack-0.3.20}/tests/test_upload_bundle.py +17 -11
  7. {figpack-0.3.18 → figpack-0.3.20}/LICENSE +0 -0
  8. {figpack-0.3.18 → figpack-0.3.20}/MANIFEST.in +0 -0
  9. {figpack-0.3.18 → figpack-0.3.20}/README.md +0 -0
  10. {figpack-0.3.18 → figpack-0.3.20}/figpack/cli.py +0 -0
  11. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/__init__.py +0 -0
  12. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_bundle_utils.py +0 -0
  13. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_figure_utils.py +0 -0
  14. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_file_handler.py +0 -0
  15. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_patch_figure.py +0 -0
  16. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_revert_patch_figure.py +0 -0
  17. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_save_figure.py +0 -0
  18. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_server_manager.py +0 -0
  19. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_show_view.py +0 -0
  20. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_view_figure.py +0 -0
  21. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/_zarr_consolidate.py +0 -0
  22. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/config.py +0 -0
  23. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/extension_view.py +0 -0
  24. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/figpack_extension.py +0 -0
  25. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/figpack_view.py +0 -0
  26. {figpack-0.3.18 → figpack-0.3.20}/figpack/core/zarr.py +0 -0
  27. {figpack-0.3.18 → figpack-0.3.20}/figpack/extensions.py +0 -0
  28. {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/index-CSMGUquF.js +0 -0
  29. {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/index-GPjx4QpG.css +0 -0
  30. {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/assets/neurosift-logo-CLsuwLMO.png +0 -0
  31. {figpack-0.3.18 → figpack-0.3.20}/figpack/figpack-figure-dist/index.html +0 -0
  32. {figpack-0.3.18 → figpack-0.3.20}/figpack/utils/__init__.py +0 -0
  33. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Box.py +0 -0
  34. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/CaptionedView.py +0 -0
  35. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/DataFrame.py +0 -0
  36. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Gallery.py +0 -0
  37. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/GalleryItem.py +0 -0
  38. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Iframe.py +0 -0
  39. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Image.py +0 -0
  40. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/LayoutItem.py +0 -0
  41. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Markdown.py +0 -0
  42. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MatplotlibFigure.py +0 -0
  43. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MountainLayout.py +0 -0
  44. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MountainLayoutItem.py +0 -0
  45. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/MultiChannelTimeseries.py +0 -0
  46. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/PlotlyExtension.py +0 -0
  47. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/__init__.py +0 -0
  48. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/_plotly_extension.py +0 -0
  49. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/PlotlyExtension/plotly_view.js +0 -0
  50. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Spectrogram.py +0 -0
  51. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/Splitter.py +0 -0
  52. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/TabLayout.py +0 -0
  53. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/TabLayoutItem.py +0 -0
  54. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/TimeseriesGraph.py +0 -0
  55. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/VerticalLayout.py +0 -0
  56. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/VerticalLayoutItem.py +0 -0
  57. {figpack-0.3.18 → figpack-0.3.20}/figpack/views/__init__.py +0 -0
  58. {figpack-0.3.18 → figpack-0.3.20}/figpack-serve/worker/container/app.py +0 -0
  59. {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/SOURCES.txt +0 -0
  60. {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/dependency_links.txt +0 -0
  61. {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/entry_points.txt +0 -0
  62. {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/requires.txt +0 -0
  63. {figpack-0.3.18 → figpack-0.3.20}/figpack.egg-info/top_level.txt +0 -0
  64. {figpack-0.3.18 → figpack-0.3.20}/setup.cfg +0 -0
  65. {figpack-0.3.18 → figpack-0.3.20}/tests/test_box.py +0 -0
  66. {figpack-0.3.18 → figpack-0.3.20}/tests/test_cli.py +0 -0
  67. {figpack-0.3.18 → figpack-0.3.20}/tests/test_core.py +0 -0
  68. {figpack-0.3.18 → figpack-0.3.20}/tests/test_dataframe.py +0 -0
  69. {figpack-0.3.18 → figpack-0.3.20}/tests/test_extension_system.py +0 -0
  70. {figpack-0.3.18 → figpack-0.3.20}/tests/test_figpack_view.py +0 -0
  71. {figpack-0.3.18 → figpack-0.3.20}/tests/test_file_handler.py +0 -0
  72. {figpack-0.3.18 → figpack-0.3.20}/tests/test_gallery.py +0 -0
  73. {figpack-0.3.18 → figpack-0.3.20}/tests/test_image.py +0 -0
  74. {figpack-0.3.18 → figpack-0.3.20}/tests/test_markdown.py +0 -0
  75. {figpack-0.3.18 → figpack-0.3.20}/tests/test_matplotlib_figure.py +0 -0
  76. {figpack-0.3.18 → figpack-0.3.20}/tests/test_multichannel_timeseries.py +0 -0
  77. {figpack-0.3.18 → figpack-0.3.20}/tests/test_plotly_figure.py +0 -0
  78. {figpack-0.3.18 → figpack-0.3.20}/tests/test_server_manager.py +0 -0
  79. {figpack-0.3.18 → figpack-0.3.20}/tests/test_spectrogram.py +0 -0
  80. {figpack-0.3.18 → figpack-0.3.20}/tests/test_splitter.py +0 -0
  81. {figpack-0.3.18 → figpack-0.3.20}/tests/test_tablayout.py +0 -0
  82. {figpack-0.3.18 → figpack-0.3.20}/tests/test_timeseries_graph.py +0 -0
  83. {figpack-0.3.18 → figpack-0.3.20}/tests/test_view_figure.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: figpack
3
- Version: 0.3.18
3
+ Version: 0.3.20
4
4
  Summary: A Python package for creating shareable, interactive visualizations in the browser
5
5
  Author-email: Jeremy Magland <jmagland@flatironinstitute.org>
6
6
  License: Apache-2.0
@@ -2,7 +2,7 @@
2
2
  figpack - A Python package for creating shareable, interactive visualizations in the browser
3
3
  """
4
4
 
5
- __version__ = "0.3.18"
5
+ __version__ = "0.3.20"
6
6
 
7
7
  from .cli import view_figure
8
8
  from .core import FigpackView, FigpackExtension, ExtensionView
@@ -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
- def _get_batch_signed_urls(figure_url: str, files_batch: list, api_key: str) -> dict:
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
- Returns:
28
- dict: Mapping of relative_path to signed_url
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 signed URLs for batch: {error_msg}")
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 signed URLs for batch: {response_data.get('message', 'Unknown error')}"
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
- signed_urls_data = response_data.get("signedUrls", [])
65
- if not signed_urls_data:
66
- raise Exception("No signed URLs returned for batch")
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
- # Convert to mapping
69
- signed_urls_map = {}
70
- for item in signed_urls_data:
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 signed_urls_map
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.ok:
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
- # Get signed URLs for this batch
314
- try:
315
- signed_urls_map = _get_batch_signed_urls(
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
- except Exception as e:
319
- print(f"Failed to get signed URLs for batch {batch_num}: {e}")
320
- raise
321
-
322
- # Upload files in this batch in parallel
323
- with ThreadPoolExecutor(max_workers=MAX_WORKERS_FOR_UPLOAD) as executor:
324
- # Submit upload tasks for this batch
325
- future_to_file = {}
326
- for rel_path, file_path in batch:
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
- future_to_file[future] = rel_path
335
- else:
336
- print(f"Warning: No signed URL found for {rel_path}")
337
-
338
- # Process completed uploads for this batch
339
- for future in as_completed(future_to_file):
340
- relative_path = future_to_file[future]
341
- try:
342
- future.result() # This will raise any exception that occurred during upload
343
-
344
- # Thread-safe progress update
345
- with count_lock:
346
- uploaded_count += 1
347
- print(
348
- f"Uploaded {uploaded_count}/{total_files_to_upload}: {relative_path}"
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
- except Exception as e:
352
- print(f"Failed to upload {relative_path}: {e}")
353
- raise # Re-raise the exception to stop the upload process
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
- signed_urls_map = _get_batch_signed_urls(
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 "manifest.json" not in signed_urls_map:
393
- raise Exception("No signed URL returned for manifest.json")
394
-
395
- # Upload manifest using the same retry function
396
- _upload_single_file_with_signed_url(
397
- "manifest.json",
398
- temp_file_path,
399
- signed_urls_map["manifest.json"],
400
- num_retries=4,
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: figpack
3
- Version: 0.3.18
3
+ Version: 0.3.20
4
4
  Summary: A Python package for creating shareable, interactive visualizations in the browser
5
5
  Author-email: Jeremy Magland <jmagland@flatironinstitute.org>
6
6
  License: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "figpack"
7
- version = "0.3.18"
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
- _get_batch_signed_urls,
10
+ _get_upload_mode,
11
11
  _upload_bundle,
12
12
  _upload_single_file_with_signed_url,
13
13
  )
14
14
 
15
15
 
16
- def test_get_batch_signed_urls(tmp_path):
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 = _get_batch_signed_urls(figure_url, files_batch, api_key)
43
+ result = _get_upload_mode(figure_url, files_batch, api_key)
43
44
 
44
- assert result == {"path1.txt": "signed-url-1", "path2.txt": "signed-url-2"}
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 test_get_batch_signed_urls_http_error():
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 signed URLs for batch"):
61
- _get_batch_signed_urls("test-url", [], "test-key")
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 test_get_batch_signed_urls_api_error(tmp_path):
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 signed URLs for batch: API error message"
79
+ Exception, match="Failed to get upload info for batch: API error message"
78
80
  ):
79
- _get_batch_signed_urls("test-url", files_batch, "test-key")
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