source: trunk/module/setup.py @ 553

Last change on this file since 553 was 553, checked in by cito, 4 years ago

Require at least Python 2.6 for the trunk (5.x)

Support for even older Python versions is maintained in the 4.x branch.
The goal for 5.x is to be a single-source code for both Python 2 and 3,
and this is only possible by dropping support for Python 2.5 and older.
For instance, the new except .. as syntax works only since Python 2.6.
Otherwise we would need to use 2to3 and things would be very ugly.
Note that Python 2.6 is now 7 years old. We may want to drop Python 2.6
as well at some point if it turns out to be a burden.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1#! /usr/bin/python
2# $Id: setup.py 553 2015-11-20 11:16:03Z cito $
3
4"""Setup script for PyGreSQL version 5.0
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>
13* setup script created 2000/04 Mark Alexander <mwa@gate.net>
14* tweaked 2000/05 Jeremy Hylton <jeremy@cnri.reston.va.us>
15* win32 support 2001/01 by Gerhard Haering <gerhard@bigfoot.de>
16* tweaked 2006/02-2010/02 by Christoph Zwerschke <cito@online.de>
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
24The supported versions are Python 2.6-3.5 and PostgreSQL 9.0-9.5.
25
26Use as follows:
27python setup.py build   # to build the module
28python setup.py install # to install it
29
30You can use MinGW or MinGW-w64 for building on Windows:
31python setup.py build -c mingw32 install
32
33See docs.python.org/doc/install/ for more information on
34using distutils to install Python programs.
35
36"""
37
38version = '5.0a0'
39
40
41import sys
42
43if not (2, 6) <= sys.version_info[:2] <= (3, 5):
44    raise Exception("Sorry, PyGreSQL %s"
45        " does not support this Python version" % version)
46
47
48import os
49import platform
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
57from distutils.sysconfig import get_python_inc, get_python_lib
58
59
60def pg_config(s):
61    """Retrieve information about installed version of PostgreSQL."""
62    f = os.popen('pg_config --%s' % s)
63    d = f.readline().strip()
64    if f.close() is not None:
65        raise Exception("pg_config tool is not available.")
66    if not d:
67        raise Exception("Could not get %s information." % s)
68    return d
69
70
71def pg_version():
72    """Return the PostgreSQL version as a tuple of integers."""
73    parts = []
74    for part in pg_config('version').split()[-1].split('.'):
75        if part.isdigit():
76            part = int(part)
77        parts.append(part)
78    return tuple(parts or [8])
79
80
81pg_version = pg_version()
82py_modules = ['pg', 'pgdb']
83libraries = ['pq']
84# Make sure that the Python header files are searched before
85# those of PostgreSQL, because PostgreSQL can have its own Python.h
86include_dirs = [get_python_inc(), pg_config('includedir')]
87library_dirs = [get_python_lib(), pg_config('libdir')]
88define_macros = [('PYGRESQL_VERSION', version)]
89undef_macros = []
90extra_compile_args = ['-O2', '-Wall', '-Werror']
91
92
93class build_pg_ext(build_ext):
94    """Customized build_ext command for PyGreSQL."""
95
96    description = "build the PyGreSQL C extension"
97
98    user_options = build_ext.user_options + [
99        ('direct-access', None,
100            "enable direct access functions"),
101        ('large-objects', None,
102            "enable large object support"),
103        ('default-vars', None,
104            "enable default variables use"),
105        ('escaping-funcs', None,
106            "enable string escaping functions")]
107
108    boolean_options = build_ext.boolean_options + [
109        'direct-access', 'large-objects', 'default-vars', 'escaping-funcs']
110
111    def get_compiler(self):
112        """Return the C compiler used for building the extension."""
113        return self.compiler or get_default_compiler()
114
115    def initialize_options(self):
116        build_ext.initialize_options(self)
117        self.direct_access = True
118        self.large_objects = True
119        self.default_vars = True
120        self.escaping_funcs = pg_version[0] >= 9
121
122    def finalize_options(self):
123        """Set final values for all build_pg options."""
124        build_ext.finalize_options(self)
125        if self.direct_access:
126            define_macros.append(('DIRECT_ACCESS', None))
127        if self.large_objects:
128            define_macros.append(('LARGE_OBJECTS', None))
129        if self.default_vars:
130            define_macros.append(('DEFAULT_VARS', None))
131        if self.escaping_funcs:
132            define_macros.append(('ESCAPING_FUNCS', None))
133        if sys.platform == 'win32':
134            bits = platform.architecture()[0]
135            if bits == '64bit': # we need to find libpq64
136                for path in os.environ['PATH'].split(os.pathsep) + [
137                        r'C:\Program Files\PostgreSQL\libpq64']:
138                    library_dir = os.path.join(path, 'lib')
139                    if not os.path.isdir(library_dir):
140                        continue
141                    lib = os.path.join(library_dir, 'libpqdll.')
142                    if not (os.path.exists(lib + 'lib')
143                            or os.path.exists(lib + 'a')):
144                        continue
145                    include_dir = os.path.join(path, 'include')
146                    if not os.path.isdir(include_dir):
147                        continue
148                    if library_dir not in library_dirs:
149                        library_dirs.insert(1, library_dir)
150                    if include_dir not in include_dirs:
151                        include_dirs.insert(1, include_dir)
152                    libraries[0] += 'dll' # libpqdll instead of libpq
153                    break
154            compiler = self.get_compiler()
155            if compiler == 'mingw32': # MinGW
156                if bits == '64bit': # needs MinGW-w64
157                    define_macros.append(('MS_WIN64', None))
158            elif compiler == 'msvc': # Microsoft Visual C++
159                libraries[0] = 'lib' + libraries[0]
160
161
162setup(
163    name="PyGreSQL",
164    version=version,
165    description="Python PostgreSQL Interfaces",
166    long_description=__doc__.split('\n\n', 2)[1], # first passage
167    keywords="pygresql postgresql database api dbapi",
168    author="D'Arcy J. M. Cain",
169    author_email="darcy@PyGreSQL.org",
170    url="http://www.pygresql.org",
171    download_url="ftp://ftp.pygresql.org/pub/distrib/",
172    platforms=["any"],
173    license="Python",
174    py_modules=py_modules,
175    ext_modules=[Extension('_pg', ['pgmodule.c'],
176        include_dirs=include_dirs, library_dirs=library_dirs,
177        define_macros=define_macros, undef_macros=undef_macros,
178        libraries=libraries, extra_compile_args=extra_compile_args)],
179    zip_safe=False,
180    cmdclass=dict(build_ext=build_pg_ext),
181    classifiers=[
182        "Development Status :: 6 - Mature",
183        "Intended Audience :: Developers",
184        "License :: OSI Approved :: Python Software Foundation License",
185        "Operating System :: OS Independent",
186        "Programming Language :: C",
187        "Programming Language :: Python",
188        "Programming Language :: SQL",
189        "Topic :: Database",
190        "Topic :: Database :: Front-Ends",
191        "Topic :: Software Development :: Libraries :: Python Modules"]
192)
Note: See TracBrowser for help on using the repository browser.