From 10fc5b5f369b968e605394cb55c2000dea7f45be Mon Sep 17 00:00:00 2001 From: Tom Morrell Date: Thu, 13 Jun 2019 11:14:16 -0700 Subject: [PATCH] Formatting --- repo2docker/contentproviders/zenodo.py | 52 ++++++++++++++++---------- setup.py | 2 +- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/repo2docker/contentproviders/zenodo.py b/repo2docker/contentproviders/zenodo.py index 3faa2f8c..6673c449 100644 --- a/repo2docker/contentproviders/zenodo.py +++ b/repo2docker/contentproviders/zenodo.py @@ -30,22 +30,22 @@ class Zenodo(ContentProvider): return urlopen(req) def _process_doi(self, doi): - #Transform a DOI to a URL - #If not a doi, assume we have a URL and return + # Transform a DOI to a URL + # If not a doi, assume we have a URL and return if is_doi(doi): - #Zenodo instances will most likely use DataCite DOIs - #Could also resolve the DOI to get the url - #Get url from DataCite + # Zenodo instances will most likely use DataCite DOIs + # Could also resolve the DOI to get the url + # Get url from DataCite doi = normalize_doi(doi) req = Request( - "https://api.datacite.org/dois/{}".format(doi), - headers={"accept": "application/json"}, + "https://api.datacite.org/dois/{}".format(doi), + headers={"accept": "application/json"}, ) resp = self._urlopen(req) record = json.loads(resp.read().decode("utf-8")) - url = record['data']['attributes']['url'] + url = record["data"]["attributes"]["url"] return url else: return doi @@ -55,24 +55,36 @@ class Zenodo(ContentProvider): # We need the hostname (url where records are), api url (for metadata), # filepath (path to files in metadata), filename (path to filename in # metadata), type (path to type in metadata) - - hosts = [{'hostname':["https://zenodo.org/record/","http://zenodo.org/record/"], - 'api':'https://zenodo.org/api/records/','filepath':"files", - 'filename':"files.key",'download':"links.download", - 'type':"metadata.upload_type"}, - {'hostname':["https://data.caltech.edu/records/","http://data.caltech.edu/records/"], - 'api':"https://data.caltech.edu/api/record/",'filepath':"files", - 'filename':"electronic_location_and_access.electronic_name.0", - 'type':"metadata.resourceType.resourceTypeGeneral"}] + + hosts = [ + { + "hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"], + "api": "https://zenodo.org/api/records/", + "filepath": "files", + "filename": "files.key", + "download": "links.download", + "type": "metadata.upload_type", + }, + { + "hostname": [ + "https://data.caltech.edu/records/", + "http://data.caltech.edu/records/", + ], + "api": "https://data.caltech.edu/api/record/", + "filepath": "files", + "filename": "electronic_location_and_access.electronic_name.0", + "type": "metadata.resourceType.resourceTypeGeneral", + }, + ] url = self._process_doi(doi) resp = self._urlopen(url) self.record_id = resp.url.rsplit("/", maxsplit=1)[1] for host in hosts: - if any([url.startswith(s) for s in host['hostname']]): + if any([url.startswith(s) for s in host["hostname"]]): return {"record": self.record_id, "host": host} - + def fetch(self, spec, output_dir, yield_output=False): """Fetch and unpack a Zenodo record""" record_id = spec["record"] @@ -80,7 +92,7 @@ class Zenodo(ContentProvider): yield "Fetching Zenodo record {}.\n".format(record_id) req = Request( - "{}{}".format(host['api'],record_id), + "{}{}".format(host["api"], record_id), headers={"accept": "application/json"}, ) resp = self._urlopen(req) diff --git a/setup.py b/setup.py index c61262bb..8b47c9a5 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( "ruamel.yaml>=0.15", "toml", "semver", - "idutils" + "idutils", ], python_requires=">=3.5", author="Project Jupyter Contributors",