Skip to content

Commit

Permalink
improve build system
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann authored Sep 26, 2022
1 parent 3d3e4b7 commit 4f33992
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 70 deletions.
132 changes: 74 additions & 58 deletions .github/workflows/pythonbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,49 @@ on:
- published

jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- uses: actions/setup-python@v2

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest hypothesis mypy Cython==3.0.0a11
# 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: |
git apply ./tools/sdist.patch
pip install build
python -m build --sdist
# test whether tarball contains all files required for compiling
pip install dist/Levenshtein-*.tar.gz -v
- name: Test type stubs
run: |
python -m mypy.stubtest Levenshtein --ignore-missing-stub
- name: Test with pytest and backtrace in case of SegFault
run: |
tools/seg_wrapper.sh pytest tests
- uses: actions/upload-artifact@v2
with:
path: dist/*.tar.gz

build_wheels_windows:
name: Build wheel on windows-latest/${{matrix.arch}}/${{matrix.python_tag}}
needs: [build_sdist]
runs-on: windows-latest
strategy:
fail-fast: false
Expand All @@ -25,13 +66,6 @@ jobs:
- arch: auto32
python_tag: "pp39-*"

# PyPy Windows is currently broken in scikit-build
- arch: auto64
python_tag: "pp37-*"
- arch: auto64
python_tag: "pp38-*"
- arch: auto64
python_tag: "pp39-*"
env:
CIBW_BUILD: ${{matrix.python_tag}}
CIBW_ARCHS: ${{matrix.arch}}
Expand All @@ -40,15 +74,17 @@ jobs:
CIBW_BUILD_VERBOSITY: 3

steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
submodules: 'true'
name: artifact
path: dist

- uses: actions/setup-python@v2

- name: Build wheels
uses: pypa/cibuildwheel@v2.9.0
uses: pypa/cibuildwheel@v2.10.1
with:
package-dir: dist/*.tar.gz
output-dir: wheelhouse

- name: Upload wheels
Expand All @@ -58,12 +94,13 @@ jobs:

build_wheels_macos:
name: Build wheel on macos-latest/${{matrix.arch}}/${{matrix.python_tag}}
needs: [build_sdist]
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
arch: [x86_64, arm64, universal2]
python_tag: ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*", "cp311-*"]
python_tag: ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*", "cp311-*", "pp37-*", "pp38-*", "pp39-*"]
exclude:
# MacOS Arm only supported since Python 3.8
- arch: arm64
Expand All @@ -74,6 +111,20 @@ jobs:
python_tag: "cp36-*"
- arch: universal2
python_tag: "cp37-*"

# PyPy not supported on MacOS Arm
- arch: arm64
python_tag: "pp37-*"
- arch: arm64
python_tag: "pp38-*"
- arch: arm64
python_tag: "pp39-*"
- arch: universal2
python_tag: "pp37-*"
- arch: universal2
python_tag: "pp38-*"
- arch: universal2
python_tag: "pp39-*"
env:
CIBW_BUILD: ${{matrix.python_tag}}
CIBW_ARCHS: ${{matrix.arch}}
Expand All @@ -83,15 +134,17 @@ jobs:
CIBW_BUILD_VERBOSITY: 3

steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
submodules: 'true'
name: artifact
path: dist

- uses: actions/setup-python@v2

- name: Build wheels
uses: pypa/cibuildwheel@v2.9.0
uses: pypa/cibuildwheel@v2.10.1
with:
package-dir: dist/*.tar.gz
output-dir: wheelhouse

- name: Upload wheels
Expand All @@ -101,6 +154,7 @@ jobs:

build_wheels_linux:
name: Build wheels on ubuntu-latest/${{matrix.arch}}/${{matrix.python_tag}}
needs: [build_sdist]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -130,65 +184,27 @@ jobs:
CIBW_BUILD_VERBOSITY: 3

steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
submodules: 'true'
name: artifact
path: dist

- uses: actions/setup-python@v2

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

- name: Build wheel
uses: pypa/cibuildwheel@v2.9.0
uses: pypa/cibuildwheel@v2.10.1
with:
package-dir: dist/*.tar.gz
output-dir: wheelhouse

- name: Upload wheels
uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'
- uses: actions/setup-python@v2

- 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: |
git apply ./tools/sdist.patch
pip install build
python -m build --sdist
# test whether tarball contains all files required for compiling
pip install dist/Levenshtein-*.tar.gz
- name: Test type stubs
run: |
python -m mypy.stubtest Levenshtein --ignore-missing-stub
- name: Test with pytest and backtrace in case of SegFault
run: |
tools/seg_wrapper.sh pytest tests
- uses: actions/upload-artifact@v2
with:
path: dist/*.tar.gz

deploy-wheels:
if: github.event_name == 'release' && github.event.action == 'published'
needs: [build_wheels_windows, build_wheels_macos, build_wheels_linux, build_sdist]
Expand All @@ -201,7 +217,7 @@ jobs:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@master
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
28 changes: 21 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.12.0)

set(CMAKE_BUILD_TYPE "RelWithDebInfo")
cmake_minimum_required(VERSION 3.12...3.24)

cmake_policy(SET CMP0054 NEW)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(SKBUILD_LINK_LIBRARIES_KEYWORD PRIVATE)
set(Python_FIND_IMPLEMENTATIONS CPython PyPy)

set(THREADS_PREFER_PTHREAD_FLAG ON)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -18,14 +18,28 @@ else()
add_compile_options(-Wall -Wextra -pedantic)
endif()

find_package(PythonExtensions REQUIRED)
find_package(Python COMPONENTS Interpreter Development)
if(CMAKE_VERSION VERSION_LESS 3.18)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
else()
set(Python_ARTIFACTS_INTERACTIVE TRUE)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
endif()

if("${Python_INTERPRETER_ID}" STREQUAL "PyPy")
message(STATUS "PyPy SOABI: ${Python_SOABI}")
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX').split('.')[1])"
OUTPUT_VARIABLE Python_SOABI
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
message(STATUS "Corrected SOABI: ${Python_SOABI}")
endif()

find_package(rapidfuzz 1.0.4 QUIET)
if (rapidfuzz_FOUND)
message("Using system supplied version of rapidfuzz-cpp")
message(STATUS "Using system supplied version of rapidfuzz-cpp")
else()
message("Using packaged version of rapidfuzz-cpp")
message(STATUS "Using packaged version of rapidfuzz-cpp")
add_subdirectory(extern/rapidfuzz-cpp)
endif()

Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### v0.20.4
#### Changed
- modernize cmake build to fix most conda-forge builds

### v0.20.3
#### Changed
- Added support for Python3.11
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include src/Levenshtein/py.typed

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

include extern/rapidfuzz-cpp/LICENSE
include extern/rapidfuzz-cpp/CMakeLists.txt
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Max Bachmann'

# The full version, including alpha/beta/rc tags
release = '0.20.3'
release = '0.20.4'

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="Levenshtein",
version="0.20.3",
version="0.20.4",
url="https://github.com/maxbachmann/Levenshtein",
author="Max Bachmann",
install_requires=["rapidfuzz >= 2.3.0, < 3.0.0"],
Expand Down
3 changes: 1 addition & 2 deletions src/Levenshtein/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ endif()
endfunction(create_cython_target)

create_cython_target(levenshtein_cpp)
add_library(levenshtein_cpp MODULE ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
Python_add_library(levenshtein_cpp MODULE WITH_SOABI ${levenshtein_cpp} ${LEV_BASE_DIR}/Levenshtein-c/_levenshtein.cpp)
target_compile_features(levenshtein_cpp PUBLIC cxx_std_17)
target_include_directories(levenshtein_cpp PRIVATE ${LEV_BASE_DIR}/Levenshtein-c)
target_link_libraries(levenshtein_cpp PRIVATE rapidfuzz::rapidfuzz)
python_extension_module(levenshtein_cpp)
install(TARGETS levenshtein_cpp LIBRARY DESTINATION src/Levenshtein)
2 changes: 1 addition & 1 deletion src/Levenshtein/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__author__: str = "Max Bachmann"
__license__: str = "GPL"
__version__: str = "0.20.3"
__version__: str = "0.20.4"

from rapidfuzz.distance.Levenshtein import distance
from rapidfuzz.distance.Indel import normalized_similarity as ratio
Expand Down

0 comments on commit 4f33992

Please sign in to comment.