Skip to content

Commit a31d4a3

Browse files
committed
Force Zenodo artifact uploads to use application/octet-stream and add a regression test so release tarballs no longer fail with HTTP 415 during the publish workflow.
1 parent 5094004 commit a31d4a3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

tools/release/publish_zenodo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import argparse
55
import json
6-
import mimetypes
76
import os
87
import sys
98
from pathlib import Path
@@ -244,14 +243,15 @@ def upload_dist_files(draft: dict, token: str, dist_dir: Path) -> None:
244243
for path in sorted(dist_dir.iterdir()):
245244
if not path.is_file():
246245
continue
247-
content_type = mimetypes.guess_type(path.name)[0] or "application/octet-stream"
248246
with path.open("rb") as handle:
249247
api_request(
250248
"PUT",
251249
f"{bucket_url}/{parse.quote(path.name)}",
252250
token=token,
253251
data=handle.read(),
254-
content_type=content_type,
252+
# Zenodo bucket uploads reject extension-specific types like
253+
# application/gzip for source tarballs and require raw bytes.
254+
content_type="application/octet-stream",
255255
)
256256
print(f"Uploaded {path.name} to Zenodo draft {draft['id']}.")
257257

ultraplot/tests/test_release_metadata.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,35 @@ def test_zenodo_release_metadata_is_built_from_repository_sources():
9696
assert metadata["creators"][0]["orcid"] == "0000-0001-9862-8936"
9797

9898

99+
def test_zenodo_uploads_use_octet_stream(tmp_path, monkeypatch):
100+
"""
101+
Zenodo bucket uploads should use a generic binary content type.
102+
"""
103+
publish_zenodo = _load_publish_zenodo()
104+
calls = []
105+
106+
def fake_api_request(method, url, **kwargs):
107+
calls.append((method, url, kwargs))
108+
return None
109+
110+
monkeypatch.setattr(publish_zenodo, "api_request", fake_api_request)
111+
(tmp_path / "ultraplot-2.1.5.tar.gz").write_bytes(b"sdist")
112+
(tmp_path / "ultraplot-2.1.5-py3-none-any.whl").write_bytes(b"wheel")
113+
114+
publish_zenodo.upload_dist_files(
115+
{"id": 18492463, "links": {"bucket": "https://zenodo.example/files/bucket"}},
116+
"token",
117+
tmp_path,
118+
)
119+
120+
assert len(calls) == 2
121+
assert all(method == "PUT" for method, _, _ in calls)
122+
assert all(
123+
kwargs["content_type"] == "application/octet-stream"
124+
for _, _, kwargs in calls
125+
)
126+
127+
99128
def test_zenodo_json_is_not_committed():
100129
"""
101130
Zenodo metadata should no longer be duplicated in a separate committed file.

0 commit comments

Comments
 (0)