From 8c65fbf0b9a1a290545f4a807840cbd11e9f2edc Mon Sep 17 00:00:00 2001 From: oesteban Date: Thu, 15 Nov 2018 14:56:02 -0800 Subject: [PATCH 1/2] [MAINT] Reduce minimal code redundancy in filemanip.get_dependencies --- nipype/utils/filemanip.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 8bf4c456d2..6058b9f204 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -880,22 +880,20 @@ def get_dependencies(name, environ): Uses otool on darwin, ldd on linux. Currently doesn't support windows. """ + command = None if sys.platform == 'darwin': - proc = sp.Popen( - 'otool -L `which %s`' % name, - stdout=sp.PIPE, - stderr=sp.PIPE, - shell=True, - env=environ) + command = 'otool -L `which %s`' % name elif 'linux' in sys.platform: - proc = sp.Popen( - 'ldd `which %s`' % name, - stdout=sp.PIPE, - stderr=sp.PIPE, - shell=True, - env=environ) + command = 'ldd `which %s`' % name else: return 'Platform %s not supported' % sys.platform + + proc = sp.Popen( + command, + stdout=sp.PIPE, + stderr=sp.PIPE, + shell=True, + env=environ) o, e = proc.communicate() return o.rstrip() From 060cc4968a439be3a1a06f3b89aa1a70dda2adfb Mon Sep 17 00:00:00 2001 From: oesteban Date: Thu, 15 Nov 2018 15:05:50 -0800 Subject: [PATCH 2/2] more reliable get_dependencies --- nipype/utils/filemanip.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 6058b9f204..bf73335d8f 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -888,14 +888,21 @@ def get_dependencies(name, environ): else: return 'Platform %s not supported' % sys.platform - proc = sp.Popen( - command, - stdout=sp.PIPE, - stderr=sp.PIPE, - shell=True, - env=environ) - o, e = proc.communicate() - return o.rstrip() + deps = None + try: + proc = sp.Popen( + command, + stdout=sp.PIPE, + stderr=sp.PIPE, + shell=True, + env=environ) + o, e = proc.communicate() + deps = o.rstrip() + except Exception as ex: + deps = '"%s" failed' % command + fmlogger.warning('Could not get dependencies of %s. Error:\n%s', + name, ex.message) + return deps def canonicalize_env(env):