m-ou-se / inline-python

Inline Python code directly in your Rust code
https://docs.rs/inline-python
BSD 2-Clause "Simplified" License
1.16k stars 40 forks source link

Compile python code at Rust compile time. #5

Closed de-vri-es closed 5 years ago

de-vri-es commented 5 years ago

This PR compiles the python code at Rust compile time. Implements #3.

Currently this will ouput this on a syntax error:

error: proc macro panicked
  --> inline-python-example/src/main.rs:7:2
   |
7  |       python! {
   |  _____^
8  | |         import matplotlib.pyplot as plt
9  | |         plt.plot('data)
10 | |         def foo()
11 | |         plt.show()
12 | |     }
   | |_____^
   |
   = help: message: invalid syntax at inline-python-example/src/main.rs:10:10

Though we know the filename, line number and column, we can't easily turn that into a Span, so for now it just prints the information in an error message. Would be very cool though if we can get a span to point to the syntax error.

I had to manually expose the PyMarshal_* functions, but I'll send those to pyo3 in a PR too.

de-vri-es commented 5 years ago

PR to add PyMarshal_* functions at pyo3 can be found here: https://github.com/PyO3/pyo3/pull/460