comparison rust/hg-cpython/src/debug.rs @ 44531:d4f19eb471ca

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
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 05 Mar 2020 10:24:10 +0100
parents
children 9f96beb9bafe
comparison
equal deleted inserted replaced
44530:4d1634e59f13 44531:d4f19eb471ca
1 // debug.rs
2 //
3 // Copyright 2020 Raphaël Gomès <rgomes@octobus.net>
4 //
5 // This software may be used and distributed according to the terms of the
6 // GNU General Public License version 2 or any later version.
7
8 //! Module to get debug information about Rust extensions.
9 use cpython::{PyDict, PyModule, PyResult, Python};
10
11 /// Create the module, with `__package__` given from parent
12 pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
13 let dotted_name = &format!("{}.debug", package);
14 let m = PyModule::new(py, dotted_name)?;
15
16 m.add(py, "__package__", package)?;
17 m.add(py, "__doc__", "Rust debugging information")?;
18
19 m.add(py, "re2_installed", cfg!(feature = "with-re2"))?;
20
21 let sys = PyModule::import(py, "sys")?;
22 let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
23 sys_modules.set_item(py, dotted_name, &m)?;
24
25 Ok(m)
26 }