提交 c47e8ecc authored 作者: Olivier Delalleau's avatar Olivier Delalleau

A few PEP8 fixes

上级 ebe3e3b4
"""Generate and compile C modules for Python, """Generate and compile C modules for Python,
""" """
import atexit, cPickle, logging, operator, os, shutil, stat, StringIO import atexit
import subprocess, sys, tempfile, time import cPickle
import logging
import operator
import os
import shutil
import stat
import StringIO
import subprocess
import sys
import tempfile
import time
import distutils.sysconfig import distutils.sysconfig
...@@ -1268,16 +1278,20 @@ def std_lib_dirs_and_libs(): ...@@ -1268,16 +1278,20 @@ def std_lib_dirs_and_libs():
else: else:
# Typical include directory: /usr/include/python2.6 # Typical include directory: /usr/include/python2.6
libname = os.path.basename(python_inc) libname = os.path.basename(python_inc)
return [libname],[] return [libname], []
def std_libs(): def std_libs():
return std_lib_dirs_and_libs()[0] return std_lib_dirs_and_libs()[0]
def std_lib_dirs(): def std_lib_dirs():
return std_lib_dirs_and_libs()[1] return std_lib_dirs_and_libs()[1]
# Using the dummy file descriptors below is a workaround for a crash experienced
# in an unusual Python 2.4.4 Windows environment with the default None values. # Using the dummy file descriptors below is a workaround for a crash
# experienced in an unusual Python 2.4.4 Windows environment with the default
# None values.
dummy_in = open(os.devnull) dummy_in = open(os.devnull)
dummy_err = open(os.devnull, 'w') dummy_err = open(os.devnull, 'w')
p = None p = None
...@@ -1293,18 +1307,29 @@ del p ...@@ -1293,18 +1307,29 @@ del p
del dummy_in del dummy_in
del dummy_err del dummy_err
def gcc_version(): def gcc_version():
return gcc_version_str return gcc_version_str
def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[], lib_dirs=[], libs=[],
preargs=[]): def gcc_module_compile_str(module_name, src_code, location=None,
include_dirs=[], lib_dirs=[], libs=[], preargs=[]):
""" """
:param module_name: string (this has been embedded in the src_code :param module_name: string (this has been embedded in the src_code
:param src_code: a complete c or c++ source listing for the module :param src_code: a complete c or c++ source listing for the module
:param location: a pre-existing filesystem directory where the cpp file and .so will be written
:param include_dirs: a list of include directory names (each gets prefixed with -I) :param location: a pre-existing filesystem directory where the cpp file and
:param lib_dirs: a list of library search path directory names (each gets prefixed with -L) .so will be written
:param include_dirs: a list of include directory names (each gets prefixed
with -I)
:param lib_dirs: a list of library search path directory names (each gets
prefixed with -L)
:param libs: a list of libraries to link with (each gets prefixed with -l) :param libs: a list of libraries to link with (each gets prefixed with -l)
:param preargs: a list of extra compiler arguments :param preargs: a list of extra compiler arguments
:returns: dynamically-imported python module of the compiled code. :returns: dynamically-imported python module of the compiled code.
...@@ -1327,16 +1352,18 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[] ...@@ -1327,16 +1352,18 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
lib_dirs = std_lib_dirs() + lib_dirs lib_dirs = std_lib_dirs() + lib_dirs
#DSE Patch 1 for supporting OSX frameworks; add -framework Python #DSE Patch 1 for supporting OSX frameworks; add -framework Python
if sys.platform=='darwin' : if sys.platform == 'darwin':
preargs.extend(['-undefined','dynamic_lookup']) preargs.extend(['-undefined', 'dynamic_lookup'])
python_inc = distutils.sysconfig.get_python_inc() python_inc = distutils.sysconfig.get_python_inc()
# link with the framework library *if specifically requested* # link with the framework library *if specifically requested*
# config.mac_framework_link is by default False, since on some mac # config.mac_framework_link is by default False, since on some mac
# installs linking with -framework causes a Bus Error # installs linking with -framework causes a Bus Error
if python_inc.count('Python.framework')>0 and config.cmodule.mac_framework_link: if (python_inc.count('Python.framework') > 0 and
preargs.extend(['-framework','Python']) config.cmodule.mac_framework_link):
preargs.extend(['-framework', 'Python'])
# Figure out whether the current Python executable is 32 or 64 bit and compile accordingly # Figure out whether the current Python executable is 32 or 64 bit and
# compile accordingly.
n_bits = local_bitwidth() n_bits = local_bitwidth()
preargs.extend(['-m%s' % n_bits]) preargs.extend(['-m%s' % n_bits])
_logger.debug("OS X: compiling for %s bit architecture", n_bits) _logger.debug("OS X: compiling for %s bit architecture", n_bits)
...@@ -1377,11 +1404,11 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[] ...@@ -1377,11 +1404,11 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
cxxflags = [flag for flag in config.gcc.cxxflags.split(' ') if flag] cxxflags = [flag for flag in config.gcc.cxxflags.split(' ') if flag]
#print >> sys.stderr, config.gcc.cxxflags.split(' ') #print >> sys.stderr, config.gcc.cxxflags.split(' ')
cmd.extend(cxxflags) cmd.extend(cxxflags)
cmd.extend('-I%s'%idir for idir in include_dirs) cmd.extend('-I%s' % idir for idir in include_dirs)
cmd.extend(['-o',lib_filename]) cmd.extend(['-o', lib_filename])
cmd.append(cppfilename) cmd.append(cppfilename)
cmd.extend(['-L%s'%ldir for ldir in lib_dirs]) cmd.extend(['-L%s' % ldir for ldir in lib_dirs])
cmd.extend(['-l%s'%l for l in libs]) cmd.extend(['-l%s' % l for l in libs])
#print >> sys.stderr, 'COMPILING W CMD', cmd #print >> sys.stderr, 'COMPILING W CMD', cmd
_logger.debug('Running cmd: %s', ' '.join(cmd)) _logger.debug('Running cmd: %s', ' '.join(cmd))
...@@ -1405,7 +1432,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[] ...@@ -1405,7 +1432,7 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
print '===============================' print '==============================='
for i, l in enumerate(src_code.split('\n')): for i, l in enumerate(src_code.split('\n')):
#gcc put its messages to stderr, so we add ours now #gcc put its messages to stderr, so we add ours now
print >> sys.stderr, '%05i\t%s'%(i+1, l) print >> sys.stderr, '%05i\t%s' % (i + 1, l)
print '===============================' print '==============================='
print_command_line_error() print_command_line_error()
# Print errors just below the command line. # Print errors just below the command line.
...@@ -1417,8 +1444,9 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[] ...@@ -1417,8 +1444,9 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
(status, compile_stderr.replace('\n', '. '))) (status, compile_stderr.replace('\n', '. ')))
#touch the __init__ file #touch the __init__ file
file(os.path.join(location, "__init__.py"),'w').close() file(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename) return dlimport(lib_filename)
def icc_module_compile_str(*args): def icc_module_compile_str(*args):
raise NotImplementedError() raise NotImplementedError()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论