Skip to content

Commit

Permalink
Merge pull request twmht#21 from sileht/sileht/build-fix
Browse files Browse the repository at this point in the history
Allow to compile the extension everywhere
  • Loading branch information
twmht authored Feb 15, 2018
2 parents 1ba2b1a + e4c0de9 commit 272ec9a
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 46 deletions.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/build/
/docs/_build/
build
docs/_build
.pytest_cache
.eggs/
.tox/
*.egg-info/
*.pyc
*.so
__pycache__
rocksdb/_rocksdb.cpp

18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Empty file added docs/_static/.empty
Empty file.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome to python-rocksdb's documentation!
=====================================
==========================================

Overview
--------
Expand Down
27 changes: 20 additions & 7 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -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
----------------

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/tutorial/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Basic Usage of python-rocksdb
************************
*****************************

Open
====
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rocksdb/merge_operators.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
18 changes: 11 additions & 7 deletions rocksdb/tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import shutil
import gc
import unittest
Expand Down Expand Up @@ -89,12 +90,12 @@ def test_write_batch_iter(self):
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))

Expand Down Expand Up @@ -340,10 +341,13 @@ def setUp(self):
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):
Expand Down
2 changes: 1 addition & 1 deletion rocksdb/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_simple(self):
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)
Expand Down
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
41 changes: 16 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@
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',
'-O3',
'-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",
Expand All @@ -45,11 +27,20 @@ def cythonize(extensions): return extensions
author_email="[email protected]",
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 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 272ec9a

Please sign in to comment.