Skip to content

Commit

Permalink
generate cython
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Jul 9, 2022
1 parent 09766c3 commit d41c882
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 10 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/pythonbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,30 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'true'

- uses: actions/setup-python@v2
name: Install Python
with:
python-version: '3.7'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest hypothesis mypy Cython==3.0.0a10
# The cythonized files allow installation from the sdist without cython
- name: Generate cython
run: |
chmod +x ./src/Levenshtein/generate.sh
./src/Levenshtein/generate.sh
- name: Build sdist
run: |
pip3 install build; python3 -m build --sdist
git apply ./tools/sdist.patch
pip install build
python -m build --sdist
# test whether tarball contains all files required for compiling
pip3 install dist/Levenshtein-*.tar.gz
pip3 uninstall Levenshtein --yes
pip install dist/Levenshtein-*.tar.gz
- name: Test with pytest and backtrace in case of SegFault
run: |
tools/seg_wrapper.sh pytest tests
- uses: actions/upload-artifact@v2
with:
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ endif()

find_package(PythonExtensions REQUIRED)
find_package(Python COMPONENTS Interpreter Development)
find_package(Cython REQUIRED)

find_package(rapidfuzz 1.0.4 QUIET)
if (rapidfuzz_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include src/Levenshtein/**/*.pyi
include src/Levenshtein/py.typed

recursive-include src/Levenshtein CMakeLists.txt
recursive-include src/Levenshtein *.hpp *.h *.cpp *.pyx *.pxd
recursive-include src/Levenshtein *.hpp *.h *.cpp *.pyx *.pxd *.cxx

include extern/rapidfuzz-cpp/LICENSE
include extern/rapidfuzz-cpp/CMakeLists.txt
Expand Down
12 changes: 11 additions & 1 deletion src/Levenshtein/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@

add_cython_target(levenshtein_cpp CXX)
function(create_cython_target _name)
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx)
set(${_name} ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx PARENT_SCOPE)
else()
find_package(Cython REQUIRED)
add_cython_target(${_name} CXX)
set(${_name} ${_name} PARENT_SCOPE)
endif()
endfunction(create_cython_target)

create_cython_target(levenshtein_cpp)
add_library(levenshtein_cpp MODULE ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
target_compile_features(levenshtein_cpp PUBLIC cxx_std_14)
target_include_directories(levenshtein_cpp PRIVATE ${LEV_BASE_DIR}/Levenshtein-c)
Expand Down
10 changes: 10 additions & 0 deletions src/Levenshtein/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
curdir="${0%/*}"

generate_cython()
{
python -m cython -I "$curdir" --cplus "$curdir"/"$1".pyx -o "$curdir"/"$1".cxx || exit 1
echo "Generated $curdir/$1.cxx"
}

generate_cython levenshtein_cpp
2 changes: 2 additions & 0 deletions tools/backtrace
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
backtrace
quit
13 changes: 13 additions & 0 deletions tools/sdist.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/pyproject.toml b/pyproject.toml
index 13a4e16..edb35af 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -3,7 +3,6 @@ requires = [
"setuptools",
"scikit-build>=0.13.0",
"cmake",
- "ninja; platform_system!='Windows'",
- "Cython==3.0.0a10"
+ "ninja; platform_system!='Windows'"
]
build-backend = "setuptools.build_meta"
8 changes: 8 additions & 0 deletions tools/seg_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

ulimit -c unlimited
"$@"
if [[ $? -eq 139 ]]; then
coredumpctl gdb -1 -A "--batch -x $SCRIPTPATH/backtrace"
fi

0 comments on commit d41c882

Please sign in to comment.