# HG changeset patch # User Raphaël Gomès # Date 1583400250 -3600 # Node ID d4f19eb471ca22f161cb817075e153638b13d55e # Parent 4d1634e59f130427e6ee0dbaa94b6c75aaae5e8d rust-cpython: add `debug` module to expose debug information to Python This will be mostly used in `debuginstall`. Differential Revision: https://phab.mercurial-scm.org/D8225 diff -r 4d1634e59f13 -r d4f19eb471ca rust/hg-cpython/src/debug.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/hg-cpython/src/debug.rs Thu Mar 05 10:24:10 2020 +0100 @@ -0,0 +1,26 @@ +// debug.rs +// +// Copyright 2020 Raphaël Gomès +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +//! Module to get debug information about Rust extensions. +use cpython::{PyDict, PyModule, PyResult, Python}; + +/// Create the module, with `__package__` given from parent +pub fn init_module(py: Python, package: &str) -> PyResult { + let dotted_name = &format!("{}.debug", package); + let m = PyModule::new(py, dotted_name)?; + + m.add(py, "__package__", package)?; + m.add(py, "__doc__", "Rust debugging information")?; + + m.add(py, "re2_installed", cfg!(feature = "with-re2"))?; + + let sys = PyModule::import(py, "sys")?; + let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?; + sys_modules.set_item(py, dotted_name, &m)?; + + Ok(m) +} diff -r 4d1634e59f13 -r d4f19eb471ca rust/hg-cpython/src/lib.rs --- a/rust/hg-cpython/src/lib.rs Fri Jan 24 11:06:01 2020 +0100 +++ b/rust/hg-cpython/src/lib.rs Thu Mar 05 10:24:10 2020 +0100 @@ -30,6 +30,7 @@ #[macro_use] pub mod ref_sharing; pub mod dagops; +pub mod debug; pub mod dirstate; pub mod discovery; pub mod exceptions; @@ -47,6 +48,7 @@ let dotted_name: String = m.get(py, "__name__")?.extract(py)?; m.add(py, "ancestor", ancestors::init_module(py, &dotted_name)?)?; m.add(py, "dagop", dagops::init_module(py, &dotted_name)?)?; + m.add(py, "debug", debug::init_module(py, &dotted_name)?)?; m.add(py, "discovery", discovery::init_module(py, &dotted_name)?)?; m.add(py, "dirstate", dirstate::init_module(py, &dotted_name)?)?; m.add(py, "revlog", revlog::init_module(py, &dotted_name)?)?;