Run-time check for Decimal on Python 2.3.

This commit is contained in:
Federico Di Gregorio 2005-11-03 01:35:17 +00:00
parent d67b171eed
commit f03b94d84b
4 changed files with 27 additions and 5 deletions

View File

@ -1,3 +1,8 @@
2005-11-03 Federico Di Gregorio <fog@initd.org>
* Applied patch from Daniele Varazzo to enablÃeDecimal on Python
2.3 when the module is available (run-time check, nice.)
2005-10-26 Federico Di Gregorio <fog@initd.org>
* setup.cfg: added include_dirs line for SUSE 9.3.

View File

@ -363,6 +363,11 @@ psyco_decimal_init(void)
if (decimal) {
decimalType = PyObject_GetAttrString(decimal, "Decimal");
}
else {
PyErr_Clear();
decimalType = (PyObject *)&PyFloat_Type;
Py_INCREF(decimalType);
}
#endif
}

View File

@ -6,6 +6,11 @@ define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
# Set to 1 to use Python datatime objects for default date/time representation
use_pydatetime=1
# Set to 1 if you want to enable "Decimal" type on python 2.3.
# If the "decimal" module is found in the PYTHONPATH it will be used,
# else fall back on the float type.
use_decimal=0
# "include_dirs" is the preferred method for locating postgresql headers,
# but some extra checks on sys.platform will still be done in setup.py.
# The next line is the default as used on psycopg author Debian laptop:

View File

@ -81,11 +81,13 @@ class psycopg_build_ext(build_ext):
('use-pg-dll', None,
"Build against libpq.dll"),
('use-pydatetime', None,
"Use Python datatime objects for date and time representation.")
"Use Python datatime objects for date and time representation."),
('use-decimal', None,
"Use Decimal type even on Python 2.3 if the module is provided."),
])
boolean_options = build_ext.boolean_options[:]
boolean_options.extend(('use-pg-dll', 'use-pydatetime'))
boolean_options.extend(('use-pg-dll', 'use-pydatetime', 'use-decimal'))
# libpq directory in win32 source distribution: compiler dependant.
libpqdir = None
@ -246,9 +248,7 @@ define_macros.append(('PY_MINOR_VERSION', str(sys.version_info[1])))
# some macros related to python versions and features
if sys.version_info[0] >= 2 and sys.version_info[1] >= 3:
define_macros.append(('HAVE_PYBOOL','1'))
if sys.version_info[0] >= 2 and sys.version_info[1] >= 4:
define_macros.append(('HAVE_DECIMAL','1'))
# gather information to build the extension module
ext = [] ; data_files = []
@ -265,6 +265,13 @@ from ConfigParser import ConfigParser
parser = ConfigParser()
parser.read('setup.cfg')
# Choose if to use Decimal type
use_decimal = int(parser.get('build_ext', 'use_decimal'))
if sys.version_info[0] >= 2 and (
sys.version_info[1] >= 4 or (sys.version_info[1] == 3 and use_decimal)):
define_macros.append(('HAVE_DECIMAL','1'))
version_flags.append('dec')
# Choose a datetime module
have_pydatetime = False
have_mxdatetime = False