Skip to content

Commit 4f33992

Browse files
authored
improve build system
1 parent 3d3e4b7 commit 4f33992

File tree

8 files changed

+104
-70
lines changed

8 files changed

+104
-70
lines changed

.github/workflows/pythonbuild.yml

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,49 @@ on:
88
- published
99

1010
jobs:
11+
build_sdist:
12+
name: Build source distribution
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
submodules: 'true'
18+
- uses: actions/setup-python@v2
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install pytest hypothesis mypy Cython==3.0.0a11
24+
25+
# The cythonized files allow installation from the sdist without cython
26+
- name: Generate cython
27+
run: |
28+
chmod +x ./src/Levenshtein/generate.sh
29+
./src/Levenshtein/generate.sh
30+
31+
- name: Build sdist
32+
run: |
33+
git apply ./tools/sdist.patch
34+
pip install build
35+
python -m build --sdist
36+
# test whether tarball contains all files required for compiling
37+
pip install dist/Levenshtein-*.tar.gz -v
38+
39+
- name: Test type stubs
40+
run: |
41+
python -m mypy.stubtest Levenshtein --ignore-missing-stub
42+
43+
- name: Test with pytest and backtrace in case of SegFault
44+
run: |
45+
tools/seg_wrapper.sh pytest tests
46+
47+
- uses: actions/upload-artifact@v2
48+
with:
49+
path: dist/*.tar.gz
50+
1151
build_wheels_windows:
1252
name: Build wheel on windows-latest/${{matrix.arch}}/${{matrix.python_tag}}
53+
needs: [build_sdist]
1354
runs-on: windows-latest
1455
strategy:
1556
fail-fast: false
@@ -25,13 +66,6 @@ jobs:
2566
- arch: auto32
2667
python_tag: "pp39-*"
2768

28-
# PyPy Windows is currently broken in scikit-build
29-
- arch: auto64
30-
python_tag: "pp37-*"
31-
- arch: auto64
32-
python_tag: "pp38-*"
33-
- arch: auto64
34-
python_tag: "pp39-*"
3569
env:
3670
CIBW_BUILD: ${{matrix.python_tag}}
3771
CIBW_ARCHS: ${{matrix.arch}}
@@ -40,15 +74,17 @@ jobs:
4074
CIBW_BUILD_VERBOSITY: 3
4175

4276
steps:
43-
- uses: actions/checkout@v2
77+
- uses: actions/download-artifact@v2
4478
with:
45-
submodules: 'true'
79+
name: artifact
80+
path: dist
4681

4782
- uses: actions/setup-python@v2
4883

4984
- name: Build wheels
50-
uses: pypa/cibuildwheel@v2.9.0
85+
uses: pypa/cibuildwheel@v2.10.1
5186
with:
87+
package-dir: dist/*.tar.gz
5288
output-dir: wheelhouse
5389

5490
- name: Upload wheels
@@ -58,12 +94,13 @@ jobs:
5894

5995
build_wheels_macos:
6096
name: Build wheel on macos-latest/${{matrix.arch}}/${{matrix.python_tag}}
97+
needs: [build_sdist]
6198
runs-on: macos-latest
6299
strategy:
63100
fail-fast: false
64101
matrix:
65102
arch: [x86_64, arm64, universal2]
66-
python_tag: ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*", "cp311-*"]
103+
python_tag: ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*", "cp311-*", "pp37-*", "pp38-*", "pp39-*"]
67104
exclude:
68105
# MacOS Arm only supported since Python 3.8
69106
- arch: arm64
@@ -74,6 +111,20 @@ jobs:
74111
python_tag: "cp36-*"
75112
- arch: universal2
76113
python_tag: "cp37-*"
114+
115+
# PyPy not supported on MacOS Arm
116+
- arch: arm64
117+
python_tag: "pp37-*"
118+
- arch: arm64
119+
python_tag: "pp38-*"
120+
- arch: arm64
121+
python_tag: "pp39-*"
122+
- arch: universal2
123+
python_tag: "pp37-*"
124+
- arch: universal2
125+
python_tag: "pp38-*"
126+
- arch: universal2
127+
python_tag: "pp39-*"
77128
env:
78129
CIBW_BUILD: ${{matrix.python_tag}}
79130
CIBW_ARCHS: ${{matrix.arch}}
@@ -83,15 +134,17 @@ jobs:
83134
CIBW_BUILD_VERBOSITY: 3
84135

85136
steps:
86-
- uses: actions/checkout@v2
137+
- uses: actions/download-artifact@v2
87138
with:
88-
submodules: 'true'
139+
name: artifact
140+
path: dist
89141

90142
- uses: actions/setup-python@v2
91143

92144
- name: Build wheels
93-
uses: pypa/cibuildwheel@v2.9.0
145+
uses: pypa/cibuildwheel@v2.10.1
94146
with:
147+
package-dir: dist/*.tar.gz
95148
output-dir: wheelhouse
96149

97150
- name: Upload wheels
@@ -101,6 +154,7 @@ jobs:
101154

102155
build_wheels_linux:
103156
name: Build wheels on ubuntu-latest/${{matrix.arch}}/${{matrix.python_tag}}
157+
needs: [build_sdist]
104158
runs-on: ubuntu-latest
105159
strategy:
106160
fail-fast: false
@@ -130,65 +184,27 @@ jobs:
130184
CIBW_BUILD_VERBOSITY: 3
131185

132186
steps:
133-
- uses: actions/checkout@v2
187+
- uses: actions/download-artifact@v2
134188
with:
135-
submodules: 'true'
189+
name: artifact
190+
path: dist
136191

137192
- uses: actions/setup-python@v2
138193

139194
- uses: docker/setup-qemu-action@v1
140195
name: Set up QEMU
141196

142197
- name: Build wheel
143-
uses: pypa/cibuildwheel@v2.9.0
198+
uses: pypa/cibuildwheel@v2.10.1
144199
with:
200+
package-dir: dist/*.tar.gz
145201
output-dir: wheelhouse
146202

147203
- name: Upload wheels
148204
uses: actions/upload-artifact@v2
149205
with:
150206
path: ./wheelhouse/*.whl
151207

152-
build_sdist:
153-
name: Build source distribution
154-
runs-on: ubuntu-latest
155-
steps:
156-
- uses: actions/checkout@v2
157-
with:
158-
submodules: 'true'
159-
- uses: actions/setup-python@v2
160-
161-
- name: Install dependencies
162-
run: |
163-
python -m pip install --upgrade pip
164-
pip install pytest hypothesis mypy Cython==3.0.0a10
165-
166-
# The cythonized files allow installation from the sdist without cython
167-
- name: Generate cython
168-
run: |
169-
chmod +x ./src/Levenshtein/generate.sh
170-
./src/Levenshtein/generate.sh
171-
172-
- name: Build sdist
173-
run: |
174-
git apply ./tools/sdist.patch
175-
pip install build
176-
python -m build --sdist
177-
# test whether tarball contains all files required for compiling
178-
pip install dist/Levenshtein-*.tar.gz
179-
180-
- name: Test type stubs
181-
run: |
182-
python -m mypy.stubtest Levenshtein --ignore-missing-stub
183-
184-
- name: Test with pytest and backtrace in case of SegFault
185-
run: |
186-
tools/seg_wrapper.sh pytest tests
187-
188-
- uses: actions/upload-artifact@v2
189-
with:
190-
path: dist/*.tar.gz
191-
192208
deploy-wheels:
193209
if: github.event_name == 'release' && github.event.action == 'published'
194210
needs: [build_wheels_windows, build_wheels_macos, build_wheels_linux, build_sdist]
@@ -201,7 +217,7 @@ jobs:
201217
name: artifact
202218
path: dist
203219

204-
- uses: pypa/gh-action-pypi-publish@master
220+
- uses: pypa/gh-action-pypi-publish@release/v1
205221
with:
206222
user: __token__
207223
password: ${{ secrets.pypi_password }}

CMakeLists.txt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
cmake_minimum_required(VERSION 3.12.0)
2-
3-
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
1+
cmake_minimum_required(VERSION 3.12...3.24)
42

53
cmake_policy(SET CMP0054 NEW)
4+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
65
set(SKBUILD_LINK_LIBRARIES_KEYWORD PRIVATE)
6+
set(Python_FIND_IMPLEMENTATIONS CPython PyPy)
77

88
set(THREADS_PREFER_PTHREAD_FLAG ON)
99
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -18,14 +18,28 @@ else()
1818
add_compile_options(-Wall -Wextra -pedantic)
1919
endif()
2020

21-
find_package(PythonExtensions REQUIRED)
22-
find_package(Python COMPONENTS Interpreter Development)
21+
if(CMAKE_VERSION VERSION_LESS 3.18)
22+
find_package(Python COMPONENTS Interpreter Development REQUIRED)
23+
else()
24+
set(Python_ARTIFACTS_INTERACTIVE TRUE)
25+
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
26+
endif()
27+
28+
if("${Python_INTERPRETER_ID}" STREQUAL "PyPy")
29+
message(STATUS "PyPy SOABI: ${Python_SOABI}")
30+
execute_process(
31+
COMMAND "${Python_EXECUTABLE}" -c
32+
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX').split('.')[1])"
33+
OUTPUT_VARIABLE Python_SOABI
34+
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
35+
message(STATUS "Corrected SOABI: ${Python_SOABI}")
36+
endif()
2337

2438
find_package(rapidfuzz 1.0.4 QUIET)
2539
if (rapidfuzz_FOUND)
26-
message("Using system supplied version of rapidfuzz-cpp")
40+
message(STATUS "Using system supplied version of rapidfuzz-cpp")
2741
else()
28-
message("Using packaged version of rapidfuzz-cpp")
42+
message(STATUS "Using packaged version of rapidfuzz-cpp")
2943
add_subdirectory(extern/rapidfuzz-cpp)
3044
endif()
3145

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### v0.20.4
4+
#### Changed
5+
- modernize cmake build to fix most conda-forge builds
6+
37
### v0.20.3
48
#### Changed
59
- Added support for Python3.11

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ include src/Levenshtein/py.typed
99

1010
recursive-include src/Levenshtein CMakeLists.txt
1111
recursive-include src/Levenshtein *.hpp *.h *.cpp *.pyx *.pxd *.cxx *.pyi
12+
recursive-include tests *
1213

1314
include extern/rapidfuzz-cpp/LICENSE
1415
include extern/rapidfuzz-cpp/CMakeLists.txt

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Max Bachmann'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '0.20.3'
25+
release = '0.20.4'
2626

2727
# -- General configuration ---------------------------------------------------
2828

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="Levenshtein",
8-
version="0.20.3",
8+
version="0.20.4",
99
url="https://github.com/maxbachmann/Levenshtein",
1010
author="Max Bachmann",
1111
install_requires=["rapidfuzz >= 2.3.0, < 3.0.0"],

src/Levenshtein/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ endif()
1010
endfunction(create_cython_target)
1111

1212
create_cython_target(levenshtein_cpp)
13-
add_library(levenshtein_cpp MODULE ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
13+
Python_add_library(levenshtein_cpp MODULE WITH_SOABI ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
1414
target_compile_features(levenshtein_cpp PUBLIC cxx_std_17)
1515
target_include_directories(levenshtein_cpp PRIVATE ${LEV_BASE_DIR}/Levenshtein-c)
1616
target_link_libraries(levenshtein_cpp PRIVATE rapidfuzz::rapidfuzz)
17-
python_extension_module(levenshtein_cpp)
1817
install(TARGETS levenshtein_cpp LIBRARY DESTINATION src/Levenshtein)

src/Levenshtein/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
__author__: str = "Max Bachmann"
1818
__license__: str = "GPL"
19-
__version__: str = "0.20.3"
19+
__version__: str = "0.20.4"
2020

2121
from rapidfuzz.distance.Levenshtein import distance
2222
from rapidfuzz.distance.Indel import normalized_similarity as ratio

0 commit comments

Comments
 (0)