Skip to content
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
55 changes: 28 additions & 27 deletions .github/workflows/python-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,48 @@ concurrency:
cancel-in-progress: true
jobs:
python-tests:
name: "Test python bindings"
name: "Test Python bindings"
strategy:
matrix:
on: [ 'ubuntu-24.04', 'macos-15-intel' , 'macos-26' ]
on: [ 'ubuntu-24.04', 'macos-15-intel', 'macos-26' ]
python: [ '3.10', '3.11', '3.12', '3.13' ]

runs-on: ${{matrix.on}}
runs-on: ${{ matrix.on }}
env:
INSTALL_PREFIX: "/usr/local"

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v6
- name: "Checkout repository"
uses: actions/checkout@v4

- name: "Set up Python ${{ matrix.python }}"
uses: actions/setup-python@v6
with:
python-version: ${{matrix.python}}
- name: "Install packages ubuntu"
if: ${{ startsWith(matrix.on, 'ubuntu-') }}
run: sudo apt install -y ninja-build g++
python-version: ${{ matrix.python }}

# Install platform build dependencies
- name: "Install system packages (Ubuntu)"
if: startsWith(matrix.on, 'ubuntu-')
run: sudo apt-get update && sudo apt-get install -y ninja-build g++ cmake

- name: "Setup macos runner"
if: ${{ startsWith(matrix.on, 'macos-') }}
- name: "Setup Homebrew (macOS)"
if: startsWith(matrix.on, 'macos-')
uses: Homebrew/actions/setup-homebrew@main

- name: "Install macos packages"
if: ${{ startsWith(matrix.on, 'macos-') }}
- name: "Install system packages (macOS)"
if: startsWith(matrix.on, 'macos-')
run: brew install ninja gcc cmake

- name: "Run CMake"
# Install Python build dependencies
- name: "Build and Install Python wheel"
run: |
cmake -DCMAKE_BUILD_TYPE=Release \
-G Ninja \
-B ../build \
-S ${GITHUB_WORKSPACE}
cmake --build ../build -j $(nproc)
sudo cmake --install ../build --prefix $INSTALL_PREFIX

- name: "Install python test environment"
run: python -m pip install -r ${GITHUB_WORKSPACE}/test-requirement.txt
python -m pip install --upgrade pip
python -m pip install -r build-requirements.txt
python -m build
pip install dist/*.whl

- name: "Run python tests"
# Run unit tests
- name: "Run Python tests"
run: |
export CAPIO_CL_PY_BINDING_PATH=$(realpath $INSTALL_PREFIX/lib/python/py_capio_cl*)
echo "Python module path: $CAPIO_CL_PY_BINDING_PATH"
pytest ${GITHUB_WORKSPACE}/tests/python/test_*
python -m pip install -r test-requirements.txt
pytest -v tests/python/test_*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ cmake-build-*/**
.venv/**
__pycache__/
*.pyc
dist/**

# Prerequisites
*.d
Expand Down
8 changes: 2 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ install(TARGETS ${TARGET_NAME}
#####################################
if (BUILD_PYTHON_BINDINGS)

set(PYTHON_BIND_NAME py_capio_cl)
set(PYTHON_BIND_NAME _py_capio_cl)

pybind11_add_module(${PYTHON_BIND_NAME}
bindings/python_bindings.cpp
Expand All @@ -97,11 +97,7 @@ if (BUILD_PYTHON_BINDINGS)
${CMAKE_CURRENT_SOURCE_DIR}
)

install(TARGETS ${PYTHON_BIND_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/python
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/python
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(TARGETS _py_capio_cl DESTINATION py_capio_cl)

endif ()

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ These bindings expose the core C++ APIs—such as `Engine`, `Parser`, directly
to Python, allowing the CAPIO-CL logic to be used within python projects.

### 🔧 Building the Bindings
To include Python support when building CAPIO-CL:
You can build and install the Python bindings directly from the CAPIO-CL source tree using:

```bash
cmake -DBUILD_PYTHON_BINDINGS=ON ..
cmake --build . --target py_capio_cl
pip install --upgrade pip
pip install -r build-requirements.txt
python -m build
pip install dst/*.whl
```
Now you will be able to directly import the package **py_capio_cl** in your project!

---

Expand Down
2 changes: 1 addition & 1 deletion bindings/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace py = pybind11;

PYBIND11_MODULE(py_capio_cl, m) {
PYBIND11_MODULE(_py_capio_cl, m) {
m.doc() =
"CAPIO-CL: Cross Application Programmable I/O - Coordination Language python bindings.";
py::class_<capiocl::Engine>(
Expand Down
1 change: 1 addition & 0 deletions build-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build==1.3.0
1 change: 1 addition & 0 deletions py_capio_cl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._py_capio_cl import *
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[build-system]
requires = [
"scikit-build-core[pyproject]==0.11.6",
"pybind11==3.0.1",
"setuptools==80.9.0",
"wheel==0.45.1"
]
build-backend = "scikit_build_core.build"

[project]
name = "py_capio_cl"
dynamic = ["version"]
description = "Python bindings for the CAPIO-CL coordination language"
readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.10"
authors = [
{ name = "Marco Edoardo Santimaria", email = "marcoedoardo.santimaria@unito.it" }
]

[project.urls]
Homepage = "https://capio.hpc4ai.it"
Documentation = "https://capio.hpc4ai.it/docs/coord-language/"
Repository = "https://github.com/High-Performance-IO/CAPIO-CL"
Issues = "https://github.com/High-Performance-IO/CAPIO-CL/issues"


[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "CMakeLists.txt"
regex = "(?m)VERSION\\s+(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
result = "{major}.{minor}.{patch}"

[tool.scikit-build]
cmake.version = ">=3.18"
ninja.version = ">=1.10"
File renamed without changes.
26 changes: 1 addition & 25 deletions tests/python/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,4 @@
'''
TEST(testpy_capio_clEngine, testAddFileDefault) {
py_capio_cl::Engine engine;
EXPECT_EQ(engine.size(), 0);
engine.newFile("test.dat");
EXPECT_EQ(engine.size(), 1);
EXPECT_EQ(engine.getCommitRule("test.dat"), py_capio_cl::COMMITTED_ON_TERMINATION);
EXPECT_EQ(engine.getFireRule("test.dat"), py_capio_cl::MODE_UPDATE);
EXPECT_TRUE(engine.getConsumers("test.dat").empty());
EXPECT_TRUE(engine.getProducers("test.dat").empty());
EXPECT_FALSE(engine.isPermanent("test.dat"));
EXPECT_FALSE(engine.isExcluded("test.dat"));
EXPECT_TRUE(engine.isFile("test.dat"));
EXPECT_FALSE(engine.isDirectory("test.dat"));
EXPECT_EQ(engine.getDirectoryFileCount("test.dat"), 0);
EXPECT_FALSE(engine.isStoredInMemory("test.dat"));
}
'''

import os
import importlib.util

spec = importlib.util.spec_from_file_location("py_capio_cl", os.getenv("CAPIO_CL_PY_BINDING_PATH"))
py_capio_cl = importlib.util.module_from_spec(spec)
spec.loader.exec_module(py_capio_cl)
import py_capio_cl


def test_instantiation():
Expand Down
Loading