From f3bc2ad9396f51051cfd59cb0dec06686c0863f7 Mon Sep 17 00:00:00 2001 From: fynnbe Date: Fri, 24 May 2024 07:39:21 +0200 Subject: [PATCH] only set license if known to zenodo --- bioimageio_collection_backoffice/backup.py | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/bioimageio_collection_backoffice/backup.py b/bioimageio_collection_backoffice/backup.py index 5c1a70e9..045a0b6d 100644 --- a/bioimageio_collection_backoffice/backup.py +++ b/bioimageio_collection_backoffice/backup.py @@ -199,17 +199,10 @@ def rdf_to_metadata( keywords = ["backup.bioimage.io", "bioimage.io", "bioimage.io:" + rdf.type] # related_identifiers = generate_related_identifiers_from_rdf(rdf, rdf_file_name) # TODO: add related identifiers - # for debugging: check if license id is valid: - # license_response = requests.get( - # f"https://zenodo.org/api/vocabularies/licenses/{rdf.license.lower()}" - # ) - # raise_for_status_discretely(license_response) - - return { + ret: Dict[str, Any] = { "title": f"bioimage.io upload: {rdf.id}", "description": description, "access_right": "open", - "license": rdf.license, "upload_type": "dataset" if rdf.type == "dataset" else "software", "creators": creators, "publication_date": publication_date.date().isoformat(), @@ -219,6 +212,26 @@ def rdf_to_metadata( # "communities": [], } + # check if license id is valid: + license_response = requests.get( + f"https://zenodo.org/api/vocabularies/licenses/{rdf.license.lower()}" + ) + try: + raise_for_status_discretely(license_response) + except Exception as e: + logger.error(str(e)) + logger.error( + ( + f"License '{rdf.license}' not known to Zenodo." + + " Please add manually as custom license" + + " (as this is currently not supported to do via REST API)" + ) + ) + else: + ret["license"] = rdf.license + + return ret + def generate_related_identifiers_from_rdf(rdf: ResourceDescr, rdf_file_name: str): related_identifiers: List[Dict[str, str]] = []