Installation via pip (C-Python bindings)

I was wondering if the whole code could be installable via pip.
As the user guide mentiones, Python API is installable via pip, but the rest has to be installed from Conda/Docker/Spack or compiled via CMake.

Idea

Could pip install openmc install everything, similarly to e.g. numpy?

My research

I’m not an expert, so please correct me here.

C code can be shipped in Python wheels, requiring 2 steps:

  1. create Python objects from C code - this can be done manually using the Python C API or with special tools such as pybind11, nanobind or boost-python
  2. use a build backend that can compile it, such as meson-python

A minimal example of such process can be found in meson-python tutorial, pybind11 tutorial or nanobind tutorial.

Examples of python packages using this approach are numpy, scipy or tensorflow (if I am not mistaken).

Benefits of such approach

  • simpler installation (pip install openmc or uv add openmc)
  • broader options to use C API from Python - possibly for coupled calculations (?)

Cons

  • extra code
  • prepared wheels will likely not be optimized for all platforms - building from source would likely produce mode optimized code (e.g. when using --march=native) (extra research needed here - I’ve seen some more elaborate build configurations e.g. at numpy
  • I don’t know how to handle the build dependencies (libpng-dev and others) with meson-python

Thanks for any comments on that.

We already have a running PR here Enable Scikit-Build-Core Support by ahnaf-tahmid-chowdhury · Pull Request #3339 · openmc-dev/openmc · GitHub