Clean up a bunch of lint from pylint/pyflakes/pep8 checking

- Don't override global variable name "ext" (use "extension" as function
  argument names)
- Improve function naming (get_compiler -> get_compiler_name)
- Other misc operator spacing and 80-column violation cleanup.
- Remove unneeded import (DistUtilsFileError)
This commit is contained in:
Steve Lacy 2011-06-06 14:19:27 -07:00 committed by Daniele Varrazzo
parent f3526d0630
commit c826446ff8

View File

@ -49,7 +49,6 @@ import sys
import re import re
import subprocess import subprocess
from distutils.core import setup, Extension from distutils.core import setup, Extension
from distutils.errors import DistutilsFileError
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc from distutils.sysconfig import get_python_inc
from distutils.ccompiler import get_default_compiler from distutils.ccompiler import get_default_compiler
@ -130,10 +129,10 @@ or with the pg_config option in 'setup.cfg'.
def autodetect_pg_config_path_posix(self): def autodetect_pg_config_path_posix(self):
"""Return pg_config from the current PATH""" """Return pg_config from the current PATH"""
exename = 'pg_config' exename = 'pg_config'
for dir in os.environ['PATH'].split(os.pathsep): for dir_name in os.environ['PATH'].split(os.pathsep):
fn = os.path.join(dir, exename) fullpath = os.path.join(dir_name, exename)
if os.path.isfile(fn): if os.path.isfile(fullpath):
return fn return fullpath
return None return None
def autodetect_pg_config_path_windows(self): def autodetect_pg_config_path_windows(self):
@ -253,7 +252,7 @@ class psycopg_build_ext(build_ext):
self.have_ssl = have_ssl self.have_ssl = have_ssl
self.static_libpq = static_libpq self.static_libpq = static_libpq
def get_compiler(self): def get_compiler_name(self):
"""Return the name of the C compiler used to compile extensions. """Return the name of the C compiler used to compile extensions.
If a compiler was not explicitly set (on the command line, for If a compiler was not explicitly set (on the command line, for
@ -270,15 +269,15 @@ class psycopg_build_ext(build_ext):
name = get_default_compiler() name = get_default_compiler()
return name return name
def get_export_symbols(self, ext): def get_export_symbols(self, extension):
# Fix MSVC seeing two of the same export symbols. # Fix MSVC seeing two of the same export symbols.
if self.get_compiler().lower().startswith('msvc'): if self.get_compiler_name().lower().startswith('msvc'):
return [] return []
else: else:
return build_ext.get_export_symbols(self, ext) return build_ext.get_export_symbols(self, extension)
def build_extension(self, ext): def build_extension(self, extension):
build_ext.build_extension(self, ext) build_ext.build_extension(self, extension)
# For Python versions that use MSVC compiler 2008, re-insert the # For Python versions that use MSVC compiler 2008, re-insert the
# manifest into the resulting .pyd file. # manifest into the resulting .pyd file.
@ -288,19 +287,21 @@ class psycopg_build_ext(build_ext):
manifest = '_psycopg.vc9.x86.manifest' manifest = '_psycopg.vc9.x86.manifest'
if platform == 'win-amd64': if platform == 'win-amd64':
manifest = '_psycopg.vc9.amd64.manifest' manifest = '_psycopg.vc9.amd64.manifest'
self.compiler.spawn(['mt.exe', '-nologo', '-manifest', self.compiler.spawn(
['mt.exe', '-nologo', '-manifest',
os.path.join('psycopg', manifest), os.path.join('psycopg', manifest),
'-outputresource:%s;2' % (os.path.join(self.build_lib, 'psycopg2', '_psycopg.pyd'))]) '-outputresource:%s;2' % (
os.path.join(self.build_lib,
'psycopg2', '_psycopg.pyd'))])
def finalize_win32(self): def finalize_win32(self):
"""Finalize build system configuration on win32 platform.""" """Finalize build system configuration on win32 platform."""
import struct
sysVer = sys.version_info[:2] sysVer = sys.version_info[:2]
# Add compiler-specific arguments: # Add compiler-specific arguments:
extra_compiler_args = [] extra_compiler_args = []
compiler_name = self.get_compiler().lower() compiler_name = self.get_compiler_name().lower()
compiler_is_msvc = compiler_name.startswith('msvc') compiler_is_msvc = compiler_name.startswith('msvc')
compiler_is_mingw = compiler_name.startswith('mingw') compiler_is_mingw = compiler_name.startswith('mingw')
if compiler_is_mingw: if compiler_is_mingw:
@ -315,18 +316,18 @@ class psycopg_build_ext(build_ext):
extra_compiler_args.append('-fno-strict-aliasing') extra_compiler_args.append('-fno-strict-aliasing')
# Force correct C runtime library linkage: # Force correct C runtime library linkage:
if sysVer <= (2,3): if sysVer <= (2, 3):
# Yes: 'msvcr60', rather than 'msvcrt', is the correct value # Yes: 'msvcr60', rather than 'msvcrt', is the correct value
# on the line below: # on the line below:
self.libraries.append('msvcr60') self.libraries.append('msvcr60')
elif sysVer in ((2,4), (2,5)): elif sysVer in ((2, 4), (2, 5)):
self.libraries.append('msvcr71') self.libraries.append('msvcr71')
# Beyond Python 2.5, we take our chances on the default C runtime # Beyond Python 2.5, we take our chances on the default C runtime
# library, because we don't know what compiler those future # library, because we don't know what compiler those future
# versions of Python will use. # versions of Python will use.
for exten in ext: # ext is a global list of Extension objects for extension in ext: # ext is a global list of Extension objects
exten.extra_compile_args.extend(extra_compiler_args) extension.extra_compile_args.extend(extra_compiler_args)
# End of add-compiler-specific arguments section. # End of add-compiler-specific arguments section.
self.libraries.append("ws2_32") self.libraries.append("ws2_32")
@ -356,8 +357,9 @@ class psycopg_build_ext(build_ext):
def finalize_linux2(self): def finalize_linux2(self):
"""Finalize build system configuration on GNU/Linux platform.""" """Finalize build system configuration on GNU/Linux platform."""
# tell piro that GCC is fine and dandy, but not so MS compilers # tell piro that GCC is fine and dandy, but not so MS compilers
for ext in self.extensions: for extension in self.extensions:
ext.extra_compile_args.append('-Wdeclaration-after-statement') extension.extra_compile_args.append(
'-Wdeclaration-after-statement')
def finalize_options(self): def finalize_options(self):
"""Complete the build system configuation.""" """Complete the build system configuation."""
@ -365,7 +367,8 @@ class psycopg_build_ext(build_ext):
self.include_dirs.append(".") self.include_dirs.append(".")
if self.static_libpq: if self.static_libpq:
if not self.link_objects: self.link_objects = [] if not self.link_objects:
self.link_objects = []
self.link_objects.append( self.link_objects.append(
os.path.join(self.pg_config.query("libdir"), "libpq.a")) os.path.join(self.pg_config.query("libdir"), "libpq.a"))
else: else:
@ -383,7 +386,8 @@ class psycopg_build_ext(build_ext):
except: except:
pgversion = "7.4.0" pgversion = "7.4.0"
verre = re.compile(r"(\d+)\.(\d+)(?:(?:\.(\d+))|(devel|(alpha|beta|rc)\d+))") verre = re.compile(
r"(\d+)\.(\d+)(?:(?:\.(\d+))|(devel|(alpha|beta|rc)\d+))")
m = verre.match(pgversion) m = verre.match(pgversion)
if m: if m:
pgmajor, pgminor, pgpatch = m.group(1, 2, 3) pgmajor, pgminor, pgpatch = m.group(1, 2, 3)
@ -411,7 +415,8 @@ define_macros = []
include_dirs = [] include_dirs = []
# gather information to build the extension module # gather information to build the extension module
ext = [] ; data_files = [] ext = []
data_files = []
# sources # sources
@ -464,7 +469,7 @@ else:
if os.path.exists(mxincludedir): if os.path.exists(mxincludedir):
# Build the support for mx: we will check at runtime if it can be imported # Build the support for mx: we will check at runtime if it can be imported
include_dirs.append(mxincludedir) include_dirs.append(mxincludedir)
define_macros.append(('HAVE_MXDATETIME','1')) define_macros.append(('HAVE_MXDATETIME', '1'))
sources.append('adapter_mxdatetime.c') sources.append('adapter_mxdatetime.c')
depends.extend(['adapter_mxdatetime.h', 'typecast_mxdatetime.c']) depends.extend(['adapter_mxdatetime.h', 'typecast_mxdatetime.c'])
have_mxdatetime = True have_mxdatetime = True
@ -472,18 +477,21 @@ if os.path.exists(mxincludedir):
# now decide which package will be the default for date/time typecasts # now decide which package will be the default for date/time typecasts
if have_pydatetime and (use_pydatetime or not have_mxdatetime): if have_pydatetime and (use_pydatetime or not have_mxdatetime):
define_macros.append(('PSYCOPG_DEFAULT_PYDATETIME','1')) define_macros.append(('PSYCOPG_DEFAULT_PYDATETIME', '1'))
elif have_mxdatetime: elif have_mxdatetime:
define_macros.append(('PSYCOPG_DEFAULT_MXDATETIME','1')) define_macros.append(('PSYCOPG_DEFAULT_MXDATETIME', '1'))
else: else:
def e(msg): error_message = """\
sys.stderr.write("error: " + msg + "\n") psycopg requires a datetime module:
e("psycopg requires a datetime module:") mx.DateTime module not found
e(" mx.DateTime module not found") python datetime module not found
e(" python datetime module not found")
e("Note that psycopg needs the module headers and not just the module") Note that psycopg needs the module headers and not just the module
e("itself. If you installed Python or mx.DateTime from a binary package") itself. If you installed Python or mx.DateTime from a binary package
e("you probably need to install its companion -dev or -devel package.") you probably need to install its companion -dev or -devel package."""
for line in error_message.split("\n"):
sys.stderr.write("error: " + line)
sys.exit(1) sys.exit(1)
# generate a nice version string to avoid confusion when users report bugs # generate a nice version string to avoid confusion when users report bugs
@ -497,9 +505,9 @@ else:
PSYCOPG_VERSION_EX = PSYCOPG_VERSION PSYCOPG_VERSION_EX = PSYCOPG_VERSION
if not PLATFORM_IS_WINDOWS: if not PLATFORM_IS_WINDOWS:
define_macros.append(('PSYCOPG_VERSION', '"'+PSYCOPG_VERSION_EX+'"')) define_macros.append(('PSYCOPG_VERSION', '"' + PSYCOPG_VERSION_EX + '"'))
else: else:
define_macros.append(('PSYCOPG_VERSION', '\\"'+PSYCOPG_VERSION_EX+'\\"')) define_macros.append(('PSYCOPG_VERSION', '\\"' + PSYCOPG_VERSION_EX + '\\"'))
if parser.has_option('build_ext', 'have_ssl'): if parser.has_option('build_ext', 'have_ssl'):
have_ssl = int(parser.get('build_ext', 'have_ssl')) have_ssl = int(parser.get('build_ext', 'have_ssl'))
@ -537,17 +545,16 @@ setup(name="psycopg2",
author="Federico Di Gregorio", author="Federico Di Gregorio",
author_email="fog@initd.org", author_email="fog@initd.org",
url="http://initd.org/psycopg/", url="http://initd.org/psycopg/",
download_url = download_url, download_url=download_url,
license="GPL with exceptions or ZPL", license="GPL with exceptions or ZPL",
platforms = ["any"], platforms=["any"],
description=__doc__.split("\n")[0], description=__doc__.split("\n")[0],
long_description="\n".join(__doc__.split("\n")[2:]), long_description="\n".join(__doc__.split("\n")[2:]),
classifiers=[x for x in classifiers.split("\n") if x], classifiers=[x for x in classifiers.split("\n") if x],
data_files=data_files, data_files=data_files,
package_dir={'psycopg2':'lib', 'psycopg2.tests': 'tests'}, package_dir={'psycopg2': 'lib', 'psycopg2.tests': 'tests'},
packages=['psycopg2', 'psycopg2.tests'], packages=['psycopg2', 'psycopg2.tests'],
cmdclass={ cmdclass={
'build_ext': psycopg_build_ext, 'build_ext': psycopg_build_ext,
'build_py': build_py, }, 'build_py': build_py, },
ext_modules=ext) ext_modules=ext)