Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_code dropped from pyembed 10.3 #348

Open
julienfr112 opened this issue Dec 24, 2020 · 2 comments
Open

run_code dropped from pyembed 10.3 #348

julienfr112 opened this issue Dec 24, 2020 · 2 comments
Labels
question Further information is requested

Comments

@julienfr112
Copy link

julienfr112 commented Dec 24, 2020

run_code has been removed for perfectly good reasons, but :

  • the run_code is still in documentation : https://pyoxidizer.readthedocs.io/en/stable/rust_rust_code.html
  • how to call python code from rust ? Does PyOxidizer focus on being a tool to package python code, and drop the idea of also being a tool to embed python in rust application, and a bridge from the former to the later ?
@wkschwartz
Copy link
Contributor

wkschwartz commented Dec 25, 2020

how to call python code from rust ?

Check out the pyembed tests. One of them creates an interpreter and a GIL-holding token py here:

let mut config = OxidizedPythonInterpreterConfig::default();
// Otherwise Rust test executable args are parsed as Python args.
config.interpreter_config.parse_argv = Some(false);
config.oxidized_importer = true;
config.set_missing_path_configuration = false;
let mut interp = MainPythonInterpreter::new(config).unwrap();
let py = interp.acquire_gil().unwrap();

Once you've got py you can import, eval, etc. I'm not sure if this is the best answer, but maybe it'll get you started.

That said, be aware that the API may not be stable. See #324.

@indygreg indygreg added the question Further information is requested label Dec 30, 2020
@indygreg
Copy link
Owner

There should be no references to run_code and other deleted functions in the latest version of the document at https://pyoxidizer.readthedocs.io/en/latest/. The references still exist in the stable documentation because there hasn't been a release since the removal.

PyOxidizer focuses on building a binary embedding a Python interpreter.

The pyembed crate provides an API for managing an embedded Python interpreter. But it intentionally stops short of generic interactions with Python code, as this is better serviced by other Rust crates (namely cpython and pyo3).

If you want to write your own Rust code to call into the Python interpreter, you can obtain a reference to cpython::Python via pyembed::MainPythonInterpreter.acquire_gil() and use that crate's Rust APIs to call into Python.

I suppose the docs around how to use pyembed as a Rust developer could be significantly improved. So I'll keep this issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants