Skip to content

Commit 6310a14

Browse files
authored
Merge pull request #2782 from oesteban/enh/get-dependencies
[MAINT] Reduce minimal code redundancy in filemanip.get_dependencies
2 parents 32d3dfa + 060cc49 commit 6310a14

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

nipype/utils/filemanip.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -880,24 +880,29 @@ def get_dependencies(name, environ):
880880
Uses otool on darwin, ldd on linux. Currently doesn't support windows.
881881
882882
"""
883+
command = None
883884
if sys.platform == 'darwin':
884-
proc = sp.Popen(
885-
'otool -L `which %s`' % name,
886-
stdout=sp.PIPE,
887-
stderr=sp.PIPE,
888-
shell=True,
889-
env=environ)
885+
command = 'otool -L `which %s`' % name
890886
elif 'linux' in sys.platform:
887+
command = 'ldd `which %s`' % name
888+
else:
889+
return 'Platform %s not supported' % sys.platform
890+
891+
deps = None
892+
try:
891893
proc = sp.Popen(
892-
'ldd `which %s`' % name,
894+
command,
893895
stdout=sp.PIPE,
894896
stderr=sp.PIPE,
895897
shell=True,
896898
env=environ)
897-
else:
898-
return 'Platform %s not supported' % sys.platform
899-
o, e = proc.communicate()
900-
return o.rstrip()
899+
o, e = proc.communicate()
900+
deps = o.rstrip()
901+
except Exception as ex:
902+
deps = '"%s" failed' % command
903+
fmlogger.warning('Could not get dependencies of %s. Error:\n%s',
904+
name, ex.message)
905+
return deps
901906

902907

903908
def canonicalize_env(env):

0 commit comments

Comments
 (0)