Skip to content

Commit 6defc92

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix/Py3UseBuiltinOpen
2 parents cd4f89a + 0f2cb9f commit 6defc92

File tree

7 files changed

+130
-2
lines changed

7 files changed

+130
-2
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
- wget http://repo.continuum.io/miniconda/Miniconda${TRAVIS_PYTHON_VERSION:0:1}-latest-Linux-x86_64.sh
1314
-O /home/travis/.cache/miniconda.sh
@@ -32,6 +33,7 @@ install:
3233
# conda install -y vtk mayavi; fi
3334
- conda install -y nipype
3435
- pip install python-coveralls coverage doctest-ignore-unicode
36+
- if [ ! -z "$DUECREDIT_ENABLE"]; then pip install duecredit; fi
3537
- rm -r /home/travis/miniconda/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/nipype*
3638
- pip install -r requirements.txt
3739
- pip install -e .

nipype/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .utils.config import NipypeConfig
1414
from .fixes.numpy.testing import nosetester
1515
from .utils.logger import Logging
16+
from .refs import due
1617

1718
try:
1819
import faulthandler

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
@@ -41,6 +41,7 @@
4141
from .traits_extension import (
4242
traits, Undefined, TraitDictObject, TraitListObject, TraitError, isdefined, File,
4343
Directory, DictStrStr, has_metadata)
44+
from ..external.due import due
4445

4546
runtime_profile = str2bool(config.get('execution', 'profile_runtime'))
4647
nipype_version = LooseVersion(__version__)
@@ -753,6 +754,7 @@ class BaseInterface(Interface):
753754
_version = None
754755
_additional_metadata = []
755756
_redirect_x = False
757+
references_ = []
756758

757759
def __init__(self, **inputs):
758760
if not self.input_spec:
@@ -775,12 +777,24 @@ def help(cls, returnhelp=False):
775777
docstring = ['']
776778

777779
allhelp = '\n'.join(docstring + cls._inputs_help() + [''] +
778-
cls._outputs_help() + [''])
780+
cls._outputs_help() + [''] +
781+
cls._refs_help() + [''])
779782
if returnhelp:
780783
return allhelp
781784
else:
782785
print(allhelp)
783786

787+
@classmethod
788+
def _refs_help(cls):
789+
""" Prints interface references.
790+
"""
791+
helpstr = ['References::']
792+
793+
for r in cls.references_:
794+
helpstr += [repr(r['entry'])]
795+
796+
return helpstr
797+
784798
@classmethod
785799
def _get_trait_desc(self, inputs, name, spec):
786800
desc = spec.desc
@@ -1005,6 +1019,13 @@ def _run_interface(self, runtime):
10051019
"""
10061020
raise NotImplementedError
10071021

1022+
def _duecredit_cite(self):
1023+
""" Add the interface references to the duecredit citations
1024+
"""
1025+
for r in self.references_:
1026+
r['path'] = self.__module__
1027+
due.cite(**r)
1028+
10081029
def run(self, **inputs):
10091030
"""Execute this interface.
10101031
@@ -1024,6 +1045,8 @@ def run(self, **inputs):
10241045
self._check_mandatory_inputs()
10251046
self._check_version_requirements(self.inputs)
10261047
interface = self.__class__
1048+
self._duecredit_cite()
1049+
10271050
# initialize provenance tracking
10281051
env = deepcopy(dict(os.environ))
10291052
runtime = Bunch(cwd=os.getcwd(),

nipype/interfaces/spm/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
from ..base import (BaseInterface, traits, isdefined, InputMultiPath,
3333
BaseInterfaceInputSpec, Directory, Undefined)
3434
from ..matlab import MatlabCommand
35+
from ...external.due import due, Doi, BibTeX
36+
3537

3638
__docformat__ = 'restructuredtext'
3739
logger = logging.getLogger('interface')
@@ -234,6 +236,17 @@ class SPMCommand(BaseInterface):
234236
_paths = None
235237
_use_mcr = None
236238

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+
237250
def __init__(self, **inputs):
238251
super(SPMCommand, self).__init__(**inputs)
239252
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
@@ -241,7 +241,7 @@ def _package_status(pkg_name, version, version_getter, checker):
241241

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

246246
# Prepare setuptools args
247247
if 'setuptools' in sys.modules:

0 commit comments

Comments
 (0)