From 87e0f00a851ebd03f0023b5a916f2d73dc7da128 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 22:14:27 +0200 Subject: [PATCH 1/9] update workflow --- .github/workflows/build_and_upload_wheels.yml | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build_and_upload_wheels.yml b/.github/workflows/build_and_upload_wheels.yml index 389169c..2ada777 100644 --- a/.github/workflows/build_and_upload_wheels.yml +++ b/.github/workflows/build_and_upload_wheels.yml @@ -6,26 +6,33 @@ on: pull_request: jobs: - macos_wheel: - runs-on: macos-latest - strategy: - matrix: - arch: [x86_64, arm64] - cw_build: ["pp*", "cp*"] - exclude: - - arch: arm64 - cw_build: "pp*" + macos_wheel_m: + runs-on: macos-14 steps: - uses: actions/checkout@v3 with: submodules: recursive - name: build wheels - uses: pypa/cibuildwheel@v2.16.2 + uses: pypa/cibuildwheel@v2.19 env: - CIBW_ARCHS: ${{ matrix.arch }} - CIBW_BUILD: ${{ matrix.cw_build }} - CIBW_TEST_SKIP: "*-macosx_arm64" + CIBW_ARCHS: "arm64" + + - uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + macos_wheel_intel: + runs-on: macos-13 + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: build wheels + uses: pypa/cibuildwheel@v2.19 + env: + CIBW_ARCHS: "x86_64" - uses: actions/upload-artifact@v3 with: @@ -45,7 +52,7 @@ jobs: with: submodules: recursive - name: build wheels - uses: pypa/cibuildwheel@v2.16.2 + uses: pypa/cibuildwheel@v2.19 env: CIBW_ARCHS: ${{ matrix.arch }} CIBW_BUILD: ${{ matrix.cw_build }} @@ -103,7 +110,7 @@ jobs: with: submodules: recursive - name: build wheels - uses: pypa/cibuildwheel@v2.16.2 + uses: pypa/cibuildwheel@v2.19 env: CIBW_ARCHS: ${{ matrix.arch }} From 2bd75f1ac0a84268fdb792fb7d9225296cc21574 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 23:14:59 +0200 Subject: [PATCH 2/9] update pre-commit --- .pre-commit-config.yaml | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7420977..1e31652 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,11 +9,9 @@ ci: autoupdate_schedule: "monthly" submodules: false -exclude: "third_party/nanoflann.hpp" - repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.5.0" + rev: "v4.6.0" hooks: - id: check-added-large-files - id: check-case-conflict @@ -28,31 +26,20 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace -- repo: https://github.com/asottile/pyupgrade - rev: "v3.15.0" - hooks: - - id: pyupgrade - args: [--py36-plus] - -- repo: https://github.com/PyCQA/isort - rev: "5.12.0" - hooks: - - id: isort - -- repo: https://github.com/psf/black - rev: "23.10.1" +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.5 hooks: - - id: black - args: [--line-length=79] + - id: clang-format + types_or: [c, c++] -- repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 +- repo: https://github.com/cheshirekow/cmake-format-precommit + rev: "v0.6.13" hooks: - - id: flake8 - args: [--extend-ignore=E203] + - id: cmake-format -- repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.4 +- repo: https://github.com/codespell-project/codespell + rev: v2.2.6 hooks: - - id: clang-format - types_or: [c++] + - id: codespell + args: [-w] + additional_dependencies: [tomli] From 1e6c716bc64b08e3fd13f4c97562403ced28e07c Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 23:15:12 +0200 Subject: [PATCH 3/9] update cmake --- CMakeLists.txt | 88 +++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b69a0d8..d4660b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,15 @@ -cmake_minimum_required(VERSION 3.12) -project(funi VERSION 0.0.0 LANGUAGES CXX) +cmake_minimum_required(VERSION 3.17) +project( + funi + VERSION 0.1.0 + LANGUAGES CXX) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + endif() # options - default is header only -option(FUNI_PYTHON "add python ext header" ON) +option(FUNI_BUILD_PYTHON "build python" ON) # config set(exe_dest "bin") @@ -20,51 +24,53 @@ set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") set(namespace "${PROJECT_NAME}::") # sources -set(CXX_HEADERS src/funi.hpp) - -if (FUNI_PYTHON) - set(CXX_HEADERS ${CXX_HEADERS} src/pyfuni.hpp) -endif() +set(CXX_HEADERS src/axis.hpp src/lexi.hpp src/pyfuni.hpp) # add library - header only -add_library(funi INTERFACE) -target_include_directories(funi - INTERFACE - $ - $) +add_library(headers INTERFACE) +target_include_directories( + headers INTERFACE $ + $) -add_library(funi::funi ALIAS funi) -set_target_properties(funi PROPERTIES CXX_STANDARD 17) +add_library(funi::headers ALIAS headers) +set_target_properties(headers PROPERTIES CXX_STANDARD 17) + +if(FUNI_BUILD_PYTHON) + find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) + find_package(pybind11 CONFIG REQUIRED) + python_add_library(funi MODULE src/pyfuni.cpp WITH_SOABI) + target_link_libraries(funi PRIVATE pybind11::headers funi::headers) + target_compile_definitions(funi PRIVATE $<$>:NDEBUG>) + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES + "Clang") + target_compile_options(funi PRIVATE $<$>:-O3>) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSCV") + target_compile_options(funi PRIVATE $<$>:/O2>) + endif() +endif() # configure config files include(CMakePackageConfigHelpers) -write_basic_package_version_file( - "${version_config}" COMPATIBILITY SameMajorVersion -) -configure_package_config_file( - "cmake/config.cmake.in" - "${project_config}" - INSTALL_DESTINATION "${cfg_dest}" -) +write_basic_package_version_file("${version_config}" + COMPATIBILITY SameMajorVersion) +configure_package_config_file("cmake/config.cmake.in" "${project_config}" + INSTALL_DESTINATION "${cfg_dest}") install( - TARGETS funi - EXPORT "${TARGETS_EXPORT_NAME}" - LIBRARY DESTINATION ${lib_dest} - ARCHIVE DESTINATION ${lib_dest} - INCLUDES DESTINATION "${incl_dest}" -) -install( - FILES "${project_config}" "${version_config}" - DESTINATION "${cfg_dest}" -) + TARGETS headers + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION ${lib_dest} + ARCHIVE DESTINATION ${lib_dest} + INCLUDES + DESTINATION "${incl_dest}") +install(FILES "${project_config}" "${version_config}" DESTINATION "${cfg_dest}") install( - EXPORT "${TARGETS_EXPORT_NAME}" - NAMESPACE "${namespace}" - DESTINATION "${cfg_dest}" -) -install( - FILES ${CXX_HEADERS} - DESTINATION ${incl_dest} -) + EXPORT "${TARGETS_EXPORT_NAME}" + NAMESPACE "${namespace}" + DESTINATION "${cfg_dest}") +install(FILES ${CXX_HEADERS} DESTINATION ${incl_dest}) + +if(FUNI_BUILD_PYTHON) + install(TARGETS funi DESTINATION .) +endif() From 88b447e1e2b54c4c569fa19bc1a58c1496f5f6e8 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 23:16:12 +0200 Subject: [PATCH 4/9] use scikit_build_core --- pyproject.toml | 35 +++++++++++++++++++++++------------ setup.py | 49 ------------------------------------------------- 2 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index bce4901..1d4d6c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,18 +1,29 @@ [build-system] -requires = [ - "setuptools>=42", - "wheel", - "pybind11", +requires = ["scikit-build-core", "pybind11>=2.12"] +build-backend = "scikit_build_core.build" + +[project] +name = "funi" +version = "0.1.0" +authors = [ + {name="Jaewook Lee", email="jaewooklee042@gmail.com"}, +] +license = {file = "LICENSE"} +description = "Find unique float arrays." +urls = {Homepage = "https://github.com/tataratat/funi"} +classifiers=[ + "Development Status :: 4 - Beta", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python", + "Natural Language :: English", + "Topic :: Scientific/Engineering", ] +dependencies = ["numpy"] +requires-python = '>=3.7' -build-backend = "setuptools.build_meta" +[project.readme] +file = "README.md" +content-type = "text/markdown" [tool.cibuildwheel] test-command = "python {project}/tests/test_funi.py" - -[tool.cibuildwheel.macos] -archs = ["x86_64", "arm64"] -test-skip = ["*arm64"] - -[tool.cibuildwheel.windows] -skip = "pp*" diff --git a/setup.py b/setup.py deleted file mode 100644 index 3b909dc..0000000 --- a/setup.py +++ /dev/null @@ -1,49 +0,0 @@ -from pybind11.setup_helpers import Pybind11Extension, build_ext -from setuptools import setup - -with open("README.md") as f: - readme = f.read() - -__version__ = "0.0.3" - -ext_modules = [ - Pybind11Extension( - "funi", - ["src/pyfuni.cpp"], - include_dirs=["src"], - extra_compile_args=["-O3"], - cxx_std=17, - ) -] - -setup( - name="funi", - version=__version__, - description="Find unique float arrays", - long_description=readme, - long_description_content_type="text/markdown", - author="Jaewook Lee", - author_email="jaewooklee042@gmail.com", - url="https://github.com/tataratat/funi", - ext_modules=ext_modules, - cmdclass={"build_ext": build_ext}, - package_data={"src": ["*.hpp"]}, - classifiers=[ - "Development Status :: 2 - Pre-Alpha", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Natural Language :: English", - "Topic :: Scientific/Engineering", - ], - install_requires=[ - "numpy", - ], - zip_safe=False, - license="MIT", -) From a19fe2ec90b84284c796212031e41d9cabb6f0b0 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 23:16:47 +0200 Subject: [PATCH 5/9] add __version__ and fix typos --- src/axis.hpp | 2 +- src/pyfuni.cpp | 4 +++- src/pyfuni.hpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/axis.hpp b/src/axis.hpp index 827156e..e226648 100644 --- a/src/axis.hpp +++ b/src/axis.hpp @@ -84,7 +84,7 @@ inline void Uff(DataType* original_points, /* in */ newpointmasks[metric_order_indices[lower_limit]] = true; } - // Value only required for stable sort (tracks the lowest occurence id of a + // Value only required for stable sort (tracks the lowest occurrence id of a // given point, that might be duplicate) IndexingType current_lowest_id{metric_order_indices[lower_limit]}; diff --git a/src/pyfuni.cpp b/src/pyfuni.cpp index 1565a97..4ca652a 100644 --- a/src/pyfuni.cpp +++ b/src/pyfuni.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include "pyfuni.hpp" PYBIND11_MODULE(funi, m) { m.def("unique_rows", @@ -10,4 +10,6 @@ PYBIND11_MODULE(funi, m) { pybind11::arg("tolerance"), pybind11::arg("sorted_index"), pybind11::arg("method")); + + m.attr("__version__") = "0.1.0"; } diff --git a/src/pyfuni.hpp b/src/pyfuni.hpp index 2ca1f41..732df97 100644 --- a/src/pyfuni.hpp +++ b/src/pyfuni.hpp @@ -56,7 +56,7 @@ py::tuple LexiUnique(const py::array_t& array_2d, inverse_ptr); } - // get unique count incase we need to return index or data + // get unique count in case we need to return index or data const IndexType n_unique = static_cast(unique_ids.size()); // finally, copy unique_ids From 1d35278b2d3aaf563c6f87a3b5309f3f9addd68f Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 23:19:55 +0200 Subject: [PATCH 6/9] update needs --- .github/workflows/build_and_upload_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_upload_wheels.yml b/.github/workflows/build_and_upload_wheels.yml index 2ada777..d3c24fe 100644 --- a/.github/workflows/build_and_upload_wheels.yml +++ b/.github/workflows/build_and_upload_wheels.yml @@ -135,7 +135,7 @@ jobs: path: ./dist/* upload_pypi: - needs: [macos_wheel, linux_wheel, windows_wheel, source_dist] + needs: [macos_wheel_m, macos_wheel_intel, linux_wheel, windows_wheel, source_dist] runs-on: ubuntu-latest # try to publish only if this is a push to stable branch if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} From 066bbc9a6d4ffbf69c24fd368f9d5da34c5975c1 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Wed, 19 Jun 2024 23:21:38 +0200 Subject: [PATCH 7/9] remove py 3.6 build --- .github/workflows/build_and_upload_wheels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_upload_wheels.yml b/.github/workflows/build_and_upload_wheels.yml index d3c24fe..23785fa 100644 --- a/.github/workflows/build_and_upload_wheels.yml +++ b/.github/workflows/build_and_upload_wheels.yml @@ -66,7 +66,7 @@ jobs: strategy: matrix: arch: [aarch64, ppc64le] - cw_build: ["cp36*many*", "cp37*many*", "cp38*many*", "cp39*many*", "cp310*many*", "cp311*many*", "cp312*many*", "pp37*many*", "pp38*many*", "pp39*many*"] + cw_build: ["cp37*many*", "cp38*many*", "cp39*many*", "cp310*many*", "cp311*many*", "cp312*many*", "pp37*many*", "pp38*many*", "pp39*many*"] exclude: - arch: ppc64le cw_build: "pp37*many*" From 3fcce62ab99f245b8acc0180a73765ce05738ad0 Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Thu, 20 Jun 2024 08:49:36 +0200 Subject: [PATCH 8/9] skip pp build for windows --- .github/workflows/build_and_upload_wheels.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_upload_wheels.yml b/.github/workflows/build_and_upload_wheels.yml index 23785fa..a5452bd 100644 --- a/.github/workflows/build_and_upload_wheels.yml +++ b/.github/workflows/build_and_upload_wheels.yml @@ -113,6 +113,7 @@ jobs: uses: pypa/cibuildwheel@v2.19 env: CIBW_ARCHS: ${{ matrix.arch }} + CIBW_SKIP: "pp*" - uses: actions/upload-artifact@v3 From 33b3b52ce3cc86700a252f95670581f1ecfd5d7a Mon Sep 17 00:00:00 2001 From: Jaewook Lee Date: Thu, 20 Jun 2024 12:04:14 +0200 Subject: [PATCH 9/9] suggestion from @clemens-fricke: update comment --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4660b4..db73291 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,8 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif() -# options - default is header only -option(FUNI_BUILD_PYTHON "build python" ON) +# options - default is to build python module together +option(FUNI_BUILD_PYTHON "build python module" ON) # config set(exe_dest "bin")