pybind / scikit_build_example

An example combining scikit-build and pybind11
Other
110 stars 29 forks source link

How would I go about incorporating C++ tests into this? #117

Closed sodiumnitrate closed 10 months ago

sodiumnitrate commented 10 months ago

I'm working on a few python packages using this setup, and there is extra code/functionality on the C++ side that I don't expose to python. I'd like to be able to write unit tests, perhaps using GTEST, that I can integrate into this setup. I attempted incorporating the setup in this tutorial, but I'm unclear about a few things. The way that I understand it, a possible solution could be:

  1. Have a github action run tests separately, following an explicit build, not with pip, and then manually run the tests. Perhaps something like this.
  2. This seems to require fetching pybind11 explicitly within CMakeLists.txt. I'm not sure if this is fine.
  3. This also probably requires CMakeLists.txt files that would work both with pip and cmake. (I'm a beginner in cmake, so I'm assuming there's a way to do this.)

Can someone chime in? Am I overcomplicating things?

sodiumnitrate commented 10 months ago

Okay, I found this example by the same author, and modified it to use scikit-build only, and not setuptools.

Essentially:

  1. delete setup.py
  2. change the content of pyproject.toml to something like:
    
    [build-system]
    requires = [
    "scikit-build-core>=0.3.3",
    "cmake>=3.14",
    "ninja",
    "pybind11>=2.6"
    ]
    build-backend = "scikit_build_core.build"

[project] name = "hello-cmake-scikit" version = "0.1.0" readme = "README.md" requires-python = ">=3.10"

[project.optional-dependencies] test = ["pytest"]


and follow the instructions in the example, basically. Closing this, but feel free to reopen if I'm doing something egregiously wrong.