Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Dataverse files without a persistentID #355

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Changes from 4 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
37 changes: 24 additions & 13 deletions pooch/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,20 +1034,31 @@
download_url : str
The HTTP URL that can be used to download the file.
"""

parsed = parse_url(self.archive_url)

# Iterate over the given files until we find one of the requested name
for filedata in self.api_response.json()["data"]["latestVersion"]["files"]:
if file_name == filedata["dataFile"]["filename"]:
return (
f"{parsed['protocol']}://{parsed['netloc']}/api/access/datafile/"
f":persistentId?persistentId={filedata['dataFile']['persistentId']}"
)

raise ValueError(
f"File '{file_name}' not found in data archive {self.archive_url} (doi:{self.doi})."
)
response = self.api_response.json()
files = {
file["dataFile"]["filename"]: file["dataFile"]
for file in response["data"]["latestVersion"]["files"]
}
if file_name not in files:
raise ValueError(
f"File '{file_name}' not found in data archive "
f"{self.archive_url} (doi:{self.doi})."
)
# Generate download_url using persistentId or file id
persistent_id = files[file_name].get("persistentId")
if persistent_id:
download_url = (
f"{parsed['protocol']}://{parsed['netloc']}/api/access/datafile/"
f":persistentId?persistentId={persistent_id}"
)
else:
file_id = files[file_name]["id"]
download_url = (

Check warning on line 1057 in pooch/downloaders.py

View check run for this annotation

Codecov / codecov/patch

pooch/downloaders.py#L1056-L1057

Added lines #L1056 - L1057 were not covered by tests
f"{parsed['protocol']}://{parsed['netloc']}/api/access/datafile/"
f"{file_id}"
)
return download_url

def populate_registry(self, pooch):
"""
Expand Down