Skip to content

Commit d86fa78

Browse files
committed
ENH: Run memoized check_version at REPL import, Node/Workflow/Interface init
1 parent 72964f4 commit d86fa78

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

nipype/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
absolute_import)
66

77
import os
8+
import functools
89
from distutils.version import LooseVersion
910

1011
from .info import (LONG_DESCRIPTION as __doc__, URL as __url__, STATUS as
@@ -58,6 +59,7 @@ def get_info():
5859
Rename, Function, Select, Merge)
5960

6061

62+
@functools.lru_cache()
6163
def check_version(raise_exception=False):
6264
"""Check for the latest version of the library
6365
@@ -95,5 +97,8 @@ def check_version(raise_exception=False):
9597
logger.critical(message)
9698

9799

100+
# Run telemetry on import for interactive sessions, such as IPython, Jupyter notebooks, Python REPL
98101
if config.getboolean('execution', 'check_version'):
99-
check_version()
102+
import __main__
103+
if not hasattr(__main__, '__file__'):
104+
check_version()

nipype/interfaces/base/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ class BaseInterface(Interface):
169169

170170
def __init__(self, from_file=None, resource_monitor=None,
171171
ignore_exception=False, **inputs):
172+
if config.getboolean('execution', 'check_version'):
173+
from ... import check_version
174+
check_version()
175+
172176
if not self.input_spec:
173177
raise Exception(
174178
'No input_spec in class: %s' % self.__class__.__name__)

nipype/pipeline/engine/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __init__(self, name=None, base_dir=None):
4141

4242
self.base_dir = base_dir
4343
self.config = deepcopy(config._sections)
44+
if config.getboolean('execution', 'check_version'):
45+
from ... import check_version
46+
check_version()
4447

4548
@property
4649
def name(self):

0 commit comments

Comments
 (0)