equal
deleted
inserted
replaced
|
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 } |