Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions binderhub/repoproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,38 @@ class FigshareProvider(RepoProvider):
"ref": {"enabled": False},
}

url_regex = re.compile(r"(.*)/articles/([^/]+)/(\d+)(/)?(\d+)?")

async def get_resolved_ref(self):
client = AsyncHTTPClient()
req = HTTPRequest(f"https://doi.org/{self.spec}", user_agent="BinderHub")
# fetch doi: will 404 if it doesn't exist
r = await client.fetch(req)
# parse doi, not figshare url
_doi_n, _, identifier = self.spec.partition("/")
doi_fields = identifier.split(".")
# 2 cases:
# versioned: 10.6084/m9.figshare.9782777.v1
# unversioned: 10.6084/m9.figshare.9782777
if len(doi_fields) < 3:
raise ValueError(f"Unexpected figshare doi: {self.spec}")
if doi_fields[-1].startswith("v"):
article_version = doi_fields[-1][1:]
article_id = doi_fields[-2]
else:
# unversioned, get latest version from API
# unversioned defaults to latest,
# and figshare doesn't put version in url,
# so resolve latest version from api
article_id = doi_fields[-1]
r = await client.fetch(
f"https://api.figshare.com/v2/articles/{article_id}/versions",
user_agent="BinderHub",
)
# list of versions containing {"version": 2}
article_versions = json.loads(r.body)
if not article_versions:
raise ValueError(f"Article {article_id} has no versions")
article_version = sorted(v["version"] for v in article_versions)[-1]

match = self.url_regex.match(r.effective_url)
article_id = match.groups()[2]
article_version = match.groups()[4]
if not article_version:
article_version = "1"
self.record_id = f"{article_id}.v{article_version}"

return self.record_id
Expand Down
17 changes: 17 additions & 0 deletions binderhub/tests/http-record.api.figshare.com.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"https://api.figshare.com/v2/articles/9782777/versions": {
"body": "[{\"version\": 1, \"url\": \"https://api.figshare.com/v2/articles/9782777/versions/1\"}, {\"version\": 2, \"url\": \"https://api.figshare.com/v2/articles/9782777/versions/2\"}, {\"version\": 3, \"url\": \"https://api.figshare.com/v2/articles/9782777/versions/3\"}]",
"code": 200,
"headers": {
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,X-API-Revision",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, DELETE, PUT",
"Access-Control-Expose-Headers": "Location",
"Content-Encoding": "gzip",
"Content-Type": "application/json",
"Date": "Fri, 10 Apr 2026 22:03:18 GMT",
"Server": "nginx",
"Vary": "Accept-Encoding"
}
}
}
10 changes: 5 additions & 5 deletions binderhub/tests/test_repoproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ async def test_zenodo(spec, resolved_spec, resolved_ref, resolved_ref_url, build
"https://doi.org/10.6084/m9.figshare.9782777.v1",
"figshare-9782777.v1",
],
# spec without version is accepted as version 1 - check FigshareProvider.get_resolved_ref()
# spec without version is accepted as latest version - check FigshareProvider.get_resolved_ref()
[
"10.6084/m9.figshare.9782777",
"10.6084/m9.figshare.9782777.v1",
"9782777.v1",
"https://doi.org/10.6084/m9.figshare.9782777.v1",
"figshare-9782777.v1",
"10.6084/m9.figshare.9782777.v3",
"9782777.v3",
"https://doi.org/10.6084/m9.figshare.9782777.v3",
"figshare-9782777.v3",
],
],
)
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ chartpress>=2.1
click
dockerspawner
jsonschema
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.06.0
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.07.2
jupyter_packaging>=0.10.4,<2
jupyterhub @ git+https://github.com/RCOSDP/CS-jupyterhub.git@5.2.1
nest-asyncio
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/images/binderhub/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ google-cloud-logging==3.*
jupyterhub @ git+https://github.com/RCOSDP/CS-jupyterhub.git@5.2.1

# jupyter-repo2docker is pinned to CS-repo2docker
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.06.0
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.07.2

# Workaround: Added a dependecy of ruamel-yaml because jupyter-telemetry,
# which has a dependency of ruamel-yaml, was removed from jupyterhub.
Expand Down
2 changes: 1 addition & 1 deletion helm-chart/images/binderhub/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jsonschema-specifications==2025.9.1
# via jsonschema
jupyter-events==0.12.0
# via jupyterhub
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.06.0
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.07.2
# via
# -r helm-chart/images/binderhub/../../../requirements.txt
# -r helm-chart/images/binderhub/requirements.in
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ escapism
jinja2
jsonschema
jupyterhub @ git+https://github.com/RCOSDP/CS-jupyterhub.git@5.2.1
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.06.0
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.07.2
kubernetes
prometheus_client
pyjwt>=2
Expand Down
2 changes: 1 addition & 1 deletion testing/local-binder-local-hub/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dockerspawner>=12
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.06.0
jupyter-repo2docker @ git+https://github.com/RCOSDP/CS-repo2docker.git@2026.07.2
jupyterhub @ git+https://github.com/RCOSDP/CS-jupyterhub.git@5.2.1
Loading