Skip to content

Commit 0f2cb9f

Browse files
authored
Merge pull request #1466 from alexsavio/enh/duecredit
WIP Add duecredit entries
2 parents b05d153 + 8dd8468 commit 0f2cb9f

File tree

7 files changed

+129
-3
lines changed

7 files changed

+129
-3
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ python:
88
env:
99
- INSTALL_DEB_DEPENDECIES=true
1010
- INSTALL_DEB_DEPENDECIES=false
11+
- INSTALL_DEB_DEPENDECIES=true DUECREDIT_ENABLE=yes
1112
before_install:
1213
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then wget http://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
1314
-O miniconda.sh; else wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
@@ -45,6 +46,7 @@ install:
4546
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then conda install --yes vtk; fi
4647
- pip install python-coveralls
4748
- pip install nose-cov
49+
- if [ ! -z "$DUECREDIT_ENABLE"]; then pip install --user -v duecredit; fi
4850
# Add tvtk (PIL is required by blockcanvas)
4951
# Install mayavi (see https://github.com/enthought/mayavi/issues/271)
5052
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then

nipype/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
from distutils.version import LooseVersion
1717

1818
from .fixes.numpy.testing import nosetester
19+
from .refs import due
1920

2021
try:
2122
import faulthandler
2223
faulthandler.enable()
2324
except (ImportError,IOError) as e:
2425
pass
2526

26-
2727
class _NoseTester(nosetester.NoseTester):
2828
""" Subclass numpy's NoseTester to add doctests by default
2929
"""

nipype/external/due.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# emacs: at the end of the file
2+
# ex: set sts=4 ts=4 sw=4 et:
3+
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
4+
"""
5+
6+
Stub file for a guaranteed safe import of duecredit constructs: if duecredit
7+
is not available.
8+
9+
To use it, place it into your project codebase to be imported, e.g. copy as
10+
11+
cp stub.py /path/tomodule/module/due.py
12+
13+
Note that it might be better to avoid naming it duecredit.py to avoid shadowing
14+
installed duecredit.
15+
16+
Then use in your code as
17+
18+
from .due import due, Doi, BibTeX
19+
20+
See https://github.com/duecredit/duecredit/blob/master/README.md for examples.
21+
22+
Origin: Originally a part of the duecredit
23+
Copyright: 2015-2016 DueCredit developers
24+
License: BSD-2
25+
"""
26+
27+
__version__ = '0.0.5'
28+
29+
30+
class InactiveDueCreditCollector(object):
31+
"""Just a stub at the Collector which would not do anything"""
32+
def _donothing(self, *args, **kwargs):
33+
"""Perform no good and no bad"""
34+
pass
35+
36+
def dcite(self, *args, **kwargs):
37+
"""If I could cite I would"""
38+
def nondecorating_decorator(func):
39+
return func
40+
return nondecorating_decorator
41+
42+
cite = load = add = _donothing
43+
44+
def __repr__(self):
45+
return self.__class__.__name__ + '()'
46+
47+
48+
def _donothing_func(*args, **kwargs):
49+
"""Perform no good and no bad"""
50+
pass
51+
52+
try:
53+
from duecredit import due, BibTeX, Doi, Url
54+
if 'due' in locals() and not hasattr(due, 'cite'):
55+
raise RuntimeError(
56+
"Imported due lacks .cite. DueCredit is now disabled")
57+
except Exception as e:
58+
if type(e).__name__ != 'ImportError':
59+
import logging
60+
logging.getLogger("duecredit").error(
61+
"Failed to import duecredit due to %s" % str(e))
62+
# Initiate due stub
63+
due = InactiveDueCreditCollector()
64+
BibTeX = Doi = Url = _donothing_func
65+
66+
# Emacs mode definitions
67+
# Local Variables:
68+
# mode: python
69+
# py-indent-offset: 4
70+
# tab-width: 4
71+
# indent-tabs-mode: nil
72+
# End:

nipype/interfaces/base.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .. import config, logging, LooseVersion
5050
from .. import __version__
5151
from ..external.six import string_types, text_type
52+
from ..external.due import due
5253

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

@@ -757,6 +758,7 @@ class BaseInterface(Interface):
757758
_version = None
758759
_additional_metadata = []
759760
_redirect_x = False
761+
references_ = []
760762

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

781783
allhelp = '\n'.join(docstring + cls._inputs_help() + [''] +
782-
cls._outputs_help() + [''])
784+
cls._outputs_help() + [''] +
785+
cls._refs_help() + [''])
783786
if returnhelp:
784787
return allhelp
785788
else:
786789
print(allhelp)
787790

791+
@classmethod
792+
def _refs_help(cls):
793+
""" Prints interface references.
794+
"""
795+
helpstr = ['References::']
796+
797+
for r in cls.references_:
798+
helpstr += [repr(r['entry'])]
799+
800+
return helpstr
801+
788802
@classmethod
789803
def _get_trait_desc(self, inputs, name, spec):
790804
desc = spec.desc
@@ -1009,6 +1023,13 @@ def _run_interface(self, runtime):
10091023
"""
10101024
raise NotImplementedError
10111025

1026+
def _duecredit_cite(self):
1027+
""" Add the interface references to the duecredit citations
1028+
"""
1029+
for r in self.references_:
1030+
r['path'] = self.__module__
1031+
due.cite(**r)
1032+
10121033
def run(self, **inputs):
10131034
"""Execute this interface.
10141035
@@ -1028,6 +1049,8 @@ def run(self, **inputs):
10281049
self._check_mandatory_inputs()
10291050
self._check_version_requirements(self.inputs)
10301051
interface = self.__class__
1052+
self._duecredit_cite()
1053+
10311054
# initialize provenance tracking
10321055
env = deepcopy(dict(os.environ))
10331056
runtime = Bunch(cwd=os.getcwd(),

nipype/interfaces/spm/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from ..matlab import MatlabCommand
3333
from ...utils import spm_docs as sd
3434
from ...external.six import string_types
35+
from ...external.due import due, Doi, BibTeX
3536
from ... import logging
3637
logger = logging.getLogger('interface')
3738

@@ -235,6 +236,17 @@ class SPMCommand(BaseInterface):
235236
_paths = None
236237
_use_mcr = None
237238

239+
references_ = [{'entry': BibTeX("@book{FrackowiakFristonFrithDolanMazziotta1997,"
240+
"author={R.S.J. Frackowiak, K.J. Friston, C.D. Frith, R.J. Dolan, and J.C. Mazziotta},"
241+
"title={Human Brain Function},"
242+
"publisher={Academic Press USA},"
243+
"year={1997},"
244+
"}"),
245+
'description': 'The fundamental text on Statistical Parametric Mapping (SPM)',
246+
# 'path': "nipype.interfaces.spm",
247+
'tags': ['implementation'],
248+
}]
249+
238250
def __init__(self, **inputs):
239251
super(SPMCommand, self).__init__(**inputs)
240252
self.inputs.on_trait_change(self._matlab_cmd_update, ['matlab_cmd',

nipype/refs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Use duecredit (duecredit.org) to provide a citation to relevant work to
3+
# be cited. This does nothing, unless the user has duecredit installed,
4+
# And calls this with duecredit (as in `python -m duecredit script.py`):
5+
from .external.due import due, Doi, BibTeX
6+
7+
due.cite(Doi("10.3389/fninf.2011.00013"),
8+
description="A flexible, lightweight and extensible neuroimaging data"
9+
" processing framework in Python",
10+
path="nipype",
11+
tags=["implementation"],)
12+
13+
due.cite(Doi("10.5281/zenodo.50186"),
14+
description="A flexible, lightweight and extensible neuroimaging data"
15+
" processing framework in Python",
16+
path="nipype",
17+
tags=["implementation"],)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _package_status(pkg_name, version, version_getter, checker):
248248

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

253253
# Prepare setuptools args
254254
if 'setuptools' in sys.modules:

0 commit comments

Comments
 (0)