rust/hg-cpython/src/debug.rs
author Georges Racinet <georges.racinet@octobus.net>
Wed, 18 Oct 2023 19:54:18 +0200
changeset 51196 44fbb7dfb563
parent 44870 9f96beb9bafe
permissions -rw-r--r--
rust-index: renamed nodemap error function for rev not in index The function name was misleading, as the error wording mentions the nodemap, hence would not be appropriate for missing revisions not related to a nodemap lookup.

// debug.rs
//
// Copyright 2020 Raphaël Gomès <rgomes@octobus.net>
//
// 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<PyModule> {
    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")?;

    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)
}