Skip to content

Instantly share code, notes, and snippets.

@jaylett
Last active August 7, 2016 12:58
Show Gist options
  • Save jaylett/ae93745aec98192e50ea5684564276ae to your computer and use it in GitHub Desktop.
Save jaylett/ae93745aec98192e50ea5684564276ae to your computer and use it in GitHub Desktop.
Second attempt at fixing python3 bindings
diff --git a/xapian-bindings/python/Makefile.am b/xapian-bindings/python/Makefile.am
index d811801..dae7e10 100644
--- a/xapian-bindings/python/Makefile.am
+++ b/xapian-bindings/python/Makefile.am
@@ -72,15 +72,22 @@ _xapian_la_LIBADD = $(XAPIAN_LIBS) $(PYTHON2_LIBS)
# as a package.
xapian/__init__.py: xapian.py
$(MKDIR_P) xapian
- cp `test -f xapian.py || echo '$(srcdir)/'`xapian.py xapian/__init__.py
+ sed "s/mname = .*/mname = 'xapian._xapian'/" < `test -f xapian.py || echo '$(srcdir)/'`xapian.py > xapian/__init__.py
# We "import _xapian" first so that if we fail to import the glue library
# we don't generate a broken .pyc or .pyo.
+#
+# We import _xapian on its own, because it requires a different PYTHONPATH.
+# This prevents importing xapian from succeeding when it should fail, such
+# as if we didn't make alternations to the SWIG shadow wrapper to cope
+# with being xapian/__init__.py.
xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON2_SO)
- PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON2) -c 'import _xapian; import xapian'
+ PYTHONPATH="xapian" $(PYTHON2) -c 'import _xapian'
+ $(PYTHON2) -c 'import xapian'
xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON2_SO)
- PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON2) -O -c 'import _xapian; import xapian'
+ PYTHONPATH="xapian" $(PYTHON2) -O -c 'import _xapian'
+ $(PYTHON2) -O -c 'import xapian'
xapian/_xapian$(PYTHON2_SO): _xapian.la
$(MKDIR_P) xapian
diff --git a/xapian-bindings/python3/Makefile.am b/xapian-bindings/python3/Makefile.am
index 2301658..e50d6c4 100644
--- a/xapian-bindings/python3/Makefile.am
+++ b/xapian-bindings/python3/Makefile.am
@@ -71,15 +71,22 @@ _xapian_la_LIBADD = $(XAPIAN_LIBS) $(PYTHON3_LIBS)
# as a package.
xapian/__init__.py: xapian.py
$(MKDIR_P) xapian
- cp `test -f xapian.py || echo '$(srcdir)/'`xapian.py xapian/__init__.py
+ sed "s/mname = .*/mname = 'xapian._xapian'/" < `test -f xapian.py || echo '$(srcdir)/'`xapian.py > xapian/__init__.py
# We "import _xapian" first so that if we fail to import the glue library
# we don't generate a broken .pyc or .pyo.
+#
+# We import _xapian on its own, because it requires a different PYTHONPATH.
+# This prevents importing xapian from succeeding when it should fail, such
+# as if we didn't make alternations to the SWIG shadow wrapper to cope
+# with being xapian/__init__.py.
xapian/__pycache__/__init__.@PYTHON3_CACHE_TAG@.pyc: xapian/__init__.py xapian/_xapian$(PYTHON3_SO)
- PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON3) -c 'import _xapian; import xapian'
+ PYTHONPATH="xapian" $(PYTHON3) -c 'import _xapian'
+ $(PYTHON3) -c 'import xapian'
xapian/__pycache__/__init__.@PYTHON3_CACHE_OPT1_EXT@: xapian/__init__.py xapian/_xapian$(PYTHON3_SO)
- PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON3) -O -c 'import _xapian; import xapian'
+ PYTHONPATH="xapian" $(PYTHON3) -O -c 'import _xapian'
+ $(PYTHON3) -O -c 'import xapian'
xapian/_xapian$(PYTHON3_SO): _xapian.la
$(MKDIR_P) xapian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment