source: trunk/setup.py @ 990

Last change on this file since 990 was 990, checked in by cito, 4 months ago

PostgreSQL 11 support was missing in setup.py

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