diff --git a/.github/workflows/pythonbuild.yml b/.github/workflows/pythonbuild.yml index 2aa9ff0..36aeb4e 100644 --- a/.github/workflows/pythonbuild.yml +++ b/.github/workflows/pythonbuild.yml @@ -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 @@ -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}} @@ -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 @@ -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 @@ -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}} @@ -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 @@ -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 @@ -130,9 +184,10 @@ 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 @@ -140,8 +195,9 @@ jobs: 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 @@ -149,46 +205,6 @@ jobs: 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] @@ -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 }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cae31a..1a526a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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() diff --git a/HISTORY.md b/HISTORY.md index 3e11ad1..d5afe20 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in index e28b5c6..4bf6c43 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/docs/conf.py b/docs/conf.py index db99811..b9378c8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 --------------------------------------------------- diff --git a/setup.py b/setup.py index 447277e..1be10d4 100644 --- a/setup.py +++ b/setup.py @@ -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"], diff --git a/src/Levenshtein/CMakeLists.txt b/src/Levenshtein/CMakeLists.txt index 134956f..c7c1ae7 100644 --- a/src/Levenshtein/CMakeLists.txt +++ b/src/Levenshtein/CMakeLists.txt @@ -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) diff --git a/src/Levenshtein/__init__.py b/src/Levenshtein/__init__.py index d8af4a1..cc5b93b 100644 --- a/src/Levenshtein/__init__.py +++ b/src/Levenshtein/__init__.py @@ -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