Skip to content

Commit

Permalink
fix depr parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Jun 25, 2024
1 parent a28bd3a commit c42900f
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions h5rdmtoolbox/convention/standard_names/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,33 +703,36 @@ def from_zenodo(source: str = None, doi_or_recid=None) -> "StandardNameTable":
if doi_or_recid is not None:
source = doi_or_recid

if source.startswith('https://zenodo.org') and source.rsplit('.', 1)[-1] in ('yaml',):
# it is a file from zenodo, download it:
from ...repository.utils import download_file
cv_filename = download_file(source)
return StandardNameTable.from_yaml(cv_filename)
if source.startswith('https://zenodo.org/record/') or source.startswith('https://doi.org/'):
from ...repository.zenodo import ZenodoRecord
z = ZenodoRecord(source)
for file in z.files:
if pathlib.Path(file.filename).suffix == '.yaml':
try:
return StandardNameTable.from_yaml(file.download())
except Exception as e:
logger.error(f'Error while reading file {file.filename}: {e}')
continue
raise FileNotFoundError(f'No valid standard name found in Zenodo repo {source}')

if source.startswith('10.5281/zenodo.'):
doi = source.split('.')[-1]
if (UserDir['standard_name_tables'] / f'{doi}.yaml').exists():
return StandardNameTable.from_yaml(UserDir['standard_name_tables'] / f'{doi}.yaml')
return StandardNameTable.from_zenodo(doi)

# parse input:
rec_id = zenodo.utils.recid_from_doi_or_redid(source)
if rec_id in cache.snt:
return cache.snt[rec_id]
if isinstance(source, str):
if source.startswith('https://zenodo.org') and source.rsplit('.', 1)[-1] in ('yaml',):
# it is a file from zenodo, download it:
from ...repository.utils import download_file
cv_filename = download_file(source)
return StandardNameTable.from_yaml(cv_filename)
if source.startswith('https://zenodo.org/record/') or source.startswith('https://doi.org/'):
from ...repository.zenodo import ZenodoRecord
z = ZenodoRecord(source)
for file in z.files:
if pathlib.Path(file.filename).suffix == '.yaml':
try:
return StandardNameTable.from_yaml(file.download())
except Exception as e:
logger.error(f'Error while reading file {file.filename}: {e}')
continue
raise FileNotFoundError(f'No valid standard name found in Zenodo repo {source}')

if source.startswith('10.5281/zenodo.'):
doi = source.split('.')[-1]
if (UserDir['standard_name_tables'] / f'{doi}.yaml').exists():
return StandardNameTable.from_yaml(UserDir['standard_name_tables'] / f'{doi}.yaml')
return StandardNameTable.from_zenodo(doi)

# parse input:
rec_id = zenodo.utils.recid_from_doi_or_redid(source)
if rec_id in cache.snt:
return cache.snt[rec_id]
elif isinstance(source, int):
rec_id = source

z = zenodo.ZenodoRecord(rec_id)
assert z.exists()
Expand Down

0 comments on commit c42900f

Please sign in to comment.