From b6a0f2a3c34b396ba5347e2a517cb9cb0f77d9b8 Mon Sep 17 00:00:00 2001 From: tsuraan Date: Wed, 9 Feb 2011 17:56:28 -0600 Subject: [PATCH 1/2] auto-detect installed luajit-2, and also a small correction for the README filename --- setup.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1d3bceb9..5c08da9f 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ +import subprocess import sys import os from distutils.core import setup, Extension @@ -25,10 +26,42 @@ extra_setup_args["zip_safe"] = False # check if LuaJIT is in a subdirectory and build statically against it +def cmd_status_output(command): + """Returns the exit code and output of the program, as a tuple""" + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + buff = [] + while proc.poll() is None: + buff.append(proc.stdout.read()) + + exit_code = proc.wait() + buff.append(proc.stdout.read()) + print 'returning', (exit_code, ''.join(buff)) + return (exit_code, ''.join(buff)) + +def luajit2_installed(): + if (cmd_status_output('pkg-config luajit --exists')[0] == 0) and \ + (cmd_status_output('pkg-config luajit --modversion')[1][0] == '2'): + return True + return False + +def lua_include(): + line = cmd_status_output('pkg-config luajit --cflags-only-I')[1] + def trim_i(s): + if s.startswith('-I'): + return s[2:] + return s + return map(trim_i, filter(None, line.split())) + +def lua_libs(): + line = cmd_status_output('pkg-config luajit --libs')[1] + return filter(None, line.split()) basedir = os.path.abspath(os.path.dirname(__file__)) def find_luajit_build(): + if luajit2_installed(): + return dict(extra_objects=lua_libs(), include_dirs=lua_include()) + static_libs = [] include_dirs = [] @@ -80,7 +113,7 @@ def write_file(filename, content): long_description = '\n\n'.join([ read_file(text_file) - for text_file in ['README.txt', 'INSTALL.txt', 'CHANGES.txt']]) + for text_file in ['README.rst', 'INSTALL.txt', 'CHANGES.txt']]) write_file(os.path.join('lupa', 'version.py'), "__version__ = '%s'\n" % VERSION) From 975b7f710f53297da8aae4b301889f89f31f630d Mon Sep 17 00:00:00 2001 From: tsuraan Date: Thu, 10 Feb 2011 11:29:50 -0600 Subject: [PATCH 2/2] using process.communicate rather than my hack, raising exceptions rather than silently failing, and all prints are pythin3 compatible --- setup.py | 58 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/setup.py b/setup.py index 5c08da9f..45940e4a 100644 --- a/setup.py +++ b/setup.py @@ -26,41 +26,59 @@ extra_setup_args["zip_safe"] = False # check if LuaJIT is in a subdirectory and build statically against it -def cmd_status_output(command): - """Returns the exit code and output of the program, as a tuple""" - proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) - buff = [] - while proc.poll() is None: - buff.append(proc.stdout.read()) - +def cmd_output(command): + """ + Returns the exit code and output of the program, as a triplet of the form + (exit_code, stdout, stderr). + """ + proc = subprocess.Popen(command, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = proc.communicate() exit_code = proc.wait() - buff.append(proc.stdout.read()) - print 'returning', (exit_code, ''.join(buff)) - return (exit_code, ''.join(buff)) + if exit_code != 0: + raise RuntimeError(stderr) + return stdout -def luajit2_installed(): - if (cmd_status_output('pkg-config luajit --exists')[0] == 0) and \ - (cmd_status_output('pkg-config luajit --modversion')[1][0] == '2'): - return True - return False +def check_luajit2_installed(): + try: + cmd_output('pkg-config luajit --exists') + except RuntimeError, e: + # pkg-config gives no stdout when it is given --exists and it cannot + # find the package, so we'll give it some better output + if not e.args[0]: + raise RuntimeError("pkg-config cannot find an installed luajit") + raise + + version_out = cmd_output('pkg-config luajit --modversion') + if version_out[0] != '2': + raise RuntimeError("Expected version 2+ of luajit, but found %s" % + version_out) def lua_include(): - line = cmd_status_output('pkg-config luajit --cflags-only-I')[1] + cflag_out = cmd_output('pkg-config luajit --cflags-only-I') + def trim_i(s): if s.startswith('-I'): return s[2:] return s - return map(trim_i, filter(None, line.split())) + return map(trim_i, filter(None, cflag_out.split())) def lua_libs(): - line = cmd_status_output('pkg-config luajit --libs')[1] - return filter(None, line.split()) + libs_out = cmd_output('pkg-config luajit --libs') + return filter(None, libs_out.split()) basedir = os.path.abspath(os.path.dirname(__file__)) def find_luajit_build(): - if luajit2_installed(): + try: + check_luajit2_installed() return dict(extra_objects=lua_libs(), include_dirs=lua_include()) + except RuntimeError, e: + print("Error finding installed luajit-2:") + print(e.args[0]) + print("Proceding with detection of local luajit-2") static_libs = [] include_dirs = []