source: trunk/setup.py @ 1011

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

Add some more attributes to the connection object

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1#!/usr/bin/python
2#
3# $Id: setup.py 991 2019-04-24 19:46:20Z 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        ('ssl-info', None,
122            "use new ssl info functions")]
123
124    boolean_options = build_ext.boolean_options + [
125        'direct-access', 'large-objects', 'default-vars',
126        'escaping-funcs', 'ssl-info']
127
128    def get_compiler(self):
129        """Return the C compiler used for building the extension."""
130        return self.compiler or get_default_compiler()
131
132    def initialize_options(self):
133        build_ext.initialize_options(self)
134        self.direct_access = True
135        self.large_objects = True
136        self.default_vars = True
137        self.escaping_funcs = pg_version >= (9, 0)
138        self.ssl_info = pg_version >= (9, 5)
139        if pg_version < (9, 0):
140            warnings.warn("PygreSQL does not support this PostgreSQL version.")
141
142    def finalize_options(self):
143        """Set final values for all build_pg options."""
144        build_ext.finalize_options(self)
145        if self.direct_access:
146            define_macros.append(('DIRECT_ACCESS', None))
147        if self.large_objects:
148            define_macros.append(('LARGE_OBJECTS', None))
149        if self.default_vars:
150            define_macros.append(('DEFAULT_VARS', None))
151        if self.escaping_funcs and pg_version >= (9, 0):
152            define_macros.append(('ESCAPING_FUNCS', None))
153        if self.ssl_info and pg_version >= (9, 5):
154            define_macros.append(('SSL_INFO', None))
155        if sys.platform == 'win32':
156            bits = platform.architecture()[0]
157            if bits == '64bit':  # we need to find libpq64
158                for path in os.environ['PATH'].split(os.pathsep) + [
159                        r'C:\Program Files\PostgreSQL\libpq64']:
160                    library_dir = os.path.join(path, 'lib')
161                    if not os.path.isdir(library_dir):
162                        continue
163                    lib = os.path.join(library_dir, 'libpqdll.')
164                    if not (os.path.exists(lib + 'lib')
165                            or os.path.exists(lib + 'a')):
166                        continue
167                    include_dir = os.path.join(path, 'include')
168                    if not os.path.isdir(include_dir):
169                        continue
170                    if library_dir not in library_dirs:
171                        library_dirs.insert(1, library_dir)
172                    if include_dir not in include_dirs:
173                        include_dirs.insert(1, include_dir)
174                    libraries[0] += 'dll'  # libpqdll instead of libpq
175                    break
176            compiler = self.get_compiler()
177            if compiler == 'mingw32':  # MinGW
178                if bits == '64bit':  # needs MinGW-w64
179                    define_macros.append(('MS_WIN64', None))
180            elif compiler == 'msvc':  # Microsoft Visual C++
181                libraries[0] = 'lib' + libraries[0]
182                extra_compile_args[1:] = ['-J', '-W3', '-WX',
183                    '-Dinline=__inline']  # needed for MSVC 9
184
185
186setup(
187    name="PyGreSQL",
188    version=version,
189    description="Python PostgreSQL Interfaces",
190    long_description=__doc__.split('\n\n', 2)[1],  # first passage
191    keywords="pygresql postgresql database api dbapi",
192    author="D'Arcy J. M. Cain",
193    author_email="darcy@PyGreSQL.org",
194    url="http://www.pygresql.org",
195    download_url="http://www.pygresql.org/download/",
196    platforms=["any"],
197    license="PostgreSQL",
198    py_modules=py_modules,
199    ext_modules=[Extension('_pg', c_sources,
200        include_dirs=include_dirs, library_dirs=library_dirs,
201        define_macros=define_macros, undef_macros=undef_macros,
202        libraries=libraries, extra_compile_args=extra_compile_args)],
203    zip_safe=False,
204    cmdclass=dict(build_ext=build_pg_ext),
205    test_suite='tests.discover',
206    classifiers=[
207        "Development Status :: 6 - Mature",
208        "Intended Audience :: Developers",
209        "License :: OSI Approved :: PostgreSQL License",
210        "Operating System :: OS Independent",
211        "Programming Language :: C",
212        'Programming Language :: Python',
213        'Programming Language :: Python :: 2',
214        'Programming Language :: Python :: 2.6',
215        'Programming Language :: Python :: 2.7',
216        'Programming Language :: Python :: 3',
217        'Programming Language :: Python :: 3.3',
218        'Programming Language :: Python :: 3.4',
219        'Programming Language :: Python :: 3.5',
220        'Programming Language :: Python :: 3.6',
221        'Programming Language :: Python :: 3.7',
222        "Programming Language :: SQL",
223        "Topic :: Database",
224        "Topic :: Database :: Front-Ends",
225        "Topic :: Software Development :: Libraries :: Python Modules"]
226)
Note: See TracBrowser for help on using the repository browser.