view rust/hg-cpython/src/debug.rs @ 51466:a43a6d4b3be6 stable

rust-index: don't use mutable borrow for head-diff computation It does not needs to mutate the index. This is one of the two suspects of RuntimeError being thrown during push.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 05 Mar 2024 15:07:04 +0100
parents 9f96beb9bafe
children
line wrap: on
line source

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