-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Labels
Description
This is a rich codebase to analyze. Let me give you a frank assessment of the Inline::Python approach and a recommended strategy instead.
Assessment of Inline::Python
I'd advise against using Inline::Python as the interop bridge. The key problems:
- Data structure translation is fragile. The build system passes around deeply nested Perl data structures — blessed hashrefs representing Fortran AST nodes, anonymous sub-callbacks registered in hook hashes, etc.
Inline::Pythoncan handle scalars and simple lists, but blessed objects and complex refs translate poorly. Inline::Pythonis poorly maintained. It has known incompatibilities with newer Perls and modern Python 3.x builds.- Debugging becomes a nightmare. Stack traces span two runtimes, and errors at the boundary are cryptic.
- The hook/plugin architecture makes it harder. Modules register callbacks into
%moduleHooksand%processHooks. A Python module can't natively register a callback into a Perl hash.
Recommended Strategy: Parallel Python Rewrite with Script-Level Cutover
Rather than interop at the module level, interop at the process boundary — keep Perl calling Perl and Python calling Python, and replace whole entry-point scripts at once.
Phase 0: Build a Python Test Harness First
Before porting anything, capture the behavior of the existing system:
- Run the build system on representative inputs and save outputs (generated Fortran/C++ files, directive parse results, etc.)
- Write a Python test framework that compares Python output to these golden files
- This gives you confidence that each ported module is behaviorally equivalent
Phase 1: Port the Infrastructure (~500 lines, ~4 modules)
These are leaf nodes with no internal dependencies — port them first and establish the Python package structure (galacticus/build/):
| Module | Lines | Notes |
|---|---|---|
| Hooks.pm | 11 | Just a shared dict — trivial |
| SourceTree/Hooks.pm | 15 | Same |
| Dependencies.pm | 132 | Topological sort — graphlib in stdlib |
| Directives.pm | 100 | XML parsing — lxml or xml.etree |
| Make.pm | 28 | Trivial |
Reactions are currently unavailable