use pyo3::prelude::*;
#[pymodule]
fn nautilus_pyo3(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
let sys = PyModule::import_bound(py, "sys")?;
let modules = sys.getattr("modules")?;
let sys_modules: &Bound<'_, PyAny> = modules.downcast()?;
let module_name = "nautilus_trader.core.nautilus_pyo3";
sys_modules.set_item(module_name, m)?;
let n = "core";
let submodule = pyo3::wrap_pymodule!(nautilus_core::python::core);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "common";
let submodule = pyo3::wrap_pymodule!(nautilus_common::python::common);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "cryptography";
let submodule = pyo3::wrap_pymodule!(nautilus_cryptography::python::cryptography);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "execution";
let submodule = pyo3::wrap_pymodule!(nautilus_execution::python::execution);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "model";
let submodule = pyo3::wrap_pymodule!(nautilus_model::python::model);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "indicators";
let submodule = pyo3::wrap_pymodule!(nautilus_indicators::python::indicators);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "infrastructure";
let submodule = pyo3::wrap_pymodule!(nautilus_infrastructure::python::infrastructure);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "network";
let submodule = pyo3::wrap_pymodule!(nautilus_network::python::network);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "persistence";
let submodule = pyo3::wrap_pymodule!(nautilus_persistence::python::persistence);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "serialization";
let submodule = pyo3::wrap_pymodule!(nautilus_serialization::python::serialization);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "test_kit";
let submodule = pyo3::wrap_pymodule!(nautilus_test_kit::python::test_kit);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "databento";
let submodule = pyo3::wrap_pymodule!(nautilus_databento::python::databento);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
let n = "tardis";
let submodule = pyo3::wrap_pymodule!(nautilus_tardis::python::tardis);
m.add_wrapped(submodule)?;
sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
re_export_module_attributes(m, n)?;
Ok(())
}
fn re_export_module_attributes(
parent_module: &Bound<'_, PyModule>,
submodule_name: &str,
) -> PyResult<()> {
let submodule = parent_module.getattr(submodule_name)?;
for item_name in submodule.dir()? {
let item_name_str: &str = item_name.extract()?;
if let Ok(attr) = submodule.getattr(item_name_str) {
parent_module.add(item_name_str, attr)?;
}
}
Ok(())
}