source: branches/4.x/setup.py @ 939

Last change on this file since 939 was 939, checked in by cito, 15 months ago

Adapt Trove classifier for the PostgreSQL license

Has been added simply as "PostgreSQL License"
(https://github.com/pypa/warehouse/issues/3843).

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