Skip to content

Commit

Permalink
Merge a64a7e9 into b64feaf
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrik Muhs committed Jan 12, 2018
2 parents b64feaf + a64a7e9 commit 80167ea
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 40 deletions.
10 changes: 8 additions & 2 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
keyvi.egg-info/
build/
dist/
__pycache__/
*.py[cod]
*.so
*.egg-info
MANIFEST
.cache

# autowrap artifacts
keyvi.pyx
keyvi.cpp
_core.pyx
_core.cpp
28 changes: 14 additions & 14 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
recursive-include autowrap_includes *.hpp
graft src
include keyvi.cpp
include _core.cpp

recursive-include keyvi/bin *.cpp
recursive-include keyvi/include/keyvi *.h
recursive-include src/cpp/keyvi/bin *.cpp
recursive-include src/cpp/keyvi/include/keyvi *.h

recursive-include keyvi/3rdparty *.h
recursive-include keyvi/3rdparty *.inl
recursive-include keyvi/3rdparty *.hpp
recursive-include keyvi/3rdparty *.cpp
recursive-include keyvi/3rdparty *.cpp.in
recursive-include src/cpp/keyvi/3rdparty *.h
recursive-include src/cpp/keyvi/3rdparty *.inl
recursive-include src/cpp/keyvi/3rdparty *.hpp
recursive-include src/cpp/keyvi/3rdparty *.cpp
recursive-include src/cpp/keyvi/3rdparty *.cpp.in

recursive-include keyvi/3rdparty CMakeLists.txt
recursive-include keyvi/3rdparty *.cmake
recursive-include keyvi/3rdparty *.cmake.in
recursive-include src/cpp/keyvi/3rdparty CMakeLists.txt
recursive-include src/cpp/keyvi/3rdparty *.cmake
recursive-include src/cpp/keyvi/3rdparty *.cmake.in

recursive-include keyvi/3rdparty/tpie *.md
graft keyvi/3rdparty/tpie/doc
include CMakeLists.txt
recursive-include src/cpp/keyvi/3rdparty/tpie *.md
graft src/cpp/keyvi/3rdparty/tpie/doc
include src/cpp/CMakeLists.txt
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Then build/install a python package:

## Develop

The python binding uses [cython](http://cython.org/) and [autowrap](https://github.com/uweschmitt/autowrap). All source files can be found in the src folder. The files keyvi.cpp and keyvi.pyx are generated on the fly during build.
The python binding uses [cython](http://cython.org/) and [autowrap](https://github.com/uweschmitt/autowrap). All source files can be found in the src folder. The files _core.cpp and _core.pyx are generated on the fly during build.
43 changes: 24 additions & 19 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
from contextlib import contextmanager
from os import path

pykeyvi_pyx = 'keyvi.pyx'
pykeyvi_cpp = 'keyvi.cpp'
pykeyvi_pyx = '_core.pyx'
pykeyvi_cpp = '_core.cpp'
keyvi_cpp_source = '../keyvi'
keyvi_cpp = 'src/cpp'
keyvi_cpp_link = path.join(keyvi_cpp, 'keyvi')

try:
cpu_count = multiprocessing.cpu_count()
Expand All @@ -36,14 +39,16 @@ def generate_pykeyvi_source():

@contextmanager
def symlink_keyvi():
if not path.exists('keyvi'):
os.symlink('../keyvi', 'keyvi')
shutil.copy('../CMakeLists.txt', 'CMakeLists.txt')
keyvi_source_path = os.path.realpath(os.path.join(os.getcwd(), "../keyvi"))
pykeyvi_source_path = os.path.join(os.getcwd(),"keyvi")
if not path.exists(keyvi_cpp_link):
if not path.exists(keyvi_cpp):
os.makedirs(keyvi_cpp)
os.symlink(path.abspath(keyvi_cpp_source), keyvi_cpp_link)
shutil.copy('../CMakeLists.txt', path.join(keyvi_cpp, 'CMakeLists.txt'))
keyvi_source_path = os.path.realpath(os.path.join(os.getcwd(), keyvi_cpp_source))
pykeyvi_source_path = os.path.join(os.getcwd(), keyvi_cpp_link)
yield (pykeyvi_source_path, keyvi_source_path)
os.unlink('keyvi')
os.remove('CMakeLists.txt')
os.unlink(keyvi_cpp_link)
os.remove(path.join(keyvi_cpp, 'CMakeLists.txt'))
else:
yield None, None

Expand All @@ -52,8 +57,8 @@ def symlink_keyvi():
# workaround for autowrap bug (includes incompatible boost)
autowrap_data_dir = "autowrap_includes"

dictionary_sources = path.abspath('keyvi')
keyvi_build_dir = path.join('keyvi-build')
dictionary_sources = path.abspath(keyvi_cpp_link)
keyvi_build_dir = path.join(keyvi_cpp, 'build')
keyvi_install_prefix = 'install'
keyvi_lib_dir = path.join(keyvi_build_dir, keyvi_install_prefix, 'lib')

Expand All @@ -67,7 +72,6 @@ def symlink_keyvi():
if pykeyvi_source_path is not None:
additional_compile_flags.append('-fdebug-prefix-map={}={}'.format(pykeyvi_source_path, keyvi_source_path))


linklibraries_static_or_dynamic = [
"boost_program_options",
"boost_iostreams",
Expand Down Expand Up @@ -113,7 +117,6 @@ def symlink_keyvi():
"zlib installation root"),
]


class custom_opts:

parent = None
Expand Down Expand Up @@ -186,13 +189,12 @@ def run(self):

self.parent.run(self)


class build(custom_opts, _build.build):
parent = _build.build
user_options = _build.build.user_options + custom_user_options


class sdist(_sdist.sdist):

def run(self):
generate_pykeyvi_source()
_sdist.sdist.run(self)
Expand All @@ -204,13 +206,16 @@ class bdist(custom_opts, _bdist.bdist):
have_wheel = False
try:
import wheel.bdist_wheel as _bdist_wheel

class bdist_wheel(custom_opts, _bdist_wheel.bdist_wheel):
parent = _bdist_wheel.bdist_wheel
user_options = _bdist_wheel.bdist_wheel.user_options + custom_user_options

have_wheel = True
except: None

class build_ext(_build_ext.build_ext):

def run(self):
generate_pykeyvi_source()

Expand Down Expand Up @@ -246,11 +251,10 @@ def run(self):
os.environ['ARCHFLAGS'] = '-arch x86_64'
_build_ext.build_ext.run(self)


ext_modules = [Extension('keyvi',
ext_modules = [Extension('keyvi._core',
include_dirs=[autowrap_data_dir,
path.join(dictionary_sources, '3rdparty/tpie'),
path.join(os.path.join(keyvi_build_dir,'keyvi/3rdparty/tpie')),
path.join(os.path.join(keyvi_build_dir, 'keyvi/3rdparty/tpie')),
path.join(dictionary_sources, 'include/keyvi'),
path.join(dictionary_sources, '3rdparty/rapidjson/include'),
path.join(dictionary_sources, '3rdparty/msgpack-c/include'),
Expand Down Expand Up @@ -286,7 +290,8 @@ def run(self):
license="ASL 2.0",
cmdclass=commands,
scripts=['bin/keyvi'],
packages=['keyvicli'],
packages=['keyvi', 'keyvicli'],
package_dir = {'': 'src/py'},
ext_modules=ext_modules,
zip_safe=False,
url='http://keyvi.org',
Expand Down
2 changes: 2 additions & 0 deletions python/src/py/keyvi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from keyvi._core import *
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions travis/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ coveralls -r . -b build/ -i keyvi \

# workaround for coverage measurement: symlink keyvi
cd python/
ln -s ../keyvi keyvi
ln -s ../../../keyvi src/cpp/keyvi
cd ..

coveralls -r . -b python/ -i python \
--gcov /usr/bin/gcov-4.8 --gcov-options '\-lp' \
-e python/keyvi/3rdparty -e build \
-e python/src/cpp/keyvi/3rdparty -e build \
-E '.*/autowrap_includes/autowrap_tools.hpp' \
-E '.*/src/extra/attributes_converter.h' \
-E '.*/keyvi.cpp' \
-E '.*/_core.cpp' \
--dump python.cov_report_tmp > /dev/null

# workaround: remove 'python' from source path before merge
sed s/"python\/keyvi"/"keyvi"/g python.cov_report_tmp > python.cov_report
sed s/"python\/src\/cpp\/keyvi"/"keyvi"/g python.cov_report_tmp > python.cov_report

export COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN}

Expand Down

0 comments on commit 80167ea

Please sign in to comment.