Don't build mx.DateTime support if the module can't be imported

Previously we only checked for the existence of the include files, but this
doesn't imply the presence of the module. Particularly true in restricted
environments such as virtualenv.

Closes ticket #53.
This commit is contained in:
Daniele Varrazzo 2011-05-04 01:07:07 +01:00
parent c687f1d816
commit af424821b7
2 changed files with 19 additions and 6 deletions

7
NEWS
View File

@ -1,3 +1,10 @@
What's new in psycopg 2.4.2
---------------------------
- Don't build mx.DateTime support if the module can't be imported
(ticket #53).
What's new in psycopg 2.4.1
---------------------------

View File

@ -450,12 +450,18 @@ if parser.has_option('build_ext', 'mx_include_dir'):
else:
mxincludedir = os.path.join(get_python_inc(plat_specific=1), "mx")
if os.path.exists(mxincludedir):
include_dirs.append(mxincludedir)
define_macros.append(('HAVE_MXDATETIME','1'))
sources.append('adapter_mxdatetime.c')
depends.extend(['adapter_mxdatetime.h', 'typecast_mxdatetime.c'])
have_mxdatetime = True
version_flags.append('mx')
# Check if mx.datetime is importable at all: see ticket #53
try:
import mx.DateTime
except ImportError:
pass
else:
include_dirs.append(mxincludedir)
define_macros.append(('HAVE_MXDATETIME','1'))
sources.append('adapter_mxdatetime.c')
depends.extend(['adapter_mxdatetime.h', 'typecast_mxdatetime.c'])
have_mxdatetime = True
version_flags.append('mx')
# now decide which package will be the default for date/time typecasts
if have_pydatetime and (use_pydatetime or not have_mxdatetime):