Skip to content

Commit

Permalink
Merge pull request #1466 from alexsavio/enh/duecredit
Browse files Browse the repository at this point in the history
WIP Add duecredit entries
  • Loading branch information
chrisgorgo committed Sep 6, 2016
2 parents b05d153 + 8dd8468 commit 0f2cb9f
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ python:
env:
- INSTALL_DEB_DEPENDECIES=true
- INSTALL_DEB_DEPENDECIES=false
- INSTALL_DEB_DEPENDECIES=true DUECREDIT_ENABLE=yes
before_install:
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then wget http://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
-O miniconda.sh; else wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
Expand Down Expand Up @@ -45,6 +46,7 @@ install:
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then conda install --yes vtk; fi
- pip install python-coveralls
- pip install nose-cov
- if [ ! -z "$DUECREDIT_ENABLE"]; then pip install --user -v duecredit; fi
# Add tvtk (PIL is required by blockcanvas)
# Install mayavi (see https://github.com/enthought/mayavi/issues/271)
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then
Expand Down
2 changes: 1 addition & 1 deletion nipype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
from distutils.version import LooseVersion

from .fixes.numpy.testing import nosetester
from .refs import due

try:
import faulthandler
faulthandler.enable()
except (ImportError,IOError) as e:
pass


class _NoseTester(nosetester.NoseTester):
""" Subclass numpy's NoseTester to add doctests by default
"""
Expand Down
72 changes: 72 additions & 0 deletions nipype/external/due.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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
See https://github.com/duecredit/duecredit/blob/master/README.md for examples.
Origin: Originally a part of the duecredit
Copyright: 2015-2016 DueCredit developers
License: BSD-2
"""

__version__ = '0.0.5'


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

cite = load = add = _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
if 'due' in locals() and not hasattr(due, 'cite'):
raise RuntimeError(
"Imported due lacks .cite. DueCredit is now disabled")
except Exception as e:
if type(e).__name__ != 'ImportError':
import logging
logging.getLogger("duecredit").error(
"Failed to import duecredit due to %s" % str(e))
# Initiate due stub
due = InactiveDueCreditCollector()
BibTeX = Doi = Url = _donothing_func

# Emacs mode definitions
# Local Variables:
# mode: python
# py-indent-offset: 4
# tab-width: 4
# indent-tabs-mode: nil
# End:
25 changes: 24 additions & 1 deletion nipype/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from .. import config, logging, LooseVersion
from .. import __version__
from ..external.six import string_types, text_type
from ..external.due import due

runtime_profile = str2bool(config.get('execution', 'profile_runtime'))

Expand Down Expand Up @@ -757,6 +758,7 @@ class BaseInterface(Interface):
_version = None
_additional_metadata = []
_redirect_x = False
references_ = []

def __init__(self, **inputs):
if not self.input_spec:
Expand All @@ -779,12 +781,24 @@ def help(cls, returnhelp=False):
docstring = ['']

allhelp = '\n'.join(docstring + cls._inputs_help() + [''] +
cls._outputs_help() + [''])
cls._outputs_help() + [''] +
cls._refs_help() + [''])
if returnhelp:
return allhelp
else:
print(allhelp)

@classmethod
def _refs_help(cls):
""" Prints interface references.
"""
helpstr = ['References::']

for r in cls.references_:
helpstr += [repr(r['entry'])]

return helpstr

@classmethod
def _get_trait_desc(self, inputs, name, spec):
desc = spec.desc
Expand Down Expand Up @@ -1009,6 +1023,13 @@ def _run_interface(self, runtime):
"""
raise NotImplementedError

def _duecredit_cite(self):
""" Add the interface references to the duecredit citations
"""
for r in self.references_:
r['path'] = self.__module__
due.cite(**r)

def run(self, **inputs):
"""Execute this interface.
Expand All @@ -1028,6 +1049,8 @@ def run(self, **inputs):
self._check_mandatory_inputs()
self._check_version_requirements(self.inputs)
interface = self.__class__
self._duecredit_cite()

# initialize provenance tracking
env = deepcopy(dict(os.environ))
runtime = Bunch(cwd=os.getcwd(),
Expand Down
12 changes: 12 additions & 0 deletions nipype/interfaces/spm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from ..matlab import MatlabCommand
from ...utils import spm_docs as sd
from ...external.six import string_types
from ...external.due import due, Doi, BibTeX
from ... import logging
logger = logging.getLogger('interface')

Expand Down Expand Up @@ -235,6 +236,17 @@ class SPMCommand(BaseInterface):
_paths = None
_use_mcr = None

references_ = [{'entry': BibTeX("@book{FrackowiakFristonFrithDolanMazziotta1997,"
"author={R.S.J. Frackowiak, K.J. Friston, C.D. Frith, R.J. Dolan, and J.C. Mazziotta},"
"title={Human Brain Function},"
"publisher={Academic Press USA},"
"year={1997},"
"}"),
'description': 'The fundamental text on Statistical Parametric Mapping (SPM)',
# 'path': "nipype.interfaces.spm",
'tags': ['implementation'],
}]

def __init__(self, **inputs):
super(SPMCommand, self).__init__(**inputs)
self.inputs.on_trait_change(self._matlab_cmd_update, ['matlab_cmd',
Expand Down
17 changes: 17 additions & 0 deletions nipype/refs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# Use duecredit (duecredit.org) to provide a citation to relevant work to
# be cited. This does nothing, unless the user has duecredit installed,
# And calls this with duecredit (as in `python -m duecredit script.py`):
from .external.due import due, Doi, BibTeX

due.cite(Doi("10.3389/fninf.2011.00013"),
description="A flexible, lightweight and extensible neuroimaging data"
" processing framework in Python",
path="nipype",
tags=["implementation"],)

due.cite(Doi("10.5281/zenodo.50186"),
description="A flexible, lightweight and extensible neuroimaging data"
" processing framework in Python",
path="nipype",
tags=["implementation"],)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _package_status(pkg_name, version, version_getter, checker):

# Get version and release info, which is all stored in nipype/info.py
ver_file = os.path.join('nipype', 'info.py')
exec(open(ver_file).read())
exec(open(ver_file).read(), locals())

# Prepare setuptools args
if 'setuptools' in sys.modules:
Expand Down

0 comments on commit 0f2cb9f

Please sign in to comment.