Skip to content

ENH: Delay etelemetry for non-interactive sessions, report bad versions #3049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .et
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{ "bad_versions" : [ "1.2.1",
"1.2.3"]
Comment on lines +1 to +2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be checked and updated before release.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are legitimately buggy. We can really only plausibly check back to 1.3.0, since this functionality will be missing before that. Is it worth looking for critical bugs in earlier release logs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was more about whether even these two were correct. from a usage perspective, nothing will change till the server starts reading these .et files and returning the info. i'll update the server soon.

}
47 changes: 39 additions & 8 deletions nipype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

config = NipypeConfig()
logging = Logging(config)
logger = logging.getLogger('nipype.utils')

INIT_MSG = "Running {packname} version {version} (latest: {latest})".format

class NipypeTester(object):
def __call__(self, doctests=True, parallel=False):
Expand Down Expand Up @@ -60,15 +58,48 @@ def get_info():
Rename, Function, Select, Merge)


if config.getboolean('execution', 'check_version'):
def check_latest_version(raise_exception=False):
"""Check for the latest version of the library

parameters:
raise_exception: boolean
Raise a RuntimeError if a bad version is being used
"""
import etelemetry
logger = logging.getLogger('nipype.utils')

INIT_MSG = "Running {packname} version {version} (latest: {latest})".format

latest = {"version": 'Unknown'}
latest = {"version": 'Unknown', "bad_versions": []}
result = None
try:
latest = etelemetry.get_project("nipy/nipype")
result = etelemetry.get_project("nipy/nipype")
except Exception as e:
logger.warning("Could not check for version updates: \n%s", e)
finally:
logger.info(INIT_MSG(packname='nipype',
version=__version__,
latest=latest["version"]))
if result:
latest.update(**result)
if LooseVersion(__version__) != LooseVersion(latest["version"]):
logger.info(INIT_MSG(packname='nipype',
version=__version__,
latest=latest["version"]))
if latest["bad_versions"] and \
any([LooseVersion(__version__) == LooseVersion(ver)
for ver in latest["bad_versions"]]):
message = ('You are using a version of Nipype with a critical '
'bug. Please use a different version.')
if raise_exception:
raise RuntimeError(message)
else:
logger.critical(message)
else:
latest = None
return latest

# Run telemetry on import for interactive sessions, such as IPython, Jupyter notebooks, Python REPL
if config.getboolean('execution', 'check_version'):
import __main__
if not hasattr(__main__, '__file__'):
from .interfaces.base import BaseInterface
if BaseInterface._etelemetry_version_data is None:
BaseInterface._etelemetry_version_data = check_latest_version()
6 changes: 6 additions & 0 deletions nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,15 @@ class BaseInterface(Interface):
_redirect_x = False
references_ = []
resource_monitor = True # Enabled for this interface IFF enabled in the config
_etelemetry_version_data = None

def __init__(self, from_file=None, resource_monitor=None,
ignore_exception=False, **inputs):
if config.getboolean('execution', 'check_version'):
from ... import check_latest_version
if BaseInterface._etelemetry_version_data is None:
BaseInterface._etelemetry_version_data = check_latest_version()

if not self.input_spec:
raise Exception(
'No input_spec in class: %s' % self.__class__.__name__)
Expand Down