Allow to compile the extension everywhere

This change:
* uses to setuptools Cython automatic extension build system.
* Add tox.ini to run tests and build docs into virtualenv
* Add .travis.yaml and Dockerfile to run tests in CI
* Change requirements to ensure:
  - Cython and setuptools are installed before we build the Cython
    extension
  - tests dependencies are not installed by default
  - doc dependencies are explicit
* Add missing lz4 library
* Allow to build the module with any librocksdb headers (no-rtti)

Closes #15
This commit is contained in:
Mehdi Abaakouk 2018-02-09 06:37:09 +01:00
parent 1ba2b1acc2
commit e4c0de9455
13 changed files with 141 additions and 46 deletions

13
.gitignore vendored
View file

@ -1,2 +1,11 @@
/build/
/docs/_build/
build
docs/_build
.pytest_cache
.eggs/
.tox/
*.egg-info/
*.pyc
*.so
__pycache__
rocksdb/_rocksdb.cpp

18
.travis.yml Normal file
View file

@ -0,0 +1,18 @@
sudo: required
dist: trusty
language: generic
services:
- docker
cache:
directories:
- ~/.cache/pip
install:
docker build . -t ci-image;
script:
docker run -v ~/.cache/pip:/home/tester/.cache/pip -v $(pwd):/home/tester/src ci-image:latest tox -e ${TOXENV} ;
env:
- TOXENV=py27
- TOXENV=py36
- TOXENV=docs

33
Dockerfile Normal file
View file

@ -0,0 +1,33 @@
FROM ubuntu:18.04
ENV SRC /home/tester/src
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -y && apt-get install -qy \
locales \
git \
wget \
python \
python3 \
python-dev \
python3-dev \
python-pip \
librocksdb-dev \
libsnappy-dev \
zlib1g-dev \
libbz2-dev \
liblz4-dev \
&& rm -rf /var/lib/apt/lists/*
#NOTE(sileht): really no utf-8 in 2017 !?
ENV LANG en_US.UTF-8
RUN update-locale
RUN locale-gen $LANG
#NOTE(sileht): Upgrade python dev tools
RUN pip install -U pip tox virtualenv
RUN groupadd --gid 2000 tester
RUN useradd --uid 2000 --gid 2000 --create-home --shell /bin/bash tester
USER tester
WORKDIR $SRC

0
docs/_static/.empty vendored Normal file
View file

View file

@ -1,5 +1,5 @@
Welcome to python-rocksdb's documentation!
=====================================
==========================================
Overview
--------

View file

@ -1,8 +1,23 @@
Installing
**********
==========
.. highlight:: bash
With distro package and pypi
****************************
This requires librocksdb-dev>=5.0
.. code-block:: bash
apt-get install python-virtualenv python-dev librocksdb-dev
virtualenv venv
source venv/bin/activate
pip install pythin-rocksdb
From source
***********
Building rocksdb
----------------
@ -42,13 +57,11 @@ These varialbes are picked up by the compiler, linker and loader
export LIBRARY_PATH=${LIBRARY_PATH}:`pwd`
Building python-rocksdb
------------------
-----------------------
.. code-block:: bash
apt-get install python-virtualenv python-dev
virtualenv pyrocks_test
cd pyrocks_test
. bin/activate
pip install "Cython>=0.20"
pip install git+git://github.com/twmht/python-rocksdb.git
virtualenv venv
source venv/bin/activate
pip install git+git://github.com/twmht/python-rocksdb.git#egg=python-rocksdb

View file

@ -1,5 +1,5 @@
Basic Usage of python-rocksdb
************************
*****************************
Open
====
@ -32,7 +32,7 @@ It assings a cache of 2.5G, uses a bloom filter for faster lookups and keeps
more data (64 MB) in memory before writting a .sst file.
About Bytes And Unicode
========================
=======================
RocksDB stores all data as uninterpreted *byte strings*.
pyrocksdb behaves the same and uses nearly everywhere byte strings too.

View file

@ -1,5 +1,5 @@
import struct as py_struct
from interfaces import AssociativeMergeOperator
from rocksdb.interfaces import AssociativeMergeOperator
class UintAddOperator(AssociativeMergeOperator):
def merge(self, key, existing_value, value):

View file

@ -1,4 +1,5 @@
import os
import sys
import shutil
import gc
import unittest
@ -89,12 +90,12 @@ class TestDB(unittest.TestCase, TestHelper):
it = iter(batch)
del batch
ref = [
('Put', 'key1', 'v1'),
('Put', 'key2', 'v2'),
('Put', 'key3', 'v3'),
('Delete', 'a', ''),
('Delete', 'key1', ''),
('Merge', 'xxx', 'value')
('Put', b'key1', b'v1'),
('Put', b'key2', b'v2'),
('Put', b'key3', b'v3'),
('Delete', b'a', b''),
('Delete', b'key1', b''),
('Merge', b'xxx', b'value')
]
self.assertEqual(ref, list(it))
@ -340,10 +341,13 @@ class TestStringAppendOperatorMerge(unittest.TestCase, TestHelper):
def tearDown(self):
self._close_db()
# NOTE(sileht): Raise "Corruption: Error: Could not perform merge." on PY3
@unittest.skipIf(sys.version_info[0] == 3,
"Unexpected behavior on PY3")
def test_merge(self):
self.db.put(b'a', b'ccc')
self.db.merge(b'a', b'ddd')
self.assertEqual(self.db.get(b'a'), 'ccc,ddd')
self.assertEqual(self.db.get(b'a'), b'ccc,ddd')
# class TestStringMaxOperatorMerge(unittest.TestCase, TestHelper):
# def setUp(self):

View file

@ -93,7 +93,7 @@ class TestOptions(unittest.TestCase):
opts.comparator,
rocksdb.BytewiseComparator)
self.assertEqual(rocksdb.CompressionType.no_compression, opts.compression)
self.assertEqual(rocksdb.CompressionType.snappy_compression, opts.compression)
opts.compression = rocksdb.CompressionType.zstd_compression
self.assertEqual(rocksdb.CompressionType.zstd_compression, opts.compression)

View file

@ -1,2 +1,10 @@
[build_sphinx]
source-dir = docs
build-dir = docs/_build
all_files = 1
[upload_sphinx]
upload-dir = docs/_build/html
[aliases]
test=pytest

View file

@ -1,15 +1,8 @@
import platform
from setuptools import setup
from setuptools import find_packages
from distutils.extension import Extension
from setuptools import Extension
try:
from Cython.Build import cythonize
except ImportError:
def cythonize(extensions): return extensions
sources = ['rocksdb/_rocksdb.cpp']
else:
sources = ['rocksdb/_rocksdb.pyx']
extra_compile_args = [
'-std=c++11',
@ -17,24 +10,13 @@ extra_compile_args = [
'-Wall',
'-Wextra',
'-Wconversion',
'-fno-strict-aliasing'
'-fno-strict-aliasing',
'-fno-rtti',
]
if platform.system() == 'Darwin':
extra_compile_args += ['-mmacosx-version-min=10.7', '-stdlib=libc++']
mod1 = Extension(
'rocksdb._rocksdb',
sources,
extra_compile_args=extra_compile_args,
language='c++',
libraries=[
'rocksdb',
'snappy',
'bz2',
'z'
]
)
setup(
name="python-rocksdb",
@ -45,11 +27,20 @@ setup(
author_email="qrnnis2623891@gmail.com",
url="https://github.com/twmht/python-rocksdb",
license='BSD License',
install_requires=['setuptools'],
setup_requires=['setuptools>=25', 'Cython>=0.20'],
install_requires=['setuptools>=25'],
package_dir={'rocksdb': 'rocksdb'},
packages=find_packages('.'),
ext_modules=cythonize([mod1]),
setup_requires=['pytest-runner'],
tests_require=['pytest'],
ext_modules=[Extension(
'rocksdb._rocksdb',
['rocksdb/_rocksdb.pyx'],
extra_compile_args=extra_compile_args,
language='c++',
libraries=['rocksdb', 'snappy', 'bz2', 'z', 'lz4'],
)],
extras_require={
"doc": ['sphinx_rtd_theme', 'sphinx'],
"test": ['pytest'],
},
include_package_data=True
)

19
tox.ini Normal file
View file

@ -0,0 +1,19 @@
[tox]
envlist = py27,py35,py36
minversion = 2.0
skipsdist = True
[testenv]
skip_install = True
deps =
-e
.[test]
commands = pytest {posargs:rocksdb/tests}
[testenv:docs]
deps = .[doc]
commands = python setup.py build_sphinx -W
[pytest]
addopts = --verbose
norecursedirs = .tox