Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to scikit-build-core #130

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
],
"__python_module": "{{ cookiecutter|modname }}",
"_catch_version": "2.13.10",
"_cibuildwheel_version": "2.13.1",
"_pybind_version": "2.10.4"
"_cibuildwheel_version": "2.22.0"
}
3 changes: 0 additions & 3 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def conditional_remove(condition, path):
conditional_remove("{{ cookiecutter.doxygen }}" == "No" and "{{ cookiecutter.readthedocs }}" == "No", "doc")
conditional_remove("{{ cookiecutter.python_bindings }}" == "No", "pyproject.toml")
conditional_remove("{{ cookiecutter.python_bindings }}" == "No", "requirements-dev.txt")
conditional_remove("{{ cookiecutter.python_bindings }}" == "No", "setup.py")
conditional_remove("{{ cookiecutter.python_bindings }}" == "No", "python")
conditional_remove("{{ cookiecutter.python_bindings }}" == "No", "tests/python")
conditional_remove("{{ cookiecutter.pypi_release }}" != "Yes", ".github/workflows/pypi.yml")
Expand All @@ -92,8 +91,6 @@ def conditional_remove(condition, path):
{% endif %}
{% if cookiecutter.use_submodules == "Yes" %}
repo.add_submodule("https://github.com/catchorg/Catch2.git", "ext/Catch2", tag="v{{ cookiecutter._catch_version }}")
if "{{ cookiecutter.python_bindings }}" == "Yes":
repo.add_submodule("https://github.com/pybind/pybind11.git", "ext/pybind11", tag="v{{ cookiecutter._pybind_version }}")
{% else %}
pass
{% endif %}
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ flaky
jsonschema
packaging
pre-commit
pybind11
PyGithub
pytest
pytest-cookies
Expand Down
59 changes: 18 additions & 41 deletions {{cookiecutter.project_slug}}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ on:
{%- if cookiecutter.use_submodules == "No" %}
env:
CATCH2_VERSION: {{ cookiecutter._catch_version }}
{%- if cookiecutter.python_bindings == "Yes" %}
PYBIND11_VERSION: {{ cookiecutter._pybind_version }}
{%- endif %}
{%- endif %}

jobs:
Expand Down Expand Up @@ -55,27 +52,6 @@ jobs:
cd build
cmake -DBUILD_TESTING=OFF ..
cmake --build . --target install
{% if cookiecutter.python_bindings == "Yes" %}
- name: Install Pybind11 (Linux + MacOS)
if: runner.os != 'Windows'
run: |
git clone -b v$PYBIND11_VERSION https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake -DBUILD_TESTING=OFF ..
sudo cmake --build . --target install

- name: Install Pybind11 (Windows)
if: runner.os == 'Windows'
run: |
git clone -b v$Env:PYBIND11_VERSION https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake -DBUILD_TESTING=OFF ..
cmake --build . --target install
{%- endif %}
{%- endif %}

- name: make build directory
Expand Down Expand Up @@ -113,7 +89,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.13"

- name: Run Python tests
shell: bash
Expand Down Expand Up @@ -148,32 +124,33 @@ jobs:
cd build
cmake -DBUILD_TESTING=OFF ..
sudo cmake --build . --target install
{%- endif %}

{% if cookiecutter.python_bindings == "Yes" %}
- name: Install Pybind11
if: runner.os != 'Windows'
- name: Install Python package editable
run: |
git clone -b v$PYBIND11_VERSION https://github.com/pybind/pybind11.git
cd pybind11
mkdir build
cd build
cmake -DBUILD_TESTING=OFF ..
sudo cmake --build . --target install
{%- endif %}
{%- endif %}

- name: make build directory
python -m pip install scikit_build_core pybind11[global]
python -m pip install --no-build-isolation --config-settings=build-dir="${{ "{{ github.workspace }}" }}/build" --config-settings=cmake.define.CMAKE_CXX_FLAGS="--coverage" --config-settings=cmake.define.BUILD_TESTING="ON" -v -e .
python -m pip install -r requirements-dev.txt

- name: Run Python tests
run: |
python -m pytest --cov --cov-report=xml
{% else %}
- name: Creat cmake build directory
run: cmake -E make_directory ${{ "{{ github.workspace }}" }}/build

- name: configure cmake
shell: bash
working-directory: ${{ "{{ github.workspace }}" }}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_CXX_FLAGS="--coverage" -DBUILD_DOCS=OFF
run: |
cmake $GITHUB_WORKSPACE -DCMAKE_CXX_FLAGS="--coverage" -DBUILD_DOCS=OFF

- name: build
shell: bash
working-directory: ${{ "{{ github.workspace }}" }}/build
run: cmake --build .
{% endif %}

- name: run tests
shell: bash
Expand All @@ -184,11 +161,11 @@ jobs:
shell: bash
working-directory: ${{ "{{ github.workspace }}" }}
run: |
lcov --directory ./build{% if cookiecutter.header_only == "No" %}/src{% endif %} --capture --output-file coverage.info
lcov --directory ./build{% if cookiecutter.header_only == "No" %}/src{% endif %} --capture --output-file coverage.info --ignore-errors mismatch

- name: Upload coverage to Codecov
- name: Upload C++ coverage to Codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
files: ${{ "{{github.workspace}}" }}/coverage.info
files: ${{ "{{github.workspace}}" }}/coverage.info{% if cookiecutter.python_bindings == "Yes" %},coverage.xml{% endif %}
{% endif %}
12 changes: 0 additions & 12 deletions {{cookiecutter.project_slug}}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ variables:
GIT_SUBMODULE_STRATEGY: recursive
{%- else %}
CATCH2_VERSION: {{ cookiecutter._catch_version }}
{%- if cookiecutter.python_bindings == "Yes" %}
PYBIND11_VERSION: {{ cookiecutter._pybind_version }}
{%- endif %}
{%- endif %}

.template: &template
Expand All @@ -16,15 +13,6 @@ variables:
- echo "Installing potential dependencies..."
{% if cookiecutter.python_bindings == "Yes" %}
- apt install -y python3-dev
{% if cookiecutter.use_submodules == "No" %}
- git clone -b v$PYBIND11_VERSION https://github.com/pybind/pybind11.git
- cd pybind11
- mkdir build
- cd build
- cmake -DBUILD_TESTING=OFF ..
- make install
- cd ../..
{% endif %}
{%- endif %}
{% if cookiecutter.use_submodules == "No" %}
- git clone -b v$CATCH2_VERSION https://github.com/catchorg/Catch2.git
Expand Down
8 changes: 2 additions & 6 deletions {{cookiecutter.project_slug}}/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Compilation options
{%- if cookiecutter.python_bindings == "Yes" %}
option(BUILD_PYTHON "Enable building of Python bindings" ON)
option(BUILD_PYTHON "Enable building of Python bindings" OFF)
{%- endif %}
{%- if cookiecutter.doxygen == "Yes" or cookiecutter.readthedocs == "Yes" %}
option(BUILD_DOCS "Enable building of documentation" ON)
Expand Down Expand Up @@ -75,11 +75,7 @@ endif()
{%- if cookiecutter.python_bindings == "Yes" %}
if(BUILD_PYTHON)
# Add Python bindings
{%- if cookiecutter.use_submodules == "Yes" %}
add_subdirectory(ext/pybind11)
{% else %}
find_package(pybind11)
{%- endif %}
find_package(pybind11 REQUIRED)
# Compile the Pybind11 module
pybind11_add_module(_{{ cookiecutter|modname }} python/{{ cookiecutter|modname }}/_{{ cookiecutter.project_slug }}.cpp)
target_link_libraries(_{{ cookiecutter|modname }} PUBLIC {{ cookiecutter.project_slug }})
Expand Down
6 changes: 2 additions & 4 deletions {{cookiecutter.project_slug}}/FILESTRUCTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ generated for you:
* `.gitmodules` tracks the state of added submodules
{%- endif %}
{%- if cookiecutter.python_bindings == "Yes" %}
* `setup.py` describes the Python package build process. This file enables you to also
install your software using e.g. `pip`.
* `pyproject.toml` provides information about the Python project and its toolchain.
`pip` uses this file before even executing `setup.py` to determine dependencies
of the build process itself. Additionally, it can be used to configure tools like `pytest`.
`pip` uses this file to control the entire build process. Additionally, it can be
used to configure tools like `pytest`.
{%- if cookiecutter.pypi_release == "Yes" -%}
Additionally, this file is needed for the automated release process to PyPI.
* `.github/workflows/pypi.yml` defines the workflow that deploys to PyPI. The
Expand Down
5 changes: 1 addition & 4 deletions {{cookiecutter.project_slug}}/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ The following tasks need to be done to get a fully working project:
* CMake `>= 3.9`
{%- if cookiecutter.use_submodules == "No" %}
* The testing framework [Catch2](https://github.com/catchorg/Catch2)
{%- if cookiecutter.python_bindings == "Yes" -%}
* The [PyBind11](https://github.com/pybind/pybind11) library
{%- endif %}
{%- endif %}
{%- if cookiecutter.external_dependency != "None" %}
* Adapt your list of external dependencies in `CMakeLists.txt` and `{{ cookiecutter.project_slug }}Config.cmake.in`.
Expand Down Expand Up @@ -43,7 +40,7 @@ The following tasks need to be done to get a fully working project:
on Debian or Ubuntu.
{%- endif %}
{%- if cookiecutter.python_bindings == "Yes" %}
* Edit the parameters of `setup()` in `setup.py` file to contain the necessary information
* Edit the parameters of `pyproject.toml` file to contain the necessary information
about your project, such as your email adress, PyPI classifiers and a short project description.
{%- endif %}
{%- if cookiecutter.pypi_release == "Yes" %}
Expand Down
23 changes: 12 additions & 11 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
# introduce pyproject.toml
[build-system]
requires = [
"setuptools>=61",
"wheel",
"scikit-build",
"cmake>=3.9",
{%- if cookiecutter.use_submodules == "No" %}
"pybind11[global]=={{ cookiecutter._pybind_version }}",
{%- endif %}
"scikit-build-core",
"pybind11[global]",
]
build-backend = "setuptools.build_meta"
build-backend = "scikit_build_core.build"

# This section provides general project metadata that is used across
# a variety of build tools. Notably, the version specified here is the
Expand Down Expand Up @@ -43,9 +38,15 @@ classifiers = [
]
dependencies = []

# NB: Setuptools-specific build options are currently still stored
# in setup.py, as scikit-build is not (yet) supporting PEP621.
# Later on, these will be stored in [tool.setuptools]
# The configuration for the scikit-build-core build process
[tool.scikit-build]
cmake.version = ">=3.9"
build.verbose = true

[tool.scikit-build.cmake.define]
BUILD_PYTHON = "ON"
BUILD_TESTING = "OFF"
BUILD_DOCS = "OFF"

# The following is the configuration for the pytest test suite
[tool.pytest.ini_options]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from {{ cookiecutter|modname }}._{{ cookiecutter|modname }} import add_one
from _{{ cookiecutter|modname }} import add_one

# Export the version given in project metadata
from importlib import metadata
Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pytest
{% if cookiecutter.codecovio == "Yes" %}
pytest-cov
{% endif %}
20 changes: 0 additions & 20 deletions {{cookiecutter.project_slug}}/setup.py

This file was deleted.

Loading