source: trunk/setup.py @ 924

Last change on this file since 924 was 924, checked in by cito, 20 months ago

Fix the license entry in the setup file

PyGreSQL is licensed under the PostgreSQL license (see LICENSE.txt)
and not the Python Software Foundation license.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.8 KB
Line 
1#! /usr/bin/python
2# $Id: setup.py 924 2017-11-24 16:16:44Z cito $
3
4"""Setup script for PyGreSQL version 5.0.4
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 2017 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-2.7, 3.3-3.6 and PostgreSQL 9.0-9.6.
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
35version = '5.0.5'
36
37
38import sys
39
40if (not (2, 6) <= sys.version_info[:2] < (3, 0)
41        and not (3, 3) <= sys.version_info[:2] < (4, 0)):
42    raise Exception("Sorry, PyGreSQL %s"
43        " does not support this Python version" % version)
44
45
46import os
47import platform
48import re
49import warnings
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
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
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
80def pg_version():
81    """Return the PostgreSQL version as a tuple of integers."""
82    match = re.search(r'(\d+)\.(\d+)', pg_config('version'))
83    if match:
84        return tuple(map(int, match.groups()))
85    return (9, 0)
86
87
88pg_version = pg_version()
89libraries = ['pq']
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')]
94define_macros = [('PYGRESQL_VERSION', version)]
95undef_macros = []
96extra_compile_args = ['-O2', '-funsigned-char', '-Wall', '-Werror']
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,
110            "enable default variables use"),
111        ('escaping-funcs', None,
112            "enable string escaping functions")]
113
114    boolean_options = build_ext.boolean_options + [
115        'direct-access', 'large-objects', 'default-vars', 'escaping-funcs']
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
121    def initialize_options(self):
122        build_ext.initialize_options(self)
123        self.direct_access = True
124        self.large_objects = True
125        self.default_vars = True
126        self.escaping_funcs = pg_version[0] >= 9
127        if pg_version < (9, 0):
128            warnings.warn("PygreSQL does not support this PostgreSQL version.")
129
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))
139        if self.escaping_funcs and pg_version[0] >= 9:
140            define_macros.append(('ESCAPING_FUNCS', None))
141        if sys.platform == 'win32':
142            bits = platform.architecture()[0]
143            if bits == '64bit':  # we need to find libpq64
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:
157                        library_dirs.insert(1, library_dir)
158                    if include_dir not in include_dirs:
159                        include_dirs.insert(1, include_dir)
160                    libraries[0] += 'dll'  # libpqdll instead of libpq
161                    break
162            compiler = self.get_compiler()
163            if compiler == 'mingw32':  # MinGW
164                if bits == '64bit':  # needs MinGW-w64
165                    define_macros.append(('MS_WIN64', None))
166            elif compiler == 'msvc':  # Microsoft Visual C++
167                libraries[0] = 'lib' + libraries[0]
168                extra_compile_args[1:] = ['-J', '-W3', '-WX',
169                    '-Dinline=__inline']  # needed for MSVC 9
170
171
172setup(
173    name="PyGreSQL",
174    version=version,
175    description="Python PostgreSQL Interfaces",
176    long_description=__doc__.split('\n\n', 2)[1],  # first passage
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",
181    download_url="http://www.pygresql.org/download/",
182    platforms=["any"],
183    license="PostgreSQL",
184    py_modules=py_modules,
185    ext_modules=[Extension('_pg', c_sources,
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)],
189    zip_safe=False,
190    cmdclass=dict(build_ext=build_pg_ext),
191    test_suite='tests.discover',
192    classifiers=[
193        "Development Status :: 6 - Mature",
194        "Intended Audience :: Developers",
195        "License :: OSI Approved :: The PostgreSQL License",
196        "Operating System :: OS Independent",
197        "Programming Language :: C",
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',
206        'Programming Language :: Python :: 3.6',
207        "Programming Language :: SQL",
208        "Topic :: Database",
209        "Topic :: Database :: Front-Ends",
210        "Topic :: Software Development :: Libraries :: Python Modules"]
211)
Note: See TracBrowser for help on using the repository browser.