comparison rust/hgcli/src/main.rs @ 44642:af739894a4c1

hgcli: add stub PyOxidizer project Using commit c772a1379c3026314eda1c8ea244b86c0658951d of PyOxidizer, I ran `pyoxidizer init-rust-project hgcli` to create a stub Rust project. The only modifications I made from what that command produced are: * Update location of pyembed crate to PyOxidizer's Git repository. * Removed some trailing whitespace from pyoxidizer.bzl * Added auto-generated Cargo.lock file Subsequent commits will modify the stub project to Mercurial's needs. Differential Revision: https://phab.mercurial-scm.org/D8350
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 31 Mar 2020 19:07:36 -0700
parents
children 26ce8e751503
comparison
equal deleted inserted replaced
44641:02f66b23cba3 44642:af739894a4c1
1 use pyembed::MainPythonInterpreter;
2
3 // Include an auto-generated file containing the default
4 // `pyembed::PythonConfig` derived by the PyOxidizer configuration file.
5 //
6 // If you do not want to use PyOxidizer to generate this file, simply
7 // remove this line and instantiate your own instance of
8 // `pyembed::PythonConfig`.
9 include!(env!("PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS"));
10
11 fn main() {
12 // The following code is in a block so the MainPythonInterpreter is destroyed in an
13 // orderly manner, before process exit.
14 let code = {
15 // Load the default Python configuration as derived by the PyOxidizer config
16 // file used at build time.
17 let config = default_python_config();
18
19 // Construct a new Python interpreter using that config, handling any errors
20 // from construction.
21 match MainPythonInterpreter::new(config) {
22 Ok(mut interp) => {
23 // And run it using the default run configuration as specified by the
24 // configuration. If an uncaught Python exception is raised, handle it.
25 // This includes the special SystemExit, which is a request to terminate the
26 // process.
27 interp.run_as_main()
28 }
29 Err(msg) => {
30 eprintln!("{}", msg);
31 1
32 }
33 }
34 };
35
36 // And exit the process according to code execution results.
37 std::process::exit(code);
38 }