diff --git a/cookiecutter.json b/cookiecutter.json index b4fc107..35b6bbc 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -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" } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 1db99ec..3bba2bc 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -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") @@ -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 %} diff --git a/requirements-dev.txt b/requirements-dev.txt index 69a7fa6..215658b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,6 @@ flaky jsonschema packaging pre-commit -pybind11 PyGithub pytest pytest-cookies diff --git a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml index 2eba7b4..575f905 100644 --- a/{{cookiecutter.project_slug}}/.github/workflows/ci.yml +++ b/{{cookiecutter.project_slug}}/.github/workflows/ci.yml @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 %} diff --git a/{{cookiecutter.project_slug}}/.gitlab-ci.yml b/{{cookiecutter.project_slug}}/.gitlab-ci.yml index 743aa7b..1172b1f 100644 --- a/{{cookiecutter.project_slug}}/.gitlab-ci.yml +++ b/{{cookiecutter.project_slug}}/.gitlab-ci.yml @@ -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 @@ -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 diff --git a/{{cookiecutter.project_slug}}/CMakeLists.txt b/{{cookiecutter.project_slug}}/CMakeLists.txt index 971d169..2dee36c 100644 --- a/{{cookiecutter.project_slug}}/CMakeLists.txt +++ b/{{cookiecutter.project_slug}}/CMakeLists.txt @@ -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) @@ -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 }}) diff --git a/{{cookiecutter.project_slug}}/FILESTRUCTURE.md b/{{cookiecutter.project_slug}}/FILESTRUCTURE.md index be2f14b..306d98e 100644 --- a/{{cookiecutter.project_slug}}/FILESTRUCTURE.md +++ b/{{cookiecutter.project_slug}}/FILESTRUCTURE.md @@ -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 diff --git a/{{cookiecutter.project_slug}}/TODO.md b/{{cookiecutter.project_slug}}/TODO.md index b1f5e45..8192e76 100644 --- a/{{cookiecutter.project_slug}}/TODO.md +++ b/{{cookiecutter.project_slug}}/TODO.md @@ -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`. @@ -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" %} diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 392890e..eb4e09d 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -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 @@ -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] diff --git a/{{cookiecutter.project_slug}}/python/{{cookiecutter.__python_module}}/__init__.py b/{{cookiecutter.project_slug}}/python/{{cookiecutter.__python_module}}/__init__.py index 9990c51..65bff69 100644 --- a/{{cookiecutter.project_slug}}/python/{{cookiecutter.__python_module}}/__init__.py +++ b/{{cookiecutter.project_slug}}/python/{{cookiecutter.__python_module}}/__init__.py @@ -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 diff --git a/{{cookiecutter.project_slug}}/requirements-dev.txt b/{{cookiecutter.project_slug}}/requirements-dev.txt index e079f8a..97c2a37 100644 --- a/{{cookiecutter.project_slug}}/requirements-dev.txt +++ b/{{cookiecutter.project_slug}}/requirements-dev.txt @@ -1 +1,4 @@ pytest +{% if cookiecutter.codecovio == "Yes" %} +pytest-cov +{% endif %} diff --git a/{{cookiecutter.project_slug}}/setup.py b/{{cookiecutter.project_slug}}/setup.py deleted file mode 100644 index 21279e2..0000000 --- a/{{cookiecutter.project_slug}}/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -from skbuild import setup -{%- if cookiecutter.use_submodules == "No" %} -import os -import pybind11 -{%- endif %} - - -setup( - packages=["{{ cookiecutter|modname }}"], - package_dir={"": "python"}, - zip_safe=False, - cmake_args=[ - "-DBUILD_TESTING=OFF", - "-DBUILD_DOCS=OFF", -{%- if cookiecutter.use_submodules == "No" %} - f"-DCMAKE_PREFIX_PATH={os.path.dirname(pybind11.__file__)}", -{%- endif %} - ], - cmake_install_dir="python/{{ cookiecutter|modname }}", -)