Skip to content

Commit

Permalink
refactor(cff): reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdoret committed Dec 17, 2024
1 parent a884cbc commit df9295e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions gimie/parsers/cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,24 @@ def get_cff_doi(data: bytes) -> Optional[List[str]]:
return None

doi_urls = []

try:
identifiers = cff.get("identifiers", [])
for identifier in identifiers:
if identifier.get("type") == "doi":
try:
doi_url = doi_to_url(identifier["value"])
doi_urls.append(doi_url)
except ValueError as err:
logger.warning(err)
identifiers = cff["identifiers"]
except (KeyError, TypeError):
logger.warning(
"CITATION.cff does not contain a valid 'identifiers' key."
)
return None

return doi_urls if doi_urls else None
for identifier in identifiers:
if identifier.get("type") == "doi":
try:
doi_url = doi_to_url(identifier["value"])
doi_urls.append(doi_url)
except ValueError as err:
logger.warning(err)

return doi_urls or None


def get_cff_authors(data: bytes) -> Optional[List[dict[str, str]]]:
Expand Down

0 comments on commit df9295e

Please sign in to comment.