python bindings: redesign Phase 1 + Phase 2#3332
Open
martin-belanger wants to merge 2 commits intolinux-nvme:masterfrom
Open
python bindings: redesign Phase 1 + Phase 2#3332martin-belanger wants to merge 2 commits intolinux-nvme:masterfrom
martin-belanger wants to merge 2 commits intolinux-nvme:masterfrom
Conversation
added 2 commits
April 29, 2026 13:32
Extend generate-accessors.py to emit three new SWIG fragment files from
the existing !generate-accessors annotations in private.h and
private-fabrics.h:
accessors.i — kernel-object structs (Ctrl, Host, Subsystem,
Namespace, GlobalCtx)
accessors-fabrics.i — fabrics-specific structs
nvme-manual-bridges.i — residual hand-written %rename bridges
A new struct-level annotation !generate-python[:alias=NAME] gates
emission for Python and carries the PascalCase class alias. Remove the
hand-written %rename(ctrl) / %rename(host) / ... lines from nvme.i;
they are now generator-emitted.
Restructure nvme.i so all %typemap directives precede the generated
%include "accessors.i". SWIG freezes type-to-typemap associations when
it first processes a struct body; struct bodies now arrive via the
generated include so typemaps must come first.
A generator-emitted _nvme_guarded_setattr is installed on each class at
import to catch typos and writes to read-only (%immutable) properties.
C-internal iteration helpers are renamed with a leading underscore via
%rename to keep them out of the public API surface.
Update nvme.i docstrings to Pythonic style (Args:/Returns: conventions,
PascalCase class names, module-level usage examples). Update tests and
examples to use the new API.
Verified: meson test -C .build passes (64 OK, 2 expected failures).
Signed-off-by: Martin Belanger <Martin.Belanger@dell.com>
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
- Convert connected() and is_registration_supported() to read-only Python properties (connected, registration_supported) - Delete set_symname(); host.hostsymname is already writable via the generated SWIG field descriptor - Rename registration_ctrl() to registration_control() to reflect that the method is a multi-action control interface (register, deregister, update via NVMF_DIM_TAS_*), not a single register operation - Update test-objects.py to match the new API Signed-off-by: Martin Belanger <martin.belanger@dell.com> Assisted-by: Claude Sonnet <noreply@anthropic.com>
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.
Summary
This PR delivers Phase 1 and Phase 2 of a 3-phase refactoring of the libnvme Python bindings. Phase 3 (callback/hook support) is planned but not yet scheduled.
Phase 1 — Generator-emitted SWIG fragments
generate-accessors.pywith a--swig-outoption that emitsaccessors.iandaccessors-fabrics.idirectly from the!generate-accessors/!generate-pythonannotations inprivate.handprivate-fabrics.h.!generate-pythongets a SWIG fragment with per-axis access routing:generatedaxes use direct field access (p->member),customaxes route through%rename+#definebridge to the hand-written accessor.nvme-swig-accessors.iandgenerate-swig-accessors.py(replaced by the generator).check-nvme-i-consistency.pyand its meson test (no longer needed —nvme.ino longer duplicates struct declarations).__setattr__guard into a single generated definition installed per class at module import.Phase 2 — API surface polish
connected()andis_registration_supported()converted to read-only Python properties (ctrl.connected,ctrl.registration_supported).host.set_symname(x)deleted;host.hostsymname = xworks directly via the generated SWIG field descriptor.registration_ctrl()renamed toregistration_control()— the method is a multi-action control interface (register, deregister, update viaNVMF_DIM_TAS_*), not a single register operation.Test plan
meson test -C .buildpasses (all 66 tests includingpython-object-properties-and-errors)meson compile -C .build update-accessorsregenerates identicalaccessors.i/accessors-fabrics.i