Skip to content

Commit

Permalink
Merge ce4fc3b into 2247b23
Browse files Browse the repository at this point in the history
  • Loading branch information
nycholas committed Nov 14, 2020
2 parents 2247b23 + ce4fc3b commit 459fead
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 76 deletions.
15 changes: 13 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
[report]
fail_under = 1
ignore_errors = True
skip_covered = True
exclude_lines =
pragma: no cover
def __repr__
if self.debug:
if settings.DEBUG
raise AssertionError
raise NotImplementedError
raise MissingDependency
except xapian.DatabaseModifiedError
if 0:
if __name__ == .__main__.:

[run]
branch = True
source =
haystack/backends/xapian_backend.py
test_haystack/xapian_tests
omit =
*migrations*
test_haystack/xapian_tests/tests/*
91 changes: 41 additions & 50 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,66 @@ sudo: false
language: python

matrix:
include:
- python: 3.7
env: DJANGO_VERSION=">=2.1,<2.2" XAPIAN_VERSION=1.4.9
dist: xenial
sudo: true
- python: 3.7
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9
dist: xenial
sudo: true
- python: 3.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.4.9
dist: xenial
sudo: true
- python: 3.6
env: DJANGO_VERSION=">=2.1,<2.2" XAPIAN_VERSION=1.4.9
- python: 3.6
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9
- python: 3.6
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.4.9
- python: 3.5
env: DJANGO_VERSION=">=2.1,<2.2" XAPIAN_VERSION=1.4.9
- python: 3.5
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9
- python: 3.5
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.4.9
- python: 3.4
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9
- python: 3.4
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.4.9
- python: 3.4
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.3.6
- python: 3.4
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.3.6
- python: 2.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.4.9
- python: 2.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.3.6
- python: 2.7
env: DJANGO_VERSION=">=1.11,<2.0" XAPIAN_VERSION=1.2.25
include:
- python: 3.8
env: DJANGO_VERSION=">=3.0" XAPIAN_VERSION=1.4.17
dist: xenial
sudo: true
- python: 3.7
env: DJANGO_VERSION=">=3.0" XAPIAN_VERSION=1.4.17
dist: xenial
sudo: true
- python: 3.7
env: DJANGO_VERSION=">=2.1,<2.2" XAPIAN_VERSION=1.4.9
dist: xenial
sudo: true
- python: 3.7
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9
dist: xenial
sudo: true
- python: 3.6
env: DJANGO_VERSION=">=2.1,<2.2" XAPIAN_VERSION=1.4.9
- python: 3.6
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9
- python: 3.5
env: DJANGO_VERSION=">=2.1,<2.2" XAPIAN_VERSION=1.4.9
- python: 3.5
env: DJANGO_VERSION=">=2.0,<2.1" XAPIAN_VERSION=1.4.9

addons:
apt:
sources:
- ubuntu-toolchain-r-test
- ubuntu-toolchain-r-test
packages:
# Xapian requires uuid-dev, Xapian ==1.3.3 requires compilers with c++11.
- uuid-dev
- gcc-4.8
- g++-4.8
# Xapian requires uuid-dev, Xapian ==1.3.3 requires compilers with c++11.
- uuid-dev
- gcc-4.8
- g++-4.8

install:
- pip install -U pip setuptools

# install Xapian
- CXX=g++-4.8 ./install_xapian.sh $XAPIAN_VERSION

- pip install "Django${DJANGO_VERSION}"
- pip install coveralls
- pip install -U "Django${DJANGO_VERSION}" six coveralls

# install Django haystack
- cd .. # move from xapian-haystack
- git clone https://github.com/toastdriven/django-haystack.git

# cp xapian-haystack to django-haystack
- cp xapian-haystack/xapian_backend.py django-haystack/haystack/backends
- cp -r xapian-haystack/tests/* django-haystack/test_haystack/
- cp xapian-haystack/tests/xapian_tests/__init__.py django-haystack/test_haystack/
- cp xapian-haystack/.coveragerc django-haystack/
- cp -rf xapian-haystack/xapian_backend.py django-haystack/haystack/backends
- cp -rf xapian-haystack/tests/* django-haystack/test_haystack/
- cp -rf xapian-haystack/tests/xapian_tests/__init__.py django-haystack/test_haystack/
- cp -rf xapian-haystack/.coveragerc django-haystack/

script:
- cd django-haystack/
- PYTHONPATH=`pwd` `which django-admin.py` makemigrations haystack --settings=test_haystack.xapian_settings
- PYTHONPATH=`pwd` `which django-admin.py` makemigrations core --settings=test_haystack.xapian_settings
- PYTHONPATH=`pwd` `which django-admin.py` makemigrations xapian_tests --settings=test_haystack.xapian_settings
- PYTHONPATH=`pwd` `which django-admin.py` migrate --settings=test_haystack.xapian_settings
- PYTHONPATH=`pwd` coverage run `which django-admin.py` test test_haystack.xapian_tests --settings=test_haystack.xapian_settings

after_success: coveralls
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ The `endswith` search operation is not supported by Xapian-Haystack.
Requirements
------------

- Python 2.7 or 3+
- Django 1.8+
- Python 3.5+
- Django 2.0+
- Django-Haystack 2.5.1
- Xapian 1.2.19+
- Xapian 1.4.0+

In particular, we build-test this backend in `Travis`_ using:

- Python 2.7 and 3.4
- Django 1.8, 1.9 and 1.10
- Python 3.5+
- Django 2.0+ and 3.0+
- Django-Haystack (master)
- Xapian 1.2.19 (Python 2 only), 1.3.3 (both), and 1.4.1 (both)
- Xapian 1.4.9 and 1.4.14


Installation
Expand Down
66 changes: 55 additions & 11 deletions install_xapian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,67 @@
# first argument of the script is Xapian version (e.g. 1.2.19)

VERSION=$1
VIRTUAL_ENV=`realpath $VIRTUAL_ENV`

if [ -z "$VERSION" ]; then
echo "usage: $0 version_number" 1>&2
exit 1
fi

# funcions
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}

# prepare
mkdir -p $VIRTUAL_ENV/packages && cd $VIRTUAL_ENV/packages
mkdir -p $VIRTUAL_ENV/packages

CORE=xapian-core-$VERSION
BINDINGS=xapian-bindings-$VERSION

# download
echo "Downloading source..."
curl -O https://oligarchy.co.uk/xapian/$VERSION/${CORE}.tar.xz
curl -O https://oligarchy.co.uk/xapian/$VERSION/${BINDINGS}.tar.xz
(cd $VIRTUAL_ENV/packages && curl -L -O -C - https://oligarchy.co.uk/xapian/$VERSION/${CORE}.tar.xz)
(cd $VIRTUAL_ENV/packages && curl -L -O -C - https://oligarchy.co.uk/xapian/$VERSION/${BINDINGS}.tar.xz)

# extract
echo "Extracting source..."
tar xf ${CORE}.tar.xz
tar xf ${BINDINGS}.tar.xz
(cd $VIRTUAL_ENV/packages && tar Jxf $VIRTUAL_ENV/packages/${CORE}.tar.xz)
(cd $VIRTUAL_ENV/packages && tar Jxf $VIRTUAL_ENV/packages/${BINDINGS}.tar.xz)

# install
echo "Installing Xapian-core..."
cd $VIRTUAL_ENV/packages/${CORE}
./configure --prefix=$VIRTUAL_ENV && make && make install
(cd $VIRTUAL_ENV/packages/${CORE} \
&& ./configure --prefix=$VIRTUAL_ENV \
&& make \
&& make install)

PYV=`python -c "import sys;t='{v[0]}'.format(v=list(sys.version_info[:1]));sys.stdout.write(t)";`

Expand All @@ -44,17 +79,26 @@ else
fi

# The bindings for Python require python-sphinx
vercomp $VERSION "1.4.11"
case $? in
0) SPHINX_VERSION="<1.7.0";; # =
1) SPHINX_VERSION=">=2.0,<3.0";; # >
2) SPHINX_VERSION="<1.7.0";; # <
esac

echo "Installing Python-Sphinx..."
pip install sphinx
pip install -U "Sphinx${SPHINX_VERSION}"

echo "Installing Xapian-bindings..."
cd $VIRTUAL_ENV/packages/${BINDINGS}
./configure --prefix=$VIRTUAL_ENV $PYTHON_FLAG XAPIAN_CONFIG=$XAPIAN_CONFIG && make && make install
(cd $VIRTUAL_ENV/packages/${BINDINGS} \
&& ./configure --prefix=$VIRTUAL_ENV $PYTHON_FLAG XAPIAN_CONFIG=$XAPIAN_CONFIG \
&& make \
&& make install)

# clean
cd $VIRTUAL_ENV
rm -rf $VIRTUAL_ENV/packages

# test
echo "Testing Xapian..."
python -c "import xapian"
python -c "import xapian" && echo "OK"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Django>=1.8
Django>=2.0
Django-Haystack>=2.5.1
six
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read(fname):

setup(
name='xapian-haystack',
version='2.1.0',
version='3.0.0',
description='A Xapian backend for Haystack',
long_description=read('README.rst'),
classifiers=[
Expand All @@ -23,11 +23,12 @@ def read(fname):
author='Jorge C. Leitão',
author_email='jorgecarleitao@gmail.com',
url='http://github.com/notanumber/xapian-haystack',
download_url='http://github.com/notanumber/xapian-haystack/tarball/2.1.0',
download_url='http://github.com/notanumber/xapian-haystack/tarball/3.0.0',
license='GPL2',
py_modules=['xapian_backend'],
install_requires=[
'django>=1.8',
'django>=2.0',
'django-haystack>=2.5.1',
'six',
]
)
16 changes: 16 additions & 0 deletions tests/xapian_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.messages',
'django.contrib.contenttypes',
'haystack',
'test_haystack.core',
'test_haystack.xapian_tests',
]
Expand All @@ -16,3 +18,17 @@
'INCLUDE_SPELLING': True,
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
]
}
}
]
7 changes: 4 additions & 3 deletions xapian_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import shutil
import sys

from django.utils import six
import six

from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_text
from django.utils.encoding import force_str

from haystack import connections
from haystack.backends import BaseEngine, BaseSearchBackend, BaseSearchQuery, SearchNode, log_query
Expand Down Expand Up @@ -1627,7 +1628,7 @@ def _to_xapian_term(term):
Converts a Python type to a
Xapian term that can be indexed.
"""
return force_text(term).lower()
return force_str(term).lower()


def _from_xapian_value(value, field_type):
Expand Down

0 comments on commit 459fead

Please sign in to comment.