Skip to content

Build infrastructure Perl to Python port #1024

@abensonca

Description

@abensonca

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:

  1. 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::Python can handle scalars and simple lists, but blessed objects and complex refs translate poorly.
  2. Inline::Python is poorly maintained. It has known incompatibilities with newer Perls and modern Python 3.x builds.
  3. Debugging becomes a nightmare. Stack traces span two runtimes, and errors at the boundary are cryptic.
  4. The hook/plugin architecture makes it harder. Modules register callbacks into %moduleHooks and %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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions