Skip to content

Commit

Permalink
Merge pull request #285 from dandi/enh-duecredit
Browse files Browse the repository at this point in the history
Add rudimentary duecredit support using zenodo's dandi-cli DOI
  • Loading branch information
yarikoptic committed Nov 25, 2020
2 parents 39c62bc + 16ff607 commit 194ce14
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dandi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
# Basic logger configuration
#

from .due import due, Doi
due.cite(
Doi("10.5281/zenodo.3692138"),
cite_module=True, # highly specialized -- if imported, means used.
description="Client to interact with DANDI Archive",
path='dandi-cli',
version=__version__, # since yoh hijacked dandi for module but is not brave enough
# to claim it to be dandi as the whole
)


def get_logger(name=None):
"""Return a logger to use
Expand Down
74 changes: 74 additions & 0 deletions dandi/due.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# emacs: at the end of the file
# ex: set sts=4 ts=4 sw=4 et:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
"""
Stub file for a guaranteed safe import of duecredit constructs: if duecredit
is not available.
To use it, place it into your project codebase to be imported, e.g. copy as
cp stub.py /path/tomodule/module/due.py
Note that it might be better to avoid naming it duecredit.py to avoid shadowing
installed duecredit.
Then use in your code as
from .due import due, Doi, BibTeX, Text
See https://github.com/duecredit/duecredit/blob/master/README.md for examples.
Origin: Originally a part of the duecredit
Copyright: 2015-2019 DueCredit developers
License: BSD-2
"""

__version__ = '0.0.8'


class InactiveDueCreditCollector(object):
"""Just a stub at the Collector which would not do anything"""
def _donothing(self, *args, **kwargs):
"""Perform no good and no bad"""
pass

def dcite(self, *args, **kwargs):
"""If I could cite I would"""
def nondecorating_decorator(func):
return func
return nondecorating_decorator

active = False
activate = add = cite = dump = load = _donothing

def __repr__(self):
return self.__class__.__name__ + '()'


def _donothing_func(*args, **kwargs):
"""Perform no good and no bad"""
pass


try:
from duecredit import due, BibTeX, Doi, Url, Text
if 'due' in locals() and not hasattr(due, 'cite'):
raise RuntimeError(
"Imported due lacks .cite. DueCredit is now disabled")
except Exception as e:
if not isinstance(e, ImportError):
import logging
logging.getLogger("duecredit").error(
"Failed to import duecredit due to %s" % str(e))
# Initiate due stub
due = InactiveDueCreditCollector()
BibTeX = Doi = Url = Text = _donothing_func

# Emacs mode definitions
# Local Variables:
# mode: python
# py-indent-offset: 4
# tab-width: 4
# indent-tabs-mode: nil
# End:
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ include_package_data = True
# e.g. import whenever pynwb fails without them
extensions =
allensdk
extras =
duecredit
style =
flake8
pre-commit
Expand All @@ -83,6 +85,7 @@ tools=
all =
#%(doc)s
%(extensions)s
%(extras)s
%(style)s
%(test)s
%(tools)s
Expand Down

0 comments on commit 194ce14

Please sign in to comment.