view rust/hg-pyo3/src/lib.rs @ 52870:c60f69556924

rust-pyo3: new module for conversions of HgPath and friends Same as `PyRevision`, the `PyHgPathRef` new-type wrapper is not a Python type, but it implements `IntoPyObject`, which will spare us tedious uses of `PyBytes::new`. The `paths_py_list` function is the the analog of `revs_py_list` for paths. There was one similar utility in `hg-cpython`, within the `dirstate::status` module. We feel it should be in a more global location, and have a name consistent with utilities for revisions. The `paths_pyiter_collect` function is similarly the analog of `revs_pyiter_collect`.
author Georges Racinet <georges.racinet@cloudcrane.io>
date Thu, 06 Feb 2025 11:18:28 +0100
parents d0c0ad938eb9
children a39680ec3e76
line wrap: on
line source

use pyo3::prelude::*;

mod ancestors;
mod dagops;
mod dirstate;
mod discovery;
mod exceptions;
mod node;
mod path;
mod revision;
mod revlog;
mod store;
mod transaction;
mod utils;

#[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()?;
    env_logger::init();

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