diff --git a/repo2docker/contentproviders/dataverse.py b/repo2docker/contentproviders/dataverse.py index 3cf8cb20..e786fe24 100644 --- a/repo2docker/contentproviders/dataverse.py +++ b/repo2docker/contentproviders/dataverse.py @@ -99,7 +99,7 @@ def parse_dataverse_url(self, url: str) -> Tuple[str, bool]: Raises a ValueError if we can not parse the url """ - parsed_url= urlparse(url) + parsed_url = urlparse(url) path = parsed_url.path qs = parse_qs(parsed_url.query) base_url = f"{parsed_url.scheme}://{parsed_url.netloc}" @@ -157,10 +157,10 @@ def get_datafiles(self, url: str) -> List[dict]: resp = self._request(dataset_api_url, headers={"accept": "application/json"}) if resp.status_code == 404 and is_ambiguous: # It's possible this is a *file* persistent_id, not a dataset one - persistent_id = self.get_dataset_id_from_file_id( - base_url, persistent_id + persistent_id = self.get_dataset_id_from_file_id(base_url, persistent_id) + dataset_api_url = ( + f"{base_url}/api/datasets/:persistentId?persistentId={persistent_id}" ) - dataset_api_url = f"{base_url}/api/datasets/:persistentId?persistentId={persistent_id}" resp = self._request( dataset_api_url, headers={"accept": "application/json"} ) @@ -181,7 +181,7 @@ def fetch(self, spec, output_dir, yield_output=False): url = spec parsed_url = urlparse(url) # FIXME: Support determining API URL better - base_url = f'{parsed_url.scheme}://{parsed_url.netloc}' + base_url = f"{parsed_url.scheme}://{parsed_url.netloc}" yield f"Fetching Dataverse record {url}.\n" diff --git a/tests/contentproviders/test_dataverse.py b/tests/contentproviders/test_dataverse.py index 7b6d1f60..9ca25852 100644 --- a/tests/contentproviders/test_dataverse.py +++ b/tests/contentproviders/test_dataverse.py @@ -6,6 +6,7 @@ from repo2docker.contentproviders import Dataverse + @pytest.mark.parametrize( ("doi", "resolved"), [ @@ -45,22 +46,22 @@ def test_detect(doi, resolved): ( "https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/6ZXAGT/3YRRYJ", "doi:10.7910/DVN/6ZXAGT", - False + False, ), ( "https://dataverse.harvard.edu/citation?persistentId=doi:10.7910/DVN/TJCLKP", "doi:10.7910/DVN/TJCLKP", - True + True, ), ( "https://dataverse.harvard.edu/api/access/datafile/3323458", "doi:10.7910/DVN/3MJ7IR", - False + False, ), ( "https://data.cimmyt.org/dataset.xhtml?persistentId=hdl:11529/10016", "hdl:11529/10016", - False + False, ), ], )