Skip to content

WIP/REF/FIX: Don't throw away exception stack traces #1490

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 10 commits into from
Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ install:
- if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then conda install --yes vtk; fi
- pip install python-coveralls
- pip install nose-cov
- pip install mock
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be removed from here and added to https://github.com/nipy/nipype/blob/master/nipype/info.py? Same thing goes for circle.yml. (this way users will be able to run tests)

# 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 circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
# Set up python environment
- pip install --upgrade pip
- pip install -e .
- pip install matplotlib sphinx ipython boto coverage dipy
- pip install matplotlib sphinx ipython boto coverage dipy mock
# Add tvtk
- pip install http://effbot.org/downloads/Imaging-1.1.7.tar.gz
- pip install -e git+https://github.com/enthought/etsdevtools.git#egg=etsdevtools
Expand Down
7 changes: 4 additions & 3 deletions nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import division
from builtins import zip
from builtins import range
from future.utils import raise_from

import os
import os.path as op
Expand Down Expand Up @@ -857,9 +858,9 @@ def __init__(self, infields=None, force_run=True, **kwargs):
def _run_interface(self, runtime):
try:
import pandas as pd
except ImportError:
raise ImportError(('This interface requires pandas '
'(http://pandas.pydata.org/) to run.'))
except ImportError as e:
raise_from(ImportError('This interface requires pandas '
'(http://pandas.pydata.org/) to run.'), e)

try:
import lockfile as pl
Expand Down
56 changes: 40 additions & 16 deletions nipype/external/six.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
import types

__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.9.0"
__version__ = "1.10.0"


# Useful for very coarse version differentiation.
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
PY34 = sys.version_info[0:2] >= (3, 4)

if PY3:
string_types = str,
Expand All @@ -57,6 +58,7 @@
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):

def __len__(self):
return 1 << 31
try:
Expand Down Expand Up @@ -160,6 +162,7 @@ def _resolve(self):


class _SixMetaPathImporter(object):

"""
A meta path importer to import six.moves and its submodules.

Expand Down Expand Up @@ -224,6 +227,7 @@ def get_code(self, fullname):


class _MovedItems(_LazyModule):

"""Lazy loading of moved objects"""
__path__ = [] # mark as package

Expand All @@ -235,8 +239,10 @@ class _MovedItems(_LazyModule):
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("intern", "__builtin__", "sys"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"),
MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"),
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("shlex_quote", "pipes", "shlex", "quote"),
MovedAttribute("StringIO", "StringIO", "io"),
Expand All @@ -246,7 +252,6 @@ class _MovedItems(_LazyModule):
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"),

MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
Expand Down Expand Up @@ -293,8 +298,13 @@ class _MovedItems(_LazyModule):
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"),
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"),
MovedModule("winreg", "_winreg"),
]
# Add windows specific modules.
if sys.platform == "win32":
_moved_attributes += [
MovedModule("winreg", "_winreg"),
]

for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
if isinstance(attr, MovedModule):
Expand All @@ -308,6 +318,7 @@ class _MovedItems(_LazyModule):


class Module_six_moves_urllib_parse(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_parse"""


Expand Down Expand Up @@ -347,6 +358,7 @@ class Module_six_moves_urllib_parse(_LazyModule):


class Module_six_moves_urllib_error(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_error"""


Expand All @@ -366,6 +378,7 @@ class Module_six_moves_urllib_error(_LazyModule):


class Module_six_moves_urllib_request(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_request"""


Expand Down Expand Up @@ -415,6 +428,7 @@ class Module_six_moves_urllib_request(_LazyModule):


class Module_six_moves_urllib_response(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_response"""


Expand All @@ -435,6 +449,7 @@ class Module_six_moves_urllib_response(_LazyModule):


class Module_six_moves_urllib_robotparser(_LazyModule):

"""Lazy loading of moved objects in six.moves.urllib_robotparser"""


Expand All @@ -452,6 +467,7 @@ class Module_six_moves_urllib_robotparser(_LazyModule):


class Module_six_moves_urllib(types.ModuleType):

"""Create a six.moves.urllib namespace that resembles the Python 3 namespace"""
__path__ = [] # mark as package
parse = _importer._get_module("moves.urllib_parse")
Expand Down Expand Up @@ -522,6 +538,9 @@ def get_unbound_function(unbound):

create_bound_method = types.MethodType

def create_unbound_method(func, cls):
return func

Iterator = object
else:
def get_unbound_function(unbound):
Expand All @@ -530,6 +549,9 @@ def get_unbound_function(unbound):
def create_bound_method(func, obj):
return types.MethodType(func, obj, obj.__class__)

def create_unbound_method(func, cls):
return types.MethodType(func, None, cls)

class Iterator(object):

def next(self):
Expand Down Expand Up @@ -568,16 +590,16 @@ def iterlists(d, **kw):
viewitems = operator.methodcaller("items")
else:
def iterkeys(d, **kw):
return iter(d.iterkeys(**kw))
return d.iterkeys(**kw)

def itervalues(d, **kw):
return iter(d.itervalues(**kw))
return d.itervalues(**kw)

def iteritems(d, **kw):
return iter(d.iteritems(**kw))
return d.iteritems(**kw)

def iterlists(d, **kw):
return iter(d.iterlists(**kw))
return d.iterlists(**kw)

viewkeys = operator.methodcaller("viewkeys")

Expand All @@ -600,21 +622,22 @@ def b(s):
def u(s):
return s
unichr = chr
if sys.version_info[1] <= 1:
def int2byte(i):
return bytes((i,))
else:
# This is about 2x faster than the implementation above on 3.2+
int2byte = operator.methodcaller("to_bytes", 1, "big")
import struct
int2byte = struct.Struct(">B").pack
del struct
byte2int = operator.itemgetter(0)
indexbytes = operator.getitem
iterbytes = iter
import io
StringIO = io.StringIO
BytesIO = io.BytesIO
_assertCountEqual = "assertCountEqual"
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
if sys.version_info[1] <= 1:
_assertRaisesRegex = "assertRaisesRegexp"
_assertRegex = "assertRegexpMatches"
else:
_assertRaisesRegex = "assertRaisesRegex"
_assertRegex = "assertRegex"
else:
def b(s):
return s
Expand Down Expand Up @@ -780,6 +803,7 @@ def with_metaclass(meta, *bases):
# metaclass for one level of class instantiation that replaces itself with
# the actual metaclass.
class metaclass(meta):

def __new__(cls, name, this_bases, d):
return meta(name, bases, d)
return type.__new__(metaclass, 'temporary_class', (), {})
Expand Down
5 changes: 3 additions & 2 deletions nipype/interfaces/afni/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from sys import platform
from builtins import object
from future.utils import raise_from

from ... import logging
from ...utils.filemanip import split_filename
Expand Down Expand Up @@ -82,9 +83,9 @@ def outputtype_to_ext(cls, outputtype):

try:
return cls.ftypes[outputtype]
except KeyError:
except KeyError as e:
msg = 'Invalid AFNIOUTPUTTYPE: ', outputtype
raise KeyError(msg)
raise_from(KeyError(msg), e)

@classmethod
def outputtype(cls):
Expand Down
17 changes: 10 additions & 7 deletions nipype/pipeline/plugins/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from future import standard_library
standard_library.install_aliases()
from future.utils import raise_from

from pickle import dumps

import sys
Expand Down Expand Up @@ -62,19 +64,20 @@ def run(self, graph, config, updatehash=False):
name = 'ipyparallel'
__import__(name)
self.iparallel = sys.modules[name]
except ImportError:
raise ImportError("ipyparallel not found. Parallel execution "
"will be unavailable")
except ImportError as e:
raise_from(ImportError("ipyparallel not found. Parallel execution "
"will be unavailable"), e)
try:
self.taskclient = self.iparallel.Client()
except Exception as e:
if isinstance(e, TimeoutError):
raise Exception("No IPython clients found.")
raise_from(Exception("No IPython clients found."), e)
if isinstance(e, IOError):
raise Exception("ipcluster/ipcontroller has not been started")
raise_from(Exception("ipcluster/ipcontroller has not been started"), e)
if isinstance(e, ValueError):
raise Exception("Ipython kernel not installed")
raise e
raise_from(Exception("Ipython kernel not installed"), e)
else:
raise e
return super(IPythonPlugin, self).run(graph, config, updatehash=updatehash)

def _get_result(self, taskid):
Expand Down
11 changes: 6 additions & 5 deletions nipype/pipeline/plugins/ipythonx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import sys
from future.utils import raise_from

from ...interfaces.base import LooseVersion
IPython_not_loaded = False
Expand Down Expand Up @@ -44,16 +45,16 @@ def run(self, graph, config, updatehash=False):
name = 'IPython.kernel.client'
__import__(name)
self.ipyclient = sys.modules[name]
except ImportError:
raise ImportError("Ipython kernel not found. Parallel execution "
"will be unavailable")
except ImportError as e:
raise_from(ImportError("Ipython kernel not found. Parallel execution "
"will be unavailable"), e)
try:
self.taskclient = self.ipyclient.TaskClient()
except Exception as e:
if isinstance(e, ConnectionRefusedError):
raise Exception("No IPython clients found.")
raise_from(Exception("No IPython clients found."), e)
if isinstance(e, ValueError):
raise Exception("Ipython kernel not installed")
raise_from(Exception("Ipython kernel not installed"), e)
return super(IPythonXPlugin, self).run(graph, config, updatehash=updatehash)

def _get_result(self, taskid):
Expand Down
13 changes: 12 additions & 1 deletion nipype/testing/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import os
import warnings
import subprocess
from mock import patch, MagicMock
from nipype.testing.utils import TempFATFS
from nose.tools import assert_true
from nose.tools import assert_true, assert_raises


def test_tempfatfs():
Expand All @@ -17,3 +19,12 @@ def test_tempfatfs():
else:
with fatfs as tmpdir:
yield assert_true, os.path.exists(tmpdir)

@patch('subprocess.check_call', MagicMock(
side_effect=subprocess.CalledProcessError('','')))
def test_tempfatfs_calledprocesserror():
yield assert_raises, IOError, TempFATFS

@patch('subprocess.Popen', MagicMock(side_effect=OSError()))
def test_tempfatfs_oserror():
yield assert_raises, IOError, TempFATFS
10 changes: 5 additions & 5 deletions nipype/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from tempfile import mkdtemp
from ..utils.misc import package_check
from nose import SkipTest

from future.utils import raise_from

def skip_if_no_package(*args, **kwargs):
"""Raise SkipTest if package_check fails
Expand Down Expand Up @@ -62,15 +62,15 @@ def __init__(self, size_in_mbytes=8, delay=0.5):
try:
subprocess.check_call(args=mkfs_args, stdout=self.dev_null,
stderr=self.dev_null)
except subprocess.CalledProcessError:
raise IOError("mkfs.vfat failed")
except subprocess.CalledProcessError as e:
raise_from(IOError("mkfs.vfat failed"), e)

try:
self.fusefat = subprocess.Popen(args=mount_args,
stdout=self.dev_null,
stderr=self.dev_null)
except OSError:
raise IOError("fusefat is not installed")
except OSError as e:
raise_from(IOError("fusefat is not installed"), e)

time.sleep(self.delay)

Expand Down
Loading