Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit af424821b70299704449337904d3ab7fb1b40751 1 parent c687f1d
@dvarrazzo authored
Showing with 19 additions and 6 deletions.
  1. +7 −0 NEWS
  2. +12 −6 setup.py
View
7 NEWS
@@ -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
18 setup.py
@@ -450,12 +450,18 @@ def autodetect_pg_config_path_windows(self):
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):

12 comments on commit af42482

@mattharrison

This commit does not make virtual installs work. If you have a system mx, you will still get the failure. At least I do on Ubuntu 10.10

@dvarrazzo
Owner

Strange, It's been tested by somebody. Do you have better indication about how to fix the problem? Or at least which packages to install in order to reproduce the failure?

@mattharrison

I've currently got mx and your dev for psycopg2 installed

$ pip freeze
...
egenix-mx-base==3.2.0
...
psycopg2==2.4.2.dev0

But I can't import the db driver...

$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mx
>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mharrison/env/lib/python2.6/site-packages/psycopg2/__init__.py", line 71, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: can't import mx.DateTime module
@dvarrazzo
Owner

The patch is for build time: when you built psycopg, was mx available?

I may try if I can make the module also importable without mx, even if it was available when building.

@mattharrison

Yeah, both system mx and virtual mx are installed (and loadable from the interpreter).

>>> import mx
>>> mx.__file__
'/home/mharrison/work/env/lib/python2.6/site-packages/mx/__init__.pyc'
>>> import mx.DateTime
>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mharrison/work/env/lib/python2.6/site-packages/psycopg2/__init__.py", line 71, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: can't import mx.DateTime module

I'm not sure what is going on, maybe I have some conflict....

@dvarrazzo
Owner

Yeah, it should have definitely worked. It is not the same issue addressed in #53: it seems something different. Can you compile psycopg with PSYCOPG_DEBUG in the setup.cfg and import it with the env variable PSYCOPG_DEBUG set? You should get some debug info, maybe there's something there.

Also, can you import mx.DateTime from your env or mx only?

@dvarrazzo
Owner

Oh, I've seen you can import mx.DateTime as well. This is definitely fishy.

What command you've uses to create your virtual env? I want to go to the bottom of this story. Thanks.

@mattharrison

hmmmm

I added

PSYCOPG_DEBUG=1

to setup.cfg and ran "pip install path/to/fixed/psycopg'

got the following in ~/.pip/pip.log


------------------------------------------------------------
/home/mharrison/work/env/bin/pip run on Tue May 24 10:32:20 2011
Unpacking ./psycopgfix/psycopg
  Running setup.py egg_info for package from file:///home/mharrison/work/psycopgfix/psycopg
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found
    error: error in setup.cfg: command 'psycopg_build_ext' has no such option 'psycopg_debug'
    Complete output from command python setup.py egg_info:
    running egg_info

creating pip-egg-info/psycopg2.egg-info

writing pip-egg-info/psycopg2.egg-info/PKG-INFO

writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt

writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

warning: manifest_maker: standard file '-c' not found

error: error in setup.cfg: command 'psycopg_build_ext' has no such option 'psycopg_debug'

----------------------------------------
Command python setup.py egg_info failed with error code 1
Exception information:
Traceback (most recent call last):
  File "/home/mharrison/work/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/basecommand.py", line 120, in main
    self.run(options, args)
  File "/home/mharrison/work/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/commands/install.py", line 161, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/home/mharrison/work/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/req.py", line 903, in prepare_files
    req_to_install.run_egg_info()
  File "/home/mharrison/work/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/req.py", line 216, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/home/mharrison/work/env/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg/pip/__init__.py", line 226, in call_subprocess
    % (command_desc, proc.returncode))
InstallationError: Command python setup.py egg_info failed with error code 1
@dvarrazzo
Owner

I suspect pip doesn't get psycopg's setup. Why don't you use the plain "python setup.py build/install"?

@mattharrison
$ python setup.py build
running build
running build_py
running build_ext
error: error in setup.cfg: command 'psycopg_build_ext' has no such option 'psycopg_debug'
@dvarrazzo
Owner

This is what I mean:

$ git diff
diff --git a/setup.cfg b/setup.cfg
index 4d440a6..bb8c3d2 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [build_ext]
-define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM
+define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,PSYCOPG_DEBUG

 # PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this)
 # PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
@mattharrison

Sorry that didn't seem to make a difference. I ended up creating a new virtualenv and just using the system psycopg2... But apparently pip doesn't jive with the driver...

Please sign in to comment.
Something went wrong with that request. Please try again.