view rust/hg-cpython/src/utils.rs @ 43772:ee3872c14ab3

rust-cpython: do not convert warning pattern to utf-8 bytes On Unix, both Rust Path and Mercurial expect a locale-dependent bytes, and we don't support Windows yet.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 19 Nov 2019 23:19:57 +0900
parents 970978975574
children d738b7a18438
line wrap: on
line source

use cpython::{PyDict, PyObject, PyResult, PyTuple, Python};

#[allow(unused)]
pub fn print_python_trace(py: Python) -> PyResult<PyObject> {
    eprintln!("===============================");
    eprintln!("Printing Python stack from Rust");
    eprintln!("===============================");
    let traceback = py.import("traceback")?;
    let sys = py.import("sys")?;
    let kwargs = PyDict::new(py);
    kwargs.set_item(py, "file", sys.get(py, "stderr")?)?;
    traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs))
}