Skip to content

Improve Python interface #200

@alecandido

Description

@alecandido

There are a bunch of items that can be improved in the Python interface, eventually leading to less code to maintain and better DX for pineappl_py consumers:

  • drop Python layer, i.e. pineappl_py/pineappl, since at this point we have enough tools in PyO3 ecosystem (pyo3, rust-numpy, and extras, e.g. logging, if ever any of these will be needed) to provide a Python native experience without a dedicated layer (we can work with numpy arrays, add static/classmethods, and getters and setters with properties)
  • code generation: a lot of bindings are really repetitive, and it is clear we can automate many of them; PyO3 itself is based on code generation, but mainly targeting Rust-powered Python libs, not bindings for standalone Rust libs, so we should clutter pineappl crate with PyO3 declarative macros; this is rather ugly, because then we might want to do the same for C bindings, and further ones in case we will ever support new languages (so scaling the number of macros with the languages supported); so either we find a native way to generate code using PyO3 macros, or we should write our own macros to generate the code corresponding to repeated patterns in current content of pineappl_py/src
  • Python types: types are useful in Rust as in Python, so, if possible, let's propagate them to the second, even though PyO3 still indicates a manual approach
  • better Python exceptions: we can use PyO3 support for plain exceptions, or its anyhow feature, since @cschwan already started introducing anyhow in main pineappl crate

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions