From 857deb3ac6726cbb9112b42477107f53fdd734cb Mon Sep 17 00:00:00 2001 From: Matthias Wittgen Date: Fri, 3 Jan 2025 16:00:10 -0800 Subject: [PATCH 1/3] Use scikit-build and existing CMakeLists.txt --- CMakeLists.txt | 12 +++++++++++- pyproject.toml | 3 +++ python/lsst/sphgeom/CMakeLists.txt | 2 -- setup.py | 21 ++------------------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c250195..89fcee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,16 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.17..3.30) project(sphgeom) +# Find Python interpreter and libraries + +find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter Development) +execute_process( + COMMAND "${Python3_EXECUTABLE}" -m pybind11 --cmakedir + OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE pybind11_ROOT + ERROR_VARIABLE error_output +) +find_package(pybind11 CONFIG REQUIRED PATHS ${pybind11_ROOT}) + enable_testing() add_subdirectory(python/lsst/sphgeom) diff --git a/pyproject.toml b/pyproject.toml index 9cbeb6b..acd3ee5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,8 +2,11 @@ requires = [ "setuptools", "lsst-versions >= 1.3.0", + "scikit-build", "wheel", "pybind11 >= 2.5.0", + "cmake", + "ninja", "numpy >= 1.18", ] build-backend = "setuptools.build_meta" diff --git a/python/lsst/sphgeom/CMakeLists.txt b/python/lsst/sphgeom/CMakeLists.txt index c11dcab..1dd3b88 100644 --- a/python/lsst/sphgeom/CMakeLists.txt +++ b/python/lsst/sphgeom/CMakeLists.txt @@ -1,5 +1,3 @@ -find_package(pybind11 REQUIRED) - pybind11_add_module(_sphgeom _angle.cc _angleInterval.cc diff --git a/setup.py b/setup.py index fa4edf7..689ba5c 100644 --- a/setup.py +++ b/setup.py @@ -9,25 +9,8 @@ interface. """ -import glob - -from pybind11.setup_helpers import ParallelCompile, Pybind11Extension, build_ext -from setuptools import setup - -# Optional multithreaded build. -ParallelCompile("NPY_NUM_BUILD_JOBS").install() - -# Find the source code -- we can combine it into a single module -pybind_src = sorted(glob.glob("python/lsst/sphgeom/*.cc")) -cpp_src = sorted(glob.glob("src/*.cc")) - -# Very inefficient approach since this compiles the maing sphgeom -# library code for every extension rather than building everything once -ext_modules = [ - Pybind11Extension("lsst.sphgeom._sphgeom", sorted(cpp_src + pybind_src), include_dirs=["include"]) -] +from skbuild import setup setup( - ext_modules=ext_modules, - cmdclass={"build_ext": build_ext}, + cmake_source_dir=".", ) From 1fa9141203c1793512e2794646fcbe6de31d8079 Mon Sep 17 00:00:00 2001 From: Matthias Wittgen Date: Fri, 3 Jan 2025 17:10:48 -0800 Subject: [PATCH 2/3] Don't use system python env --- .github/workflows/build.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0f6ea20..6edf24a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -32,10 +32,12 @@ jobs: - name: Build and install run: | python -m pip install --upgrade pip setuptools uv - uv pip install --system .[yaml,test] + uv venv + uv pip install pytest + uv pip install .[yaml,test] - name: Run tests - run: pytest -r a -v + run: uv run pytest -r a -v pypi_sdist_build: runs-on: ubuntu-latest From 1925c604e7c332e1f4bd6e65acdd36e2d3e2c537 Mon Sep 17 00:00:00 2001 From: Matthias Wittgen Date: Fri, 3 Jan 2025 19:55:27 -0800 Subject: [PATCH 3/3] Don't use system python env --- .github/workflows/build.yaml | 6 ++---- setup.py | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6edf24a..0f6ea20 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -32,12 +32,10 @@ jobs: - name: Build and install run: | python -m pip install --upgrade pip setuptools uv - uv venv - uv pip install pytest - uv pip install .[yaml,test] + uv pip install --system .[yaml,test] - name: Run tests - run: uv run pytest -r a -v + run: pytest -r a -v pypi_sdist_build: runs-on: ubuntu-latest diff --git a/setup.py b/setup.py index 689ba5c..d0572b1 100644 --- a/setup.py +++ b/setup.py @@ -13,4 +13,5 @@ setup( cmake_source_dir=".", + cmake_install_dir=".", )