source: trunk/setup.py @ 914

Last change on this file since 914 was 914, checked in by darcy, 2 years ago

Releasing 5.0.3.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.8 KB
RevLine 
[521]1#! /usr/bin/python
[418]2# $Id: setup.py 914 2017-07-23 13:10:49Z darcy $
3
[914]4"""Setup script for PyGreSQL version 5.0.4
[418]5
6PyGreSQL is an open-source Python module that interfaces to a
7PostgreSQL database. It embeds the PostgreSQL query library to allow
8easy use of the powerful PostgreSQL features from a Python script.
9
10Authors and history:
11* PyGreSQL written 1997 by D'Arcy J.M. Cain <darcy@druid.net>
12* based on code written 1995 by Pascal Andre <andre@chimay.via.ecp.fr>
[711]13* setup script created 2000 by Mark Alexander <mwa@gate.net>
14* improved 2000 by Jeremy Hylton <jeremy@cnri.reston.va.us>
15* improved 2001 by Gerhard Haering <gerhard@bigfoot.de>
16* improved 2006 and 2016 by Christoph Zwerschke <cito@online.de>
[418]17
18Prerequisites to be installed:
19* Python including devel package (header files and distutils)
20* PostgreSQL libs and devel packages (header file of the libpq client)
21* PostgreSQL pg_config tool (usually included in the devel package)
22  (the Windows installer has it as part of the database server feature)
23
[905]24The supported versions are Python 2.6-2.7, 3.3-3.6 and PostgreSQL 9.0-9.6.
[418]25
26Use as follows:
27python setup.py build   # to build the module
28python setup.py install # to install it
29
30See docs.python.org/doc/install/ for more information on
31using distutils to install Python programs.
32
33"""
34
[914]35version = '5.0.4'
[418]36
37
38import sys
39
[873]40if (not (2, 6) <= sys.version_info[:2] < (3, 0)
41        and not (3, 3) <= sys.version_info[:2] < (4, 0)):
[418]42    raise Exception("Sorry, PyGreSQL %s"
43        " does not support this Python version" % version)
44
45
46import os
47import platform
[874]48import re
[691]49import warnings
[418]50try:
51    from setuptools import setup
52except ImportError:
53    from distutils.core import setup
54from distutils.extension import Extension
55from distutils.command.build_ext import build_ext
56from distutils.ccompiler import get_default_compiler
[474]57from distutils.sysconfig import get_python_inc, get_python_lib
[418]58
59
[711]60# For historical reasons, PyGreSQL does not install itself as a single
61# "pygresql" package, but as two top-level modules "pg", providing the
62# classic interface, and "pgdb" for the modern DB-API 2.0 interface.
63# These two top-level Python modules share the same C extension "_pg".
64
65py_modules = ['pg', 'pgdb']
66c_sources = ['pgmodule.c']
67
68
[418]69def pg_config(s):
70    """Retrieve information about installed version of PostgreSQL."""
71    f = os.popen('pg_config --%s' % s)
72    d = f.readline().strip()
73    if f.close() is not None:
74        raise Exception("pg_config tool is not available.")
75    if not d:
76        raise Exception("Could not get %s information." % s)
77    return d
78
79
[517]80def pg_version():
81    """Return the PostgreSQL version as a tuple of integers."""
[874]82    match = re.search(r'(\d+)\.(\d+)', pg_config('version'))
83    if match:
84        return tuple(map(int, match.groups()))
85    return (9, 0)
[517]86
87
88pg_version = pg_version()
[418]89libraries = ['pq']
[474]90# Make sure that the Python header files are searched before
91# those of PostgreSQL, because PostgreSQL can have its own Python.h
92include_dirs = [get_python_inc(), pg_config('includedir')]
93library_dirs = [get_python_lib(), pg_config('libdir')]
[451]94define_macros = [('PYGRESQL_VERSION', version)]
[418]95undef_macros = []
[700]96extra_compile_args = ['-O2', '-funsigned-char', '-Wall', '-Werror']
[418]97
98
99class build_pg_ext(build_ext):
100    """Customized build_ext command for PyGreSQL."""
101
102    description = "build the PyGreSQL C extension"
103
104    user_options = build_ext.user_options + [
105        ('direct-access', None,
106            "enable direct access functions"),
107        ('large-objects', None,
108            "enable large object support"),
109        ('default-vars', None,
[476]110            "enable default variables use"),
111        ('escaping-funcs', None,
112            "enable string escaping functions")]
[418]113
114    boolean_options = build_ext.boolean_options + [
[517]115        'direct-access', 'large-objects', 'default-vars', 'escaping-funcs']
[418]116
117    def get_compiler(self):
118        """Return the C compiler used for building the extension."""
119        return self.compiler or get_default_compiler()
120
[450]121    def initialize_options(self):
122        build_ext.initialize_options(self)
[517]123        self.direct_access = True
124        self.large_objects = True
125        self.default_vars = True
126        self.escaping_funcs = pg_version[0] >= 9
[691]127        if pg_version < (9, 0):
128            warnings.warn("PygreSQL does not support this PostgreSQL version.")
[450]129
[418]130    def finalize_options(self):
131        """Set final values for all build_pg options."""
132        build_ext.finalize_options(self)
133        if self.direct_access:
134            define_macros.append(('DIRECT_ACCESS', None))
135        if self.large_objects:
136            define_macros.append(('LARGE_OBJECTS', None))
137        if self.default_vars:
138            define_macros.append(('DEFAULT_VARS', None))
[690]139        if self.escaping_funcs and pg_version[0] >= 9:
[476]140            define_macros.append(('ESCAPING_FUNCS', None))
[418]141        if sys.platform == 'win32':
142            bits = platform.architecture()[0]
[690]143            if bits == '64bit':  # we need to find libpq64
[418]144                for path in os.environ['PATH'].split(os.pathsep) + [
145                        r'C:\Program Files\PostgreSQL\libpq64']:
146                    library_dir = os.path.join(path, 'lib')
147                    if not os.path.isdir(library_dir):
148                        continue
149                    lib = os.path.join(library_dir, 'libpqdll.')
150                    if not (os.path.exists(lib + 'lib')
151                            or os.path.exists(lib + 'a')):
152                        continue
153                    include_dir = os.path.join(path, 'include')
154                    if not os.path.isdir(include_dir):
155                        continue
156                    if library_dir not in library_dirs:
[474]157                        library_dirs.insert(1, library_dir)
[418]158                    if include_dir not in include_dirs:
[474]159                        include_dirs.insert(1, include_dir)
[690]160                    libraries[0] += 'dll'  # libpqdll instead of libpq
[418]161                    break
162            compiler = self.get_compiler()
[690]163            if compiler == 'mingw32':  # MinGW
164                if bits == '64bit':  # needs MinGW-w64
[418]165                    define_macros.append(('MS_WIN64', None))
[690]166            elif compiler == 'msvc':  # Microsoft Visual C++
[418]167                libraries[0] = 'lib' + libraries[0]
[870]168                extra_compile_args[1:] = ['-J', '-W3', '-WX',
169                    '-Dinline=__inline']  # needed for MSVC 9
[418]170
171
172setup(
173    name="PyGreSQL",
174    version=version,
175    description="Python PostgreSQL Interfaces",
[690]176    long_description=__doc__.split('\n\n', 2)[1],  # first passage
[418]177    keywords="pygresql postgresql database api dbapi",
178    author="D'Arcy J. M. Cain",
179    author_email="darcy@PyGreSQL.org",
180    url="http://www.pygresql.org",
[898]181    download_url="http://www.pygresql.org/download/",
[418]182    platforms=["any"],
183    license="Python",
184    py_modules=py_modules,
[711]185    ext_modules=[Extension('_pg', c_sources,
[418]186        include_dirs=include_dirs, library_dirs=library_dirs,
187        define_macros=define_macros, undef_macros=undef_macros,
188        libraries=libraries, extra_compile_args=extra_compile_args)],
[550]189    zip_safe=False,
[418]190    cmdclass=dict(build_ext=build_pg_ext),
[640]191    test_suite='tests.discover',
[418]192    classifiers=[
193        "Development Status :: 6 - Mature",
194        "Intended Audience :: Developers",
195        "License :: OSI Approved :: Python Software Foundation License",
196        "Operating System :: OS Independent",
197        "Programming Language :: C",
[654]198        'Programming Language :: Python',
199        'Programming Language :: Python :: 2',
200        'Programming Language :: Python :: 2.6',
201        'Programming Language :: Python :: 2.7',
202        'Programming Language :: Python :: 3',
203        'Programming Language :: Python :: 3.3',
204        'Programming Language :: Python :: 3.4',
205        'Programming Language :: Python :: 3.5',
[418]206        "Programming Language :: SQL",
207        "Topic :: Database",
208        "Topic :: Database :: Front-Ends",
209        "Topic :: Software Development :: Libraries :: Python Modules"]
210)
Note: See TracBrowser for help on using the repository browser.