diff options
| author | Federico Di Gregorio <fog@initd.org> | 2005-11-03 01:35:17 +0000 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2005-11-03 01:35:17 +0000 |
| commit | f03b94d84b93ef154bed3d8064b56fef9e0ead12 (patch) | |
| tree | ea56e3412f09c59f8624064b2c29cae572c72a33 | |
| parent | d67b171eede2c1749f28db93c9663badd399480e (diff) | |
| download | psycopg2-f03b94d84b93ef154bed3d8064b56fef9e0ead12.tar.gz | |
Run-time check for Decimal on Python 2.3.
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | psycopg/psycopgmodule.c | 5 | ||||
| -rw-r--r-- | setup.cfg | 5 | ||||
| -rw-r--r-- | setup.py | 17 |
4 files changed, 27 insertions, 5 deletions
@@ -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. diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 92b7a9d..387d3d7 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -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 } @@ -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: @@ -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 |
