Skip to content

Commit

Permalink
Merge pull request #4568 from yarikoptic/bf-duecredit
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleam committed May 22, 2020
2 parents 69c7fae + b7e62b5 commit dc254f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions datalad/support/due_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

# Note Text was added/exposed only since DueCredit 0.6.5
from .due import due, Doi, Url, Text
from ..utils import never_fail
from ..utils import never_fail, swallow_logs
from ..dochelpers import exc_str

import logging
lgr = logging.getLogger('datalad.duecredit')
Expand Down Expand Up @@ -48,15 +49,20 @@ def duecredit_dataset(dataset):
"""

try:
res = dataset.metadata(
reporton='datasets', # Interested only in the dataset record
result_renderer=None, # No need
return_type='item-or-list' # Expecting a single record
)
# probably with metalad RFing we would gain better control
# over reporting of warnings etc, ATM the warnings are produced
# directly within get_ds_aggregate_db_locations down below and
# we have no other way but pacify all of them.
with swallow_logs(logging.ERROR) as cml:
res = dataset.metadata(
reporton='datasets', # Interested only in the dataset record
result_renderer=None, # No need
return_type='item-or-list' # Expecting a single record
)
except Exception as exc:
lgr.warning(
"Failed to obtain metadata for %s. Will not provide duecredit entry",
dataset
lgr.debug(
"Failed to obtain metadata for %s. Will not provide duecredit entry: %s",
dataset, exc_str(exc)
)
return

Expand Down
2 changes: 1 addition & 1 deletion datalad/support/tests/test_due_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_duecredit_dataset(path):
# TODO: possibly reconsider - may be our catch-all should be used there
# as well
with patch.object(due, 'cite') as mcite:
with swallow_logs(new_level=logging.WARNING) as cml:
with swallow_logs(new_level=logging.DEBUG) as cml:
duecredit_dataset(dataset) # should not crash or anything
# since no metadata - we issue warning and return without citing
# anything
Expand Down

0 comments on commit dc254f0

Please sign in to comment.