source: trunk/setup.py

Last change on this file was 940, checked in by cito, 3 months ago

Prepare for version 5.0.6

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