Migrate Vector component from ctypes to SWIG bindings with backward compatibility#41
Draft
Migrate Vector component from ctypes to SWIG bindings with backward compatibility#41
Conversation
- Create SWIG interface for Vector component (core/vector.i) - Implement SWIG-based Vector wrapper with ctypes compatibility - Modify main Vector class to use SWIG internally while maintaining ctypes interface - Add hybrid approach supporting both SWIG and ctypes backends - Update build system and gitignore for SWIG support - All 188 tests continue to pass without modification - Establish pattern for gradual migration of other components Co-authored-by: bmander <51985+bmander@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Let's gradually port the hand made pygs python bindings over to SWIG. Pick a single component to port over. Make sure all the tests keep passing
Migrate Vector component from ctypes to SWIG bindings with backward compatibility
Jul 13, 2025
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.
This PR implements the first step in gradually migrating graphserver's hand-made Python bindings from ctypes to SWIG, starting with the Vector component. The migration maintains 100% backward compatibility while establishing a pattern for future component migrations.
Problem
The current Python bindings use hand-crafted ctypes wrappers that are:
Solution
Implemented a hybrid approach that uses SWIG internally while preserving the ctypes interface:
Key Changes
1. SWIG Interface Definition (
core/vector.i)2. SWIG Vector Wrapper (
pygs/graphserver/vector_swig.py)3. Hybrid Vector Class (
pygs/graphserver/vector.py)4. Build System Updates
pyproject.tomlsetup.pyfor SWIG extension building.gitignorefor SWIG-generated filesExample Usage
Benefits
Testing
Future Work
This establishes the migration pattern for other components:
The hybrid approach allows incremental migration while maintaining system stability throughout the process.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.