2011-02-11 03:16:10 +03:00
|
|
|
# setup.py - distutils packaging
|
|
|
|
#
|
|
|
|
# Copyright (C) 2003-2010 Federico Di Gregorio <fog@debian.org>
|
|
|
|
#
|
|
|
|
# psycopg2 is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Lesser General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# psycopg2 is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
# License for more details.
|
|
|
|
|
|
|
|
"""Python-PostgreSQL Database Adapter
|
|
|
|
|
|
|
|
psycopg2 is a PostgreSQL database adapter for the Python programming
|
|
|
|
language. psycopg2 was written with the aim of being very small and fast,
|
|
|
|
and stable as a rock.
|
|
|
|
|
|
|
|
psycopg2 is different from the other database adapter because it was
|
|
|
|
designed for heavily multi-threaded applications that create and destroy
|
|
|
|
lots of cursors and make a conspicuous number of concurrent INSERTs or
|
2013-04-26 12:21:56 +04:00
|
|
|
UPDATEs. psycopg2 also provide full asynchronous operations and support
|
2011-02-11 03:16:10 +03:00
|
|
|
for coroutine libraries.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Note: The setup.py must be compatible with both Python 2 and 3
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import subprocess
|
2018-09-16 02:05:05 +03:00
|
|
|
from setuptools import setup, Extension
|
2011-02-11 03:16:10 +03:00
|
|
|
from distutils.command.build_ext import build_ext
|
|
|
|
from distutils.sysconfig import get_python_inc
|
|
|
|
from distutils.ccompiler import get_default_compiler
|
2018-01-13 23:11:18 +03:00
|
|
|
from distutils.errors import CompileError
|
2011-02-11 20:01:38 +03:00
|
|
|
from distutils.util import get_platform
|
2011-06-07 01:30:47 +04:00
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
try:
|
|
|
|
import configparser
|
|
|
|
except ImportError:
|
|
|
|
import ConfigParser as configparser
|
|
|
|
|
2018-09-23 04:54:55 +03:00
|
|
|
# Take a look at https://www.python.org/dev/peps/pep-0440/
|
2011-02-11 03:16:10 +03:00
|
|
|
# for a consistent versioning pattern.
|
|
|
|
|
2017-11-28 06:00:33 +03:00
|
|
|
PSYCOPG_VERSION = '2.8.dev0'
|
2011-02-11 03:16:10 +03:00
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
|
|
|
# note: if you are changing the list of supported Python version please fix
|
|
|
|
# the docs in install.rst and the /features/ page on the website.
|
|
|
|
classifiers = """\
|
|
|
|
Development Status :: 5 - Production/Stable
|
|
|
|
Intended Audience :: Developers
|
|
|
|
License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
|
|
|
|
License :: OSI Approved :: Zope Public License
|
|
|
|
Programming Language :: Python
|
2017-11-26 21:51:48 +03:00
|
|
|
Programming Language :: Python :: 2
|
2016-10-11 02:10:53 +03:00
|
|
|
Programming Language :: Python :: 2.7
|
|
|
|
Programming Language :: Python :: 3
|
|
|
|
Programming Language :: Python :: 3.4
|
|
|
|
Programming Language :: Python :: 3.5
|
2017-01-03 21:12:44 +03:00
|
|
|
Programming Language :: Python :: 3.6
|
2018-06-28 16:28:50 +03:00
|
|
|
Programming Language :: Python :: 3.7
|
2017-11-26 21:51:48 +03:00
|
|
|
Programming Language :: Python :: Implementation :: CPython
|
2016-10-11 02:10:53 +03:00
|
|
|
Programming Language :: C
|
|
|
|
Programming Language :: SQL
|
|
|
|
Topic :: Database
|
|
|
|
Topic :: Database :: Front-Ends
|
|
|
|
Topic :: Software Development
|
|
|
|
Topic :: Software Development :: Libraries :: Python Modules
|
|
|
|
Operating System :: Microsoft :: Windows
|
|
|
|
Operating System :: Unix
|
|
|
|
"""
|
|
|
|
|
|
|
|
version_flags = ['dt', 'dec']
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')
|
|
|
|
|
2011-06-07 01:01:52 +04:00
|
|
|
|
2011-06-07 11:58:54 +04:00
|
|
|
class PostgresConfig:
|
2011-06-07 21:53:10 +04:00
|
|
|
def __init__(self, build_ext):
|
|
|
|
self.build_ext = build_ext
|
|
|
|
self.pg_config_exe = self.build_ext.pg_config
|
|
|
|
if not self.pg_config_exe:
|
|
|
|
self.pg_config_exe = self.autodetect_pg_config_path()
|
2011-06-07 01:01:52 +04:00
|
|
|
if self.pg_config_exe is None:
|
2018-01-13 23:11:18 +03:00
|
|
|
sys.stderr.write("""
|
2011-06-07 01:01:52 +04:00
|
|
|
Error: pg_config executable not found.
|
|
|
|
|
2018-01-13 23:11:18 +03:00
|
|
|
pg_config is required to build psycopg2 from source. Please add the directory
|
|
|
|
containing pg_config to the $PATH or specify the full executable path with the
|
|
|
|
option:
|
2011-06-07 01:01:52 +04:00
|
|
|
|
|
|
|
python setup.py build_ext --pg-config /path/to/pg_config build ...
|
|
|
|
|
|
|
|
or with the pg_config option in 'setup.cfg'.
|
2018-01-13 23:11:18 +03:00
|
|
|
|
|
|
|
If you prefer to avoid building psycopg2 from source, please install the PyPI
|
|
|
|
'psycopg2-binary' package instead.
|
|
|
|
|
|
|
|
For further information please check the 'doc/src/install.rst' file (also at
|
|
|
|
<http://initd.org/psycopg/docs/install.html>).
|
|
|
|
|
2011-06-07 01:01:52 +04:00
|
|
|
""")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def query(self, attr_name):
|
|
|
|
"""Spawn the pg_config executable, querying for the given config
|
|
|
|
name, and return the printed value, sanitized. """
|
|
|
|
try:
|
|
|
|
pg_config_process = subprocess.Popen(
|
|
|
|
[self.pg_config_exe, "--" + attr_name],
|
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
except OSError:
|
|
|
|
raise Warning("Unable to find 'pg_config' file in '%s'" %
|
|
|
|
self.pg_config_exe)
|
|
|
|
pg_config_process.stdin.close()
|
|
|
|
result = pg_config_process.stdout.readline().strip()
|
|
|
|
if not result:
|
|
|
|
raise Warning(pg_config_process.stderr.readline())
|
|
|
|
if not isinstance(result, str):
|
|
|
|
result = result.decode('ascii')
|
|
|
|
return result
|
|
|
|
|
2011-06-07 20:50:52 +04:00
|
|
|
def find_on_path(self, exename, path_directories=None):
|
|
|
|
if not path_directories:
|
|
|
|
path_directories = os.environ['PATH'].split(os.pathsep)
|
|
|
|
for dir_name in path_directories:
|
|
|
|
fullpath = os.path.join(dir_name, exename)
|
|
|
|
if os.path.isfile(fullpath):
|
|
|
|
return fullpath
|
|
|
|
return None
|
|
|
|
|
2011-06-07 01:01:52 +04:00
|
|
|
def autodetect_pg_config_path(self):
|
|
|
|
"""Find and return the path to the pg_config executable."""
|
|
|
|
if PLATFORM_IS_WINDOWS:
|
|
|
|
return self.autodetect_pg_config_path_windows()
|
|
|
|
else:
|
2011-06-07 22:25:59 +04:00
|
|
|
return self.find_on_path('pg_config')
|
2011-06-07 01:01:52 +04:00
|
|
|
|
|
|
|
def autodetect_pg_config_path_windows(self):
|
|
|
|
"""Attempt several different ways of finding the pg_config
|
|
|
|
executable on Windows, and return its full path, if found."""
|
2011-06-07 21:53:10 +04:00
|
|
|
|
2011-06-07 22:25:59 +04:00
|
|
|
# This code only runs if they have not specified a pg_config option
|
|
|
|
# in the config file or via the commandline.
|
2011-06-07 21:53:10 +04:00
|
|
|
|
2011-06-07 22:25:59 +04:00
|
|
|
# First, check for pg_config.exe on the PATH, and use that if found.
|
|
|
|
pg_config_exe = self.find_on_path('pg_config.exe')
|
|
|
|
if pg_config_exe:
|
|
|
|
return pg_config_exe
|
2011-06-07 01:01:52 +04:00
|
|
|
|
2011-06-07 22:25:59 +04:00
|
|
|
# Now, try looking in the Windows Registry to find a PostgreSQL
|
|
|
|
# installation, and infer the path from that.
|
2011-06-08 01:15:37 +04:00
|
|
|
pg_config_exe = self._get_pg_config_from_registry()
|
|
|
|
if pg_config_exe:
|
|
|
|
return pg_config_exe
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def _get_pg_config_from_registry(self):
|
2011-06-07 01:01:52 +04:00
|
|
|
try:
|
|
|
|
import winreg
|
|
|
|
except ImportError:
|
|
|
|
import _winreg as winreg
|
|
|
|
|
|
|
|
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
|
|
|
|
try:
|
|
|
|
pg_inst_list_key = winreg.OpenKey(reg,
|
2011-06-08 01:15:37 +04:00
|
|
|
'SOFTWARE\\PostgreSQL\\Installations')
|
2011-06-07 01:01:52 +04:00
|
|
|
except EnvironmentError:
|
2011-06-07 22:25:59 +04:00
|
|
|
# No PostgreSQL installation, as best as we can tell.
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Determine the name of the first subkey, if any:
|
2011-06-07 01:01:52 +04:00
|
|
|
try:
|
2011-06-07 22:25:59 +04:00
|
|
|
first_sub_key_name = winreg.EnumKey(pg_inst_list_key, 0)
|
|
|
|
except EnvironmentError:
|
2011-06-08 01:15:37 +04:00
|
|
|
return None
|
|
|
|
|
|
|
|
pg_first_inst_key = winreg.OpenKey(reg,
|
2017-11-28 06:33:23 +03:00
|
|
|
'SOFTWARE\\PostgreSQL\\Installations\\' + first_sub_key_name)
|
2011-06-08 01:15:37 +04:00
|
|
|
try:
|
|
|
|
pg_inst_base_dir = winreg.QueryValueEx(
|
|
|
|
pg_first_inst_key, 'Base Directory')[0]
|
|
|
|
finally:
|
|
|
|
winreg.CloseKey(pg_first_inst_key)
|
|
|
|
|
2011-06-07 22:25:59 +04:00
|
|
|
finally:
|
|
|
|
winreg.CloseKey(pg_inst_list_key)
|
2011-06-07 01:01:52 +04:00
|
|
|
|
2011-06-08 01:15:37 +04:00
|
|
|
pg_config_path = os.path.join(
|
|
|
|
pg_inst_base_dir, 'bin', 'pg_config.exe')
|
|
|
|
if not os.path.exists(pg_config_path):
|
|
|
|
return None
|
|
|
|
|
|
|
|
# Support unicode paths, if this version of Python provides the
|
|
|
|
# necessary infrastructure:
|
2017-11-28 11:22:02 +03:00
|
|
|
if sys.version_info[0] < 3:
|
2011-06-08 01:15:37 +04:00
|
|
|
pg_config_path = pg_config_path.encode(
|
|
|
|
sys.getfilesystemencoding())
|
2011-06-07 01:01:52 +04:00
|
|
|
|
|
|
|
return pg_config_path
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
class psycopg_build_ext(build_ext):
|
|
|
|
"""Conditionally complement the setup.cfg options file.
|
|
|
|
|
2013-04-26 12:21:56 +04:00
|
|
|
This class configures the include_dirs, library_dirs, libraries
|
2011-02-11 03:16:10 +03:00
|
|
|
options as required by the system. Most of the configuration happens
|
|
|
|
in finalize_options() method.
|
|
|
|
|
|
|
|
If you want to set up the build step for a peculiar platform, add a
|
|
|
|
method finalize_PLAT(), where PLAT matches your sys.platform.
|
|
|
|
"""
|
|
|
|
user_options = build_ext.user_options[:]
|
|
|
|
user_options.extend([
|
|
|
|
('use-pydatetime', None,
|
|
|
|
"Use Python datatime objects for date and time representation."),
|
|
|
|
('pg-config=', None,
|
2016-10-11 02:10:53 +03:00
|
|
|
"The name of the pg_config binary and/or full path to find it"),
|
2011-02-11 03:16:10 +03:00
|
|
|
('have-ssl', None,
|
|
|
|
"Compile with OpenSSL built PostgreSQL libraries (Windows only)."),
|
|
|
|
('static-libpq', None,
|
|
|
|
"Statically link the PostgreSQL client library"),
|
|
|
|
])
|
|
|
|
|
|
|
|
boolean_options = build_ext.boolean_options[:]
|
|
|
|
boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq'))
|
|
|
|
|
2011-06-07 01:01:52 +04:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
build_ext.__init__(self, *args, **kwargs)
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
def initialize_options(self):
|
|
|
|
build_ext.initialize_options(self)
|
|
|
|
self.use_pg_dll = 1
|
|
|
|
self.pgdir = None
|
|
|
|
self.mx_include_dir = None
|
|
|
|
self.use_pydatetime = 1
|
|
|
|
self.have_ssl = have_ssl
|
2011-03-26 16:48:37 +03:00
|
|
|
self.static_libpq = static_libpq
|
2011-06-07 21:53:10 +04:00
|
|
|
self.pg_config = None
|
2011-02-11 03:16:10 +03:00
|
|
|
|
2011-06-08 02:28:17 +04:00
|
|
|
def compiler_is_msvc(self):
|
|
|
|
return self.get_compiler_name().lower().startswith('msvc')
|
|
|
|
|
|
|
|
def compiler_is_mingw(self):
|
|
|
|
return self.get_compiler_name().lower().startswith('mingw')
|
|
|
|
|
2011-06-07 01:19:27 +04:00
|
|
|
def get_compiler_name(self):
|
2011-02-11 03:16:10 +03:00
|
|
|
"""Return the name of the C compiler used to compile extensions.
|
|
|
|
|
|
|
|
If a compiler was not explicitly set (on the command line, for
|
|
|
|
example), fall back on the default compiler.
|
|
|
|
"""
|
|
|
|
if self.compiler:
|
|
|
|
# distutils doesn't keep the type of self.compiler uniform; we
|
|
|
|
# compensate:
|
|
|
|
if isinstance(self.compiler, str):
|
|
|
|
name = self.compiler
|
|
|
|
else:
|
|
|
|
name = self.compiler.compiler_type
|
|
|
|
else:
|
|
|
|
name = get_default_compiler()
|
|
|
|
return name
|
|
|
|
|
2011-06-07 01:19:27 +04:00
|
|
|
def get_export_symbols(self, extension):
|
2011-02-25 00:12:40 +03:00
|
|
|
# Fix MSVC seeing two of the same export symbols.
|
2011-06-08 02:28:17 +04:00
|
|
|
if self.compiler_is_msvc():
|
2011-02-25 00:12:40 +03:00
|
|
|
return []
|
|
|
|
else:
|
2011-06-07 01:19:27 +04:00
|
|
|
return build_ext.get_export_symbols(self, extension)
|
2011-02-25 00:12:40 +03:00
|
|
|
|
2018-01-13 23:11:18 +03:00
|
|
|
built_files = 0
|
|
|
|
|
2011-06-07 01:19:27 +04:00
|
|
|
def build_extension(self, extension):
|
2018-01-13 23:11:18 +03:00
|
|
|
# Count files compiled to print the binary blurb only if the first fails
|
|
|
|
compile_orig = getattr(self.compiler, '_compile', None)
|
|
|
|
if compile_orig is not None:
|
|
|
|
def _compile(*args, **kwargs):
|
|
|
|
rv = compile_orig(*args, **kwargs)
|
|
|
|
psycopg_build_ext.built_files += 1
|
|
|
|
return rv
|
|
|
|
|
|
|
|
self.compiler._compile = _compile
|
|
|
|
|
|
|
|
try:
|
|
|
|
build_ext.build_extension(self, extension)
|
|
|
|
psycopg_build_ext.built_files += 1
|
|
|
|
except CompileError:
|
|
|
|
if self.built_files == 0:
|
|
|
|
sys.stderr.write("""
|
|
|
|
It appears you are missing some prerequisite to build the package from source.
|
|
|
|
|
|
|
|
You may install a binary package by installing 'psycopg2-binary' from PyPI.
|
|
|
|
If you want to install psycopg2 from source, please install the packages
|
|
|
|
required for the build and try again.
|
|
|
|
|
|
|
|
For further information please check the 'doc/src/install.rst' file (also at
|
|
|
|
<http://initd.org/psycopg/docs/install.html>).
|
|
|
|
|
|
|
|
""")
|
|
|
|
raise
|
|
|
|
|
2011-06-08 07:50:53 +04:00
|
|
|
sysVer = sys.version_info[:2]
|
2011-02-11 03:16:10 +03:00
|
|
|
|
2011-02-15 02:03:38 +03:00
|
|
|
# For Python versions that use MSVC compiler 2008, re-insert the
|
2011-06-07 22:25:59 +04:00
|
|
|
# manifest into the resulting .pyd file.
|
2017-11-28 12:13:38 +03:00
|
|
|
if self.compiler_is_msvc() and sysVer == (2, 7):
|
2011-02-11 20:01:38 +03:00
|
|
|
platform = get_platform()
|
|
|
|
# Default to the x86 manifest
|
|
|
|
manifest = '_psycopg.vc9.x86.manifest'
|
|
|
|
if platform == 'win-amd64':
|
|
|
|
manifest = '_psycopg.vc9.amd64.manifest'
|
2014-01-11 01:41:16 +04:00
|
|
|
try:
|
|
|
|
ext_path = self.get_ext_fullpath(extension.name)
|
|
|
|
except AttributeError:
|
|
|
|
ext_path = os.path.join(self.build_lib,
|
|
|
|
'psycopg2', '_psycopg.pyd')
|
2016-01-06 17:04:33 +03:00
|
|
|
# Make sure spawn() will work if compile() was never
|
|
|
|
# called. https://github.com/psycopg/psycopg2/issues/380
|
|
|
|
if not self.compiler.initialized:
|
|
|
|
self.compiler.initialize()
|
2011-06-07 01:19:27 +04:00
|
|
|
self.compiler.spawn(
|
|
|
|
['mt.exe', '-nologo', '-manifest',
|
|
|
|
os.path.join('psycopg', manifest),
|
2014-01-10 23:56:14 +04:00
|
|
|
'-outputresource:%s;2' % ext_path])
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
def finalize_win32(self):
|
|
|
|
"""Finalize build system configuration on win32 platform."""
|
|
|
|
|
|
|
|
# Add compiler-specific arguments:
|
|
|
|
extra_compiler_args = []
|
|
|
|
|
2011-06-08 02:28:17 +04:00
|
|
|
if self.compiler_is_mingw():
|
2011-02-11 03:16:10 +03:00
|
|
|
# Default MinGW compilation of Python extensions on Windows uses
|
|
|
|
# only -O:
|
|
|
|
extra_compiler_args.append('-O3')
|
|
|
|
|
|
|
|
# GCC-compiled Python on non-Windows platforms is built with strict
|
|
|
|
# aliasing disabled, but that must be done explicitly on Windows to
|
|
|
|
# avoid large numbers of warnings for perfectly idiomatic Python C
|
|
|
|
# API code.
|
|
|
|
extra_compiler_args.append('-fno-strict-aliasing')
|
|
|
|
|
2011-06-07 01:19:27 +04:00
|
|
|
for extension in ext: # ext is a global list of Extension objects
|
|
|
|
extension.extra_compile_args.extend(extra_compiler_args)
|
2011-02-11 03:16:10 +03:00
|
|
|
# End of add-compiler-specific arguments section.
|
|
|
|
|
|
|
|
self.libraries.append("ws2_32")
|
|
|
|
self.libraries.append("advapi32")
|
2011-06-08 02:28:17 +04:00
|
|
|
if self.compiler_is_msvc():
|
2011-02-11 03:16:10 +03:00
|
|
|
# MSVC requires an explicit "libpq"
|
2016-07-01 04:23:59 +03:00
|
|
|
if "pq" in self.libraries:
|
|
|
|
self.libraries.remove("pq")
|
2011-02-11 03:16:10 +03:00
|
|
|
self.libraries.append("secur32")
|
|
|
|
self.libraries.append("libpq")
|
|
|
|
self.libraries.append("shfolder")
|
|
|
|
for path in self.library_dirs:
|
|
|
|
if os.path.isfile(os.path.join(path, "ms", "libpq.lib")):
|
|
|
|
self.library_dirs.append(os.path.join(path, "ms"))
|
|
|
|
break
|
|
|
|
if self.have_ssl:
|
|
|
|
self.libraries.append("libeay32")
|
|
|
|
self.libraries.append("ssleay32")
|
|
|
|
self.libraries.append("crypt32")
|
|
|
|
self.libraries.append("user32")
|
|
|
|
self.libraries.append("gdi32")
|
|
|
|
|
|
|
|
def finalize_darwin(self):
|
|
|
|
"""Finalize build system configuration on darwin platform."""
|
|
|
|
self.libraries.append('ssl')
|
|
|
|
self.libraries.append('crypto')
|
|
|
|
|
2012-09-21 05:28:52 +04:00
|
|
|
def finalize_linux(self):
|
2011-02-11 03:16:10 +03:00
|
|
|
"""Finalize build system configuration on GNU/Linux platform."""
|
|
|
|
# tell piro that GCC is fine and dandy, but not so MS compilers
|
2011-06-07 01:19:27 +04:00
|
|
|
for extension in self.extensions:
|
|
|
|
extension.extra_compile_args.append(
|
|
|
|
'-Wdeclaration-after-statement')
|
2011-02-11 03:16:10 +03:00
|
|
|
|
2012-09-21 05:28:52 +04:00
|
|
|
finalize_linux2 = finalize_linux
|
|
|
|
finalize_linux3 = finalize_linux
|
2011-11-26 23:08:20 +04:00
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
def finalize_options(self):
|
2013-04-26 12:21:56 +04:00
|
|
|
"""Complete the build system configuration."""
|
2016-07-07 14:05:29 +03:00
|
|
|
# An empty option in the setup.cfg causes self.libraries to include
|
|
|
|
# an empty string in the list of libraries
|
|
|
|
if self.libraries is not None and not self.libraries.strip():
|
|
|
|
self.libraries = None
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
build_ext.finalize_options(self)
|
|
|
|
|
2011-06-07 21:53:10 +04:00
|
|
|
pg_config_helper = PostgresConfig(self)
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
self.include_dirs.append(".")
|
2011-03-26 16:48:37 +03:00
|
|
|
if self.static_libpq:
|
2011-08-09 14:35:45 +04:00
|
|
|
if not getattr(self, 'link_objects', None):
|
2011-06-07 01:19:27 +04:00
|
|
|
self.link_objects = []
|
2011-02-11 03:16:10 +03:00
|
|
|
self.link_objects.append(
|
2016-10-11 02:10:53 +03:00
|
|
|
os.path.join(pg_config_helper.query("libdir"), "libpq.a"))
|
2011-02-11 03:16:10 +03:00
|
|
|
else:
|
|
|
|
self.libraries.append("pq")
|
|
|
|
|
|
|
|
try:
|
2011-06-07 21:53:10 +04:00
|
|
|
self.library_dirs.append(pg_config_helper.query("libdir"))
|
|
|
|
self.include_dirs.append(pg_config_helper.query("includedir"))
|
|
|
|
self.include_dirs.append(pg_config_helper.query("includedir-server"))
|
2018-07-03 19:16:21 +03:00
|
|
|
pgversion = pg_config_helper.query("version").split()[1]
|
2011-02-11 03:16:10 +03:00
|
|
|
|
2011-06-07 01:19:27 +04:00
|
|
|
verre = re.compile(
|
2017-02-04 16:21:07 +03:00
|
|
|
r"(\d+)(?:\.(\d+))?(?:(?:\.(\d+))|(devel|(?:alpha|beta|rc)\d+))?")
|
2011-02-11 03:16:10 +03:00
|
|
|
m = verre.match(pgversion)
|
|
|
|
if m:
|
|
|
|
pgmajor, pgminor, pgpatch = m.group(1, 2, 3)
|
2017-11-28 06:33:23 +03:00
|
|
|
# Postgres >= 10 doesn't have pgminor anymore.
|
|
|
|
pgmajor = int(pgmajor)
|
|
|
|
if pgmajor >= 10:
|
|
|
|
pgminor, pgpatch = None, pgminor
|
2017-02-04 16:21:07 +03:00
|
|
|
if pgminor is None or not pgminor.isdigit():
|
|
|
|
pgminor = 0
|
2011-02-11 03:16:10 +03:00
|
|
|
if pgpatch is None or not pgpatch.isdigit():
|
|
|
|
pgpatch = 0
|
2014-09-11 02:00:42 +04:00
|
|
|
pgminor = int(pgminor)
|
|
|
|
pgpatch = int(pgpatch)
|
2011-02-11 03:16:10 +03:00
|
|
|
else:
|
|
|
|
sys.stderr.write(
|
|
|
|
"Error: could not determine PostgreSQL version from '%s'"
|
2016-10-11 02:10:53 +03:00
|
|
|
% pgversion)
|
2011-02-11 03:16:10 +03:00
|
|
|
sys.exit(1)
|
|
|
|
|
2015-06-01 19:05:11 +03:00
|
|
|
define_macros.append(("PG_VERSION_NUM", "%d%02d%02d" %
|
2014-09-11 02:00:42 +04:00
|
|
|
(pgmajor, pgminor, pgpatch)))
|
2014-09-08 20:05:28 +04:00
|
|
|
|
2014-09-11 02:30:34 +04:00
|
|
|
# enable lo64 if libpq >= 9.3 and Python 64 bits
|
2015-02-09 01:52:50 +03:00
|
|
|
if (pgmajor, pgminor) >= (9, 3) and is_py_64():
|
2014-09-08 20:05:28 +04:00
|
|
|
define_macros.append(("HAVE_LO64", "1"))
|
|
|
|
|
2014-09-11 02:16:29 +04:00
|
|
|
# Inject the flag in the version string already packed up
|
|
|
|
# because we didn't know the version before.
|
|
|
|
# With distutils everything is complicated.
|
|
|
|
for i, t in enumerate(define_macros):
|
|
|
|
if t[0] == 'PSYCOPG_VERSION':
|
|
|
|
n = t[1].find(')')
|
|
|
|
if n > 0:
|
|
|
|
define_macros[i] = (
|
|
|
|
t[0], t[1][:n] + ' lo64' + t[1][n:])
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
except Warning:
|
2011-06-07 01:19:27 +04:00
|
|
|
w = sys.exc_info()[1] # work around py 2/3 different syntax
|
2011-02-11 03:16:10 +03:00
|
|
|
sys.stderr.write("Error: %s\n" % w)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if hasattr(self, "finalize_" + sys.platform):
|
|
|
|
getattr(self, "finalize_" + sys.platform)()
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
|
2015-02-09 01:52:50 +03:00
|
|
|
def is_py_64():
|
|
|
|
# sys.maxint not available since Py 3.1;
|
|
|
|
# sys.maxsize not available before Py 2.6;
|
|
|
|
# this is portable at least between Py 2.4 and 3.4.
|
|
|
|
import struct
|
|
|
|
return struct.calcsize("P") > 4
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
# let's start with macro definitions (the ones not already in setup.cfg)
|
|
|
|
define_macros = []
|
|
|
|
include_dirs = []
|
|
|
|
|
|
|
|
# gather information to build the extension module
|
2011-06-07 01:19:27 +04:00
|
|
|
ext = []
|
|
|
|
data_files = []
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
# sources
|
|
|
|
|
|
|
|
sources = [
|
|
|
|
'psycopgmodule.c',
|
|
|
|
'green.c', 'pqpath.c', 'utils.c', 'bytes_format.c',
|
2017-10-26 21:11:51 +03:00
|
|
|
'libpq_support.c', 'win32_support.c', 'solaris_support.c',
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
'connection_int.c', 'connection_type.c',
|
2018-10-11 04:59:45 +03:00
|
|
|
'cursor_int.c', 'cursor_type.c', 'column_type.c',
|
2015-10-27 20:21:24 +03:00
|
|
|
'replication_connection_type.c',
|
|
|
|
'replication_cursor_type.c',
|
|
|
|
'replication_message_type.c',
|
2018-10-12 00:42:52 +03:00
|
|
|
'diagnostics_type.c', 'error_type.c', 'conninfo_type.c',
|
2011-02-11 03:16:10 +03:00
|
|
|
'lobject_int.c', 'lobject_type.c',
|
|
|
|
'notify_type.c', 'xid_type.c',
|
|
|
|
|
|
|
|
'adapter_asis.c', 'adapter_binary.c', 'adapter_datetime.c',
|
|
|
|
'adapter_list.c', 'adapter_pboolean.c', 'adapter_pdecimal.c',
|
2011-05-31 01:00:20 +04:00
|
|
|
'adapter_pint.c', 'adapter_pfloat.c', 'adapter_qstring.c',
|
2011-02-11 03:16:10 +03:00
|
|
|
'microprotocols.c', 'microprotocols_proto.c',
|
|
|
|
'typecast.c',
|
|
|
|
]
|
|
|
|
|
|
|
|
depends = [
|
|
|
|
# headers
|
2013-03-19 07:06:00 +04:00
|
|
|
'config.h', 'pgtypes.h', 'psycopg.h', 'python.h', 'connection.h',
|
|
|
|
'cursor.h', 'diagnostics.h', 'error.h', 'green.h', 'lobject.h',
|
2015-10-27 20:21:24 +03:00
|
|
|
'replication_connection.h',
|
|
|
|
'replication_cursor.h',
|
|
|
|
'replication_message.h',
|
2018-10-12 00:42:52 +03:00
|
|
|
'notify.h', 'pqpath.h', 'xid.h', 'column.h', 'conninfo.h',
|
2018-12-29 18:13:12 +03:00
|
|
|
'libpq_support.h', 'win32_support.h', 'utils.h',
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
'adapter_asis.h', 'adapter_binary.h', 'adapter_datetime.h',
|
|
|
|
'adapter_list.h', 'adapter_pboolean.h', 'adapter_pdecimal.h',
|
2011-05-31 01:00:20 +04:00
|
|
|
'adapter_pint.h', 'adapter_pfloat.h', 'adapter_qstring.h',
|
2011-02-11 03:16:10 +03:00
|
|
|
'microprotocols.h', 'microprotocols_proto.h',
|
|
|
|
'typecast.h', 'typecast_binary.h',
|
|
|
|
|
|
|
|
# included sources
|
|
|
|
'typecast_array.c', 'typecast_basic.c', 'typecast_binary.c',
|
|
|
|
'typecast_builtins.c', 'typecast_datetime.c',
|
|
|
|
]
|
|
|
|
|
|
|
|
parser = configparser.ConfigParser()
|
|
|
|
parser.read('setup.cfg')
|
|
|
|
|
|
|
|
# Choose a datetime module
|
|
|
|
have_pydatetime = True
|
|
|
|
have_mxdatetime = False
|
2016-10-11 02:10:53 +03:00
|
|
|
use_pydatetime = int(parser.get('build_ext', 'use_pydatetime'))
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
# check for mx package
|
2017-03-22 06:19:34 +03:00
|
|
|
mxincludedir = ''
|
2011-02-11 03:16:10 +03:00
|
|
|
if parser.has_option('build_ext', 'mx_include_dir'):
|
|
|
|
mxincludedir = parser.get('build_ext', 'mx_include_dir')
|
2017-03-22 06:19:34 +03:00
|
|
|
if not mxincludedir:
|
2011-02-11 03:16:10 +03:00
|
|
|
mxincludedir = os.path.join(get_python_inc(plat_specific=1), "mx")
|
2016-07-07 14:05:29 +03:00
|
|
|
if mxincludedir.strip() and os.path.exists(mxincludedir):
|
2011-06-04 17:16:24 +04:00
|
|
|
# Build the support for mx: we will check at runtime if it can be imported
|
|
|
|
include_dirs.append(mxincludedir)
|
2011-06-07 01:19:27 +04:00
|
|
|
define_macros.append(('HAVE_MXDATETIME', '1'))
|
2011-06-04 17:16:24 +04:00
|
|
|
sources.append('adapter_mxdatetime.c')
|
|
|
|
depends.extend(['adapter_mxdatetime.h', 'typecast_mxdatetime.c'])
|
|
|
|
have_mxdatetime = True
|
|
|
|
version_flags.append('mx')
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
# now decide which package will be the default for date/time typecasts
|
|
|
|
if have_pydatetime and (use_pydatetime or not have_mxdatetime):
|
2011-06-07 01:19:27 +04:00
|
|
|
define_macros.append(('PSYCOPG_DEFAULT_PYDATETIME', '1'))
|
2011-02-11 03:16:10 +03:00
|
|
|
elif have_mxdatetime:
|
2011-06-07 01:19:27 +04:00
|
|
|
define_macros.append(('PSYCOPG_DEFAULT_MXDATETIME', '1'))
|
2011-02-11 03:16:10 +03:00
|
|
|
else:
|
2011-06-07 01:19:27 +04:00
|
|
|
error_message = """\
|
|
|
|
psycopg requires a datetime module:
|
|
|
|
mx.DateTime module not found
|
|
|
|
python datetime module not found
|
|
|
|
|
|
|
|
Note that psycopg needs the module headers and not just the module
|
|
|
|
itself. If you installed Python or mx.DateTime from a binary package
|
|
|
|
you probably need to install its companion -dev or -devel package."""
|
|
|
|
|
|
|
|
for line in error_message.split("\n"):
|
|
|
|
sys.stderr.write("error: " + line)
|
2011-02-11 03:16:10 +03:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# generate a nice version string to avoid confusion when users report bugs
|
2016-10-11 02:10:53 +03:00
|
|
|
version_flags.append('pq3') # no more a choice
|
|
|
|
version_flags.append('ext') # no more a choice
|
2014-04-04 20:30:10 +04:00
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
if version_flags:
|
|
|
|
PSYCOPG_VERSION_EX = PSYCOPG_VERSION + " (%s)" % ' '.join(version_flags)
|
|
|
|
else:
|
|
|
|
PSYCOPG_VERSION_EX = PSYCOPG_VERSION
|
|
|
|
|
2018-02-19 14:28:13 +03:00
|
|
|
define_macros.append(('PSYCOPG_VERSION', PSYCOPG_VERSION_EX))
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
if parser.has_option('build_ext', 'have_ssl'):
|
|
|
|
have_ssl = int(parser.get('build_ext', 'have_ssl'))
|
|
|
|
else:
|
|
|
|
have_ssl = 0
|
|
|
|
|
|
|
|
if parser.has_option('build_ext', 'static_libpq'):
|
|
|
|
static_libpq = int(parser.get('build_ext', 'static_libpq'))
|
|
|
|
else:
|
|
|
|
static_libpq = 0
|
|
|
|
|
2014-04-04 20:30:10 +04:00
|
|
|
# And now... explicitly add the defines from the .cfg files.
|
|
|
|
# Looks like setuptools or some other cog doesn't add them to the command line
|
|
|
|
# when called e.g. with "pip -e git+url'. This results in declarations
|
|
|
|
# duplicate on the commandline, which I hope is not a problem.
|
|
|
|
for define in parser.get('build_ext', 'define').split(','):
|
2014-08-24 04:43:12 +04:00
|
|
|
if define:
|
|
|
|
define_macros.append((define, '1'))
|
2014-04-04 20:30:10 +04:00
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
# build the extension
|
|
|
|
|
2016-10-11 02:10:53 +03:00
|
|
|
sources = [os.path.join('psycopg', x) for x in sources]
|
|
|
|
depends = [os.path.join('psycopg', x) for x in depends]
|
2011-02-11 03:16:10 +03:00
|
|
|
|
|
|
|
ext.append(Extension("psycopg2._psycopg", sources,
|
|
|
|
define_macros=define_macros,
|
|
|
|
include_dirs=include_dirs,
|
|
|
|
depends=depends,
|
|
|
|
undef_macros=[]))
|
2011-02-18 16:48:15 +03:00
|
|
|
|
|
|
|
# Compute the direct download url.
|
|
|
|
# Note that the current package installation programs are stupidly intelligent
|
|
|
|
# and will try to install a beta if they find a link in the homepage instead of
|
|
|
|
# using these pretty metadata. But that's their problem, not ours.
|
|
|
|
download_url = (
|
|
|
|
"http://initd.org/psycopg/tarballs/PSYCOPG-%s/psycopg2-%s.tar.gz"
|
2017-02-08 21:09:15 +03:00
|
|
|
% (re.sub(r'^(\d+)\.(\d+).*', r'\1-\2', PSYCOPG_VERSION),
|
|
|
|
PSYCOPG_VERSION))
|
2011-02-18 16:48:15 +03:00
|
|
|
|
2014-08-31 05:59:49 +04:00
|
|
|
try:
|
|
|
|
f = open("README.rst")
|
|
|
|
readme = f.read()
|
|
|
|
f.close()
|
2017-11-28 11:11:42 +03:00
|
|
|
except Exception:
|
2014-08-31 05:59:49 +04:00
|
|
|
print("failed to read readme: ignoring...")
|
|
|
|
readme = __doc__
|
|
|
|
|
2011-02-11 03:16:10 +03:00
|
|
|
setup(name="psycopg2",
|
|
|
|
version=PSYCOPG_VERSION,
|
|
|
|
maintainer="Federico Di Gregorio",
|
|
|
|
maintainer_email="fog@initd.org",
|
|
|
|
author="Federico Di Gregorio",
|
|
|
|
author_email="fog@initd.org",
|
|
|
|
url="http://initd.org/psycopg/",
|
2011-06-07 01:19:27 +04:00
|
|
|
download_url=download_url,
|
2014-05-20 20:50:53 +04:00
|
|
|
license="LGPL with exceptions or ZPL",
|
2011-06-07 01:19:27 +04:00
|
|
|
platforms=["any"],
|
2017-11-28 12:13:38 +03:00
|
|
|
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
|
2014-08-31 05:59:49 +04:00
|
|
|
description=readme.split("\n")[0],
|
|
|
|
long_description="\n".join(readme.split("\n")[2:]).lstrip(),
|
2011-02-11 03:16:10 +03:00
|
|
|
classifiers=[x for x in classifiers.split("\n") if x],
|
|
|
|
data_files=data_files,
|
2017-12-04 05:47:19 +03:00
|
|
|
package_dir={'psycopg2': 'lib'},
|
|
|
|
packages=['psycopg2'],
|
2017-12-11 05:35:41 +03:00
|
|
|
cmdclass={'build_ext': psycopg_build_ext},
|
2011-02-11 03:16:10 +03:00
|
|
|
ext_modules=ext)
|