rust/hg-pyo3/src/lib.rs
author Georges Racinet <georges.racinet@cloudcrane.io>
Fri, 20 Dec 2024 20:40:09 +0100
changeset 52774 0f9ed7e7a71b
parent 52531 4c9e31984b3a
child 52775 264047bf4b9b
permissions -rw-r--r--
rust-pyo3: make mercurial.pyo3_rustext a proper package This was not necessary with rust-cpython, and gets reflected in `__name__` immediately.

use pyo3::prelude::*;

mod ancestors;
mod convert_cpython;
mod dagops;
mod exceptions;
mod revision;
mod util;

#[pymodule]
fn pyo3_rustext(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add("__package__", "mercurial")?;
    m.add(
        "__doc__",
        "Mercurial core concepts - Rust implementation exposed via PyO3",
    )?;
    let dotted_name: String = m.getattr("__name__")?.extract()?;

    m.add_submodule(&ancestors::init_module(py, &dotted_name)?)?;
    m.add_submodule(&dagops::init_module(py, &dotted_name)?)?;
    m.add("GraphError", py.get_type::<exceptions::GraphError>())?;
    Ok(())
}