Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract have_otool.

  • Loading branch information...
commit 151441f1dba6ecf102c51cb00fab2e7accf33261 1 parent bf62a36
@stefanholek authored
Showing with 28 additions and 19 deletions.
  1. +28 −19 setup.py
View
47 setup.py
@@ -140,17 +140,19 @@ def build_extension(self, ext):
termcap = ''
# Find a termcap library
- if 'readline' in ext.libraries:
- readline = self.compiler.find_library_file(lib_dirs, 'readline')
- termcap = self.get_termcap_from(readline)
+ if self.have_otool():
- if not termcap:
- pyreadline = join(lib_dynload, 'readline.so')
- termcap = self.get_termcap_from(pyreadline)
+ if 'readline' in ext.libraries:
+ readline = self.compiler.find_library_file(lib_dirs, 'readline')
+ termcap = self.get_termcap_from(readline)
- if not termcap:
- pycurses = join(lib_dynload, '_curses.so')
- termcap = self.get_termcap_from(pycurses)
+ if not termcap:
+ pyreadline = join(lib_dynload, 'readline.so')
+ termcap = self.get_termcap_from(pyreadline)
+
+ if not termcap:
+ pycurses = join(lib_dynload, '_curses.so')
+ termcap = self.get_termcap_from(pycurses)
if not termcap:
for name in ['tinfo', 'ncursesw', 'ncurses', 'cursesw', 'curses', 'termcap']:
@@ -167,20 +169,27 @@ def build_extension(self, ext):
return build_ext.build_extension(self, ext)
+ def have_otool(self):
+ if sys.platform == 'darwin':
+ cmd = 'otool'
+ else:
+ cmd = 'ldd'
+ if not find_executable(cmd):
+ log.warn('WARNING: Command not found: %s' % cmd)
+ return False
+ return True
+
def get_termcap_from(self, module):
if module and exists(module):
- fp = None
if sys.platform == 'darwin':
- if find_executable('otool'):
- fp = os.popen('otool -L "%s"' % module)
- elif find_executable('ldd'):
- fp = os.popen('ldd "%s"' % module)
- if fp is not None:
+ cmd = 'otool -L "%s"' % module
+ else:
+ cmd = 'ldd "%s"' % module
+ with os.popen(cmd) as fp:
libraries = fp.read()
- fp.close()
- for name in ['tinfo', 'ncursesw', 'ncurses', 'cursesw', 'curses', 'termcap']:
- if 'lib%s.' % name in libraries:
- return name
+ for name in ['tinfo', 'ncursesw', 'ncurses', 'cursesw', 'curses', 'termcap']:
+ if 'lib%s.' % name in libraries:
+ return name
return ''
def configure_static_readline(self):
Please sign in to comment.
Something went wrong with that request. Please try again.