Skip to content

feat(python): add Python bindings and wrappers #2

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

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
33 changes: 25 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
- clang
- gcc
preset:
- debug-strict
- release-strict
- debug-python-strict
- release-python-strict

steps:
- name: Checkout
Expand Down Expand Up @@ -118,17 +118,34 @@ jobs:
echo "CPPFLAGS=-I$GCC_HOME/include" >>$GITHUB_ENV
echo "LDFLAGS=-L$GCC_HOME/lib/gcc/${{ env.GCC_VERSION }}" >>$GITHUB_ENV

- name: Configure with preset
- name: Install Python dependencies
run: |
cmake --preset ${{ matrix.preset }} -DENABLE_CLANG_TIDY=${{ matrix.compiler == 'clang' }}
pip3 install -U pytest

- name: Build with preset
- name: Configure
run: |
cmake --build --preset ${{ matrix.preset }} --parallel
cmake \
--preset ${{ matrix.preset }} \
-DENABLE_CLANG_TIDY=${{ matrix.compiler == 'clang' }}

- name: Test with preset
- name: Build
run: |
ctest --preset ${{ matrix.preset }} --parallel
cmake \
--build \
--preset ${{ matrix.preset }} \
--parallel

- name: Run C++ tests
run: |
ctest \
--preset ${{ matrix.preset }} \
--parallel

- name: Run Python tests
env:
PYTHONPATH: 'python/src:build/${{ matrix.preset }}-python-strict/binding'
run: |
pytest python/tests -v

- name: Upload build logs
if: failure()
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ out/
*.dylib
*.dll

# Python
__pycache__/
*.pyc
*.pyo
*.pyd
*.pyw
*.pyz

# Debug and temporary files
*.log
*.tmp
Expand Down
18 changes: 17 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ repos:

# CMake formatting with gersemi
- repo: https://github.com/BlankSpruce/gersemi
rev: 0.21.0
rev: 0.22.1
hooks:
- id: gersemi
files: (\.cmake|CMakeLists\.txt)$

# Python formatting with black
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
files: \.py$
args: ['-S']

# Python import sorting with isort
- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort
files: \.py$
args: ['--profile', 'black', '--filter-files']

# Markdown linting and formatting
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.18.1
Expand Down
15 changes: 13 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@
"cmake.automaticReconfigure": true,
"cmake.configureOnEdit": true,
"cmake.configureOnOpen": true,
"cursorpyright.analysis.extraPaths": [
"python/src",
"build/debug-python/binding",
"build/release-python/binding",
"build/debug-python-no-tests/binding",
"build/release-python-no-tests/binding",
"build/debug-python-strict/binding",
"build/release-python-strict/binding"
],
"editor.codeActionsOnSave": {
"source.fixAll.clangd": "explicit",
"source.organizeImports": "explicit"
},
"editor.detectIndentation": false,
"editor.semanticTokenColorCustomizations": {
"enabled": true
},
"editor.suggest.insertMode": "replace",
"editor.tabSize": 2,
"files.associations": {
"*.cpp": "cpp",
"*.h": "cpp",
Expand All @@ -36,6 +43,10 @@
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"git.ignoreLimitWarning": true,
"isort.args": [
"--profile",
"black"
],
"markdownlint.config": {
"extends": ".markdownlint.yaml"
}
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Options
option(BUILD_TESTS "Build tests" ${IS_MAIN_PROJECT})
option(BUILD_EXAMPLES "Build examples" ${IS_MAIN_PROJECT})
option(BUILD_PYTHON_BINDINGS "Build Python bindings" OFF)
option(ENABLE_WARNINGS "Enable compiler warnings" ON)

# macOS-specific fixes for Mach-O linker errors
Expand Down Expand Up @@ -117,6 +118,11 @@ if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Build Python bindings if enabled
if(BUILD_PYTHON_BINDINGS)
add_subdirectory(binding)
endif()

# Installation
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
Expand Down
Loading
Loading