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 What's new in psycopg 2.4.1
--------------------------- ---------------------------

View File

@ -450,6 +450,12 @@ if parser.has_option('build_ext', 'mx_include_dir'):
else: else:
mxincludedir = os.path.join(get_python_inc(plat_specific=1), "mx") mxincludedir = os.path.join(get_python_inc(plat_specific=1), "mx")
if os.path.exists(mxincludedir): if os.path.exists(mxincludedir):
# Check if mx.datetime is importable at all: see ticket #53
try:
import mx.DateTime
except ImportError:
pass
else:
include_dirs.append(mxincludedir) include_dirs.append(mxincludedir)
define_macros.append(('HAVE_MXDATETIME','1')) define_macros.append(('HAVE_MXDATETIME','1'))
sources.append('adapter_mxdatetime.c') sources.append('adapter_mxdatetime.c')