#731 closed defect (fixed)
Python bindings don't work out of the box
Reported by: | James Aylett | Owned by: | Olly Betts |
---|---|---|---|
Priority: | normal | Milestone: | 1.4.1 |
Component: | Xapian-bindings (Python) | Version: | 1.4.0 |
Severity: | critical | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Operating System: | All |
Description (last modified by )
Since the switch to a more recent SWIG, the method the shadow wrapper uses to import the wrapper (_xapian.so
or similar) has changed for python >= 2.7.0 (which is basically everything in common use these days). SWIG does not support <package>/__init__.py
as the shadow wrapper.
Right now it's unclear what the best solution is.
Change History (8)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Description: | modified (diff) |
---|---|
Milestone: | 1.4.x → 1.4.1 |
We really need to do something for 1.4.1.
comment:3 by , 8 years ago
I wonder if we should just replace the setup code wholesale - it's needlessly complicated for our needs, as we just want a wrapper than works for Python3 and a different one which works for 2.6 and 2.7, so all the code to check versions is just pointless complication and overhead.
Changing it to the following works for me (along with splitting the imports as you did in the patch):
new_instancemethod = lambda func, inst, cls: _xapian.SWIG_PyInstanceMethod_New(func) from . import _xapian _swig_property = property import builtins as __builtin__
For Python2 the following works for 2.7 and I think will also for 2.6:
from new import instancemethod as new_instancemethod from . import _xapian _swig_property = property import __builtin__
comment:4 by , 8 years ago
That's certainly much tidier! Is there an easy way to replace this by configuring SWIG, or are we going to have to build a little editing state machine in sed?
comment:5 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
We can do it with Perl if we do it at the same time as we run SWIG. Implemented for Python3 in [e32b88fc04c49b35c207f777d9a04b141bbe615c]. While we're fixing up the wrapper, I've also made it strip out various Python2.x stuff we don't need there.
comment:6 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Similar fixes for Python2 applied in [4789d1d367ee9a2ee55fb3ba23ad77d134a5a051].
comment:7 by , 8 years ago
FWIW, in SWIG 3.1 the plan is to drop all the legacy code which tries to support versions as far back as Python 2.0 - probably 2.6 and later will be the target. That'll get rid of a lot of the cruft, and at that point I'll see if we can get a way to control the import statement generated.
comment:8 by , 8 years ago
William's now added a way to specify the import code for SWIG to use, so I've made use of that in f24506a0c5cbb360e2ca89078fc4e94e1f804281. I've left the rest of the fixup script in place, as cleaning up the unnecessary code here gave a measurable (though small) speed up in module load time.
Possible solution: https://gist.github.com/jaylett/ae93745aec98192e50ea5684564276ae