annotate rust/hgcli/src/main.rs @ 44729:26ce8e751503 stable 5.4rc0

merge default into stable for 5.4 release
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 16 Apr 2020 22:51:09 +0530
parents ce088b38f92b af739894a4c1
children 426294d06ddc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44638
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
1 use pyembed::MainPythonInterpreter;
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
2
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
3 // Include an auto-generated file containing the default
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
4 // `pyembed::PythonConfig` derived by the PyOxidizer configuration file.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
5 //
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
6 // If you do not want to use PyOxidizer to generate this file, simply
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
7 // remove this line and instantiate your own instance of
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
8 // `pyembed::PythonConfig`.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
9 include!(env!("PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS"));
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
10
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
11 fn main() {
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
12 // The following code is in a block so the MainPythonInterpreter is destroyed in an
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13 // orderly manner, before process exit.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
14 let code = {
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
15 // Load the default Python configuration as derived by the PyOxidizer config
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
16 // file used at build time.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
17 let config = default_python_config();
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
18
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
19 // Construct a new Python interpreter using that config, handling any errors
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
20 // from construction.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
21 match MainPythonInterpreter::new(config) {
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
22 Ok(mut interp) => {
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23 // And run it using the default run configuration as specified by the
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
24 // configuration. If an uncaught Python exception is raised, handle it.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25 // This includes the special SystemExit, which is a request to terminate the
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 // process.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27 interp.run_as_main()
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
28 }
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
29 Err(msg) => {
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
30 eprintln!("{}", msg);
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
31 1
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
32 }
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
33 }
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
34 };
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
36 // And exit the process according to code execution results.
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
37 std::process::exit(code);
af739894a4c1 hgcli: add stub PyOxidizer project
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
38 }