Skip to content

Commit d41c882

Browse files
committed
generate cython
1 parent 09766c3 commit d41c882

File tree

8 files changed

+64
-10
lines changed

8 files changed

+64
-10
lines changed

.github/workflows/pythonbuild.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,30 @@ jobs:
157157
- uses: actions/checkout@v2
158158
with:
159159
submodules: 'true'
160-
161160
- uses: actions/setup-python@v2
162-
name: Install Python
163-
with:
164-
python-version: '3.7'
161+
162+
- name: Install dependencies
163+
run: |
164+
python -m pip install --upgrade pip
165+
pip install pytest hypothesis mypy Cython==3.0.0a10
166+
167+
# The cythonized files allow installation from the sdist without cython
168+
- name: Generate cython
169+
run: |
170+
chmod +x ./src/Levenshtein/generate.sh
171+
./src/Levenshtein/generate.sh
165172
166173
- name: Build sdist
167174
run: |
168-
pip3 install build; python3 -m build --sdist
175+
git apply ./tools/sdist.patch
176+
pip install build
177+
python -m build --sdist
169178
# test whether tarball contains all files required for compiling
170-
pip3 install dist/Levenshtein-*.tar.gz
171-
pip3 uninstall Levenshtein --yes
179+
pip install dist/Levenshtein-*.tar.gz
180+
181+
- name: Test with pytest and backtrace in case of SegFault
182+
run: |
183+
tools/seg_wrapper.sh pytest tests
172184
173185
- uses: actions/upload-artifact@v2
174186
with:

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ endif()
2020

2121
find_package(PythonExtensions REQUIRED)
2222
find_package(Python COMPONENTS Interpreter Development)
23-
find_package(Cython REQUIRED)
2423

2524
find_package(rapidfuzz 1.0.4 QUIET)
2625
if (rapidfuzz_FOUND)

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include src/Levenshtein/**/*.pyi
88
include src/Levenshtein/py.typed
99

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

1313
include extern/rapidfuzz-cpp/LICENSE
1414
include extern/rapidfuzz-cpp/CMakeLists.txt

src/Levenshtein/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

2-
add_cython_target(levenshtein_cpp CXX)
2+
function(create_cython_target _name)
3+
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx)
4+
set(${_name} ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx PARENT_SCOPE)
5+
else()
6+
find_package(Cython REQUIRED)
7+
add_cython_target(${_name} CXX)
8+
set(${_name} ${_name} PARENT_SCOPE)
9+
endif()
10+
endfunction(create_cython_target)
11+
12+
create_cython_target(levenshtein_cpp)
313
add_library(levenshtein_cpp MODULE ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
414
target_compile_features(levenshtein_cpp PUBLIC cxx_std_14)
515
target_include_directories(levenshtein_cpp PRIVATE ${LEV_BASE_DIR}/Levenshtein-c)

src/Levenshtein/generate.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
curdir="${0%/*}"
3+
4+
generate_cython()
5+
{
6+
python -m cython -I "$curdir" --cplus "$curdir"/"$1".pyx -o "$curdir"/"$1".cxx || exit 1
7+
echo "Generated $curdir/$1.cxx"
8+
}
9+
10+
generate_cython levenshtein_cpp

tools/backtrace

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
backtrace
2+
quit

tools/sdist.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/pyproject.toml b/pyproject.toml
2+
index 13a4e16..edb35af 100644
3+
--- a/pyproject.toml
4+
+++ b/pyproject.toml
5+
@@ -3,7 +3,6 @@ requires = [
6+
"setuptools",
7+
"scikit-build>=0.13.0",
8+
"cmake",
9+
- "ninja; platform_system!='Windows'",
10+
- "Cython==3.0.0a10"
11+
+ "ninja; platform_system!='Windows'"
12+
]
13+
build-backend = "setuptools.build_meta"

tools/seg_wrapper.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
3+
4+
ulimit -c unlimited
5+
"$@"
6+
if [[ $? -eq 139 ]]; then
7+
coredumpctl gdb -1 -A "--batch -x $SCRIPTPATH/backtrace"
8+
fi

0 commit comments

Comments
 (0)