Skip to content

[MAINT] Reduce minimal code redundancy in filemanip.get_dependencies #2782

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 2 commits into from
Dec 14, 2018
Merged
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
27 changes: 16 additions & 11 deletions nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,24 +880,29 @@ 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:
command = 'ldd `which %s`' % name
else:
return 'Platform %s not supported' % sys.platform

deps = None
try:
proc = sp.Popen(
'ldd `which %s`' % name,
command,
stdout=sp.PIPE,
stderr=sp.PIPE,
shell=True,
env=environ)
else:
return 'Platform %s not supported' % sys.platform
o, e = proc.communicate()
return o.rstrip()
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):
Expand Down