rust/hg-cpython/src/utils.rs
author Denis Laxalde <denis@laxalde.org>
Sun, 27 Oct 2019 18:12:24 +0100
branchstable
changeset 43334 4128ffba4431
parent 43251 970978975574
child 44515 d738b7a18438
permissions -rw-r--r--
tests: handle Message-Id email header possible wrapping The "Message-Id" header will get wrapped with a new line when exceeding 75 characters on Python 3 (see changeset 7d4f2e4899c5 introducing usage of email.header.Header.encode and respective doc). This will occur in an unpredictable manner depending on the hostname's length. To make the test output consistent across Python versions and hostname configuration, we add a filter to unwrap this header value.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43251
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     1
use cpython::{PyDict, PyObject, PyResult, PyTuple, Python};
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     2
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     3
#[allow(unused)]
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     4
pub fn print_python_trace(py: Python) -> PyResult<PyObject> {
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     5
    eprintln!("===============================");
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     6
    eprintln!("Printing Python stack from Rust");
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     7
    eprintln!("===============================");
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     8
    let traceback = py.import("traceback")?;
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     9
    let sys = py.import("sys")?;
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    10
    let kwargs = PyDict::new(py);
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    11
    kwargs.set_item(py, "file", sys.get(py, "stderr")?)?;
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    12
    traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs))
970978975574 rust-utils: introduce a debug util to print the python stack trace
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    13
}