feat: Update Python bindings for CFD C library v0.2.0#27
Merged
Conversation
Add bindings for all new v0.2.0 APIs: library lifecycle (init/finalize), version info, Poisson solver (6 functions + 22 constants), GPU device management (4 functions), logging callbacks, new boundary condition types (BC_TYPE_SYMMETRY, 3D edges), new status codes, and 3D grid/VTK support. Complete type stubs in __init__.pyi for all 51 bound functions and ~65 exported constants. Add CFDLimitExceededError and CFDNotFoundError exception classes.
There was a problem hiding this comment.
Pull request overview
Updates the Python package bindings to align with the CFD C library v0.2.0 API surface (new lifecycle/version APIs, Poisson + GPU helpers, logging callback support, new constants/status codes, and 3D/VTI/VTK-related updates).
Changes:
- Extend the C extension (
src/cfd_python.c) with v0.2.0 APIs (init/finalize/version, Poisson backend helpers, GPU device/config helpers, logging callback) and 3D-aware grid/VTK plumbing. - Simplify extension loading by auto-discovering public symbols via
dir()incfd_python/_loader.py. - Add new Python exception types and expand type stubs/constants for v0.2.0 in
cfd_python/_exceptions.py,cfd_python/__init__.py, andcfd_python/__init__.pyi.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/cfd_python.c |
Adds v0.2.0 bindings (lifecycle/version, Poisson, GPU, logging) and updates grid/VTK helpers for 3D parameters/constants. |
cfd_python/_loader.py |
Replaces curated export list with automatic discovery of public C-extension symbols; separates dynamic SOLVER_* constants. |
cfd_python/_exceptions.py |
Introduces new exception classes and maps new status codes to exceptions. |
cfd_python/__init__.pyi |
Expands type stubs for new v0.2.0 functions/constants and 3D-capable signatures. |
cfd_python/__init__.py |
Updates docs and exported symbol list (__all__) for new v0.2.0 APIs/constants/exceptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
The Python bindings now target v0.2.0 APIs (3D grid, Poisson solver, GPU management, logging) which don't exist in v0.1.6 headers.
Manual PyTuple construction didn't check PyLong_FromLong/ PyUnicode_FromString return values, risking segfault on allocation failure. PyObject_CallFunction handles this internally and also guards against NULL message pointers.
Without cleanup, the Python callback object leaks for the interpreter lifetime. Add cfd_python_free to unregister the C callback and release the Python reference.
…lues Hardcoded 0x10/0x20 could drift if the C library changes the enum. Use BC_EDGE_FRONT/BC_EDGE_BACK from boundary_conditions.h directly.
This constant doesn't exist in the v0.2.0 C extension (it was added post-tag). Including it in exports breaks `from cfd_python import *`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add bindings for all new v0.2.0 APIs: library lifecycle (init/finalize), version info, Poisson solver (6 functions + 22 constants), GPU device management (4 functions), logging callbacks, new boundary condition types (BC_TYPE_SYMMETRY, 3D edges), new status codes, and 3D grid/VTK support. Complete type stubs in init.pyi for all 51 bound functions and ~65 exported constants. Add CFDLimitExceededError and CFDNotFoundError exception classes.