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