nautilus_common/python/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Python bindings from [PyO3](https://pyo3.rs).
17
18pub mod clock;
19pub mod custom;
20pub mod enums;
21pub mod handler;
22pub mod listener;
23pub mod logging;
24pub mod msgbus;
25pub mod signal;
26pub mod timer;
27pub mod xrate;
28
29use pyo3::prelude::*;
30
31/// Loaded as nautilus_pyo3.common
32///
33/// # Errors
34///
35/// Returns a `PyErr` if registering any module components fails.
36#[pymodule]
37pub fn common(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
38    m.add_class::<crate::custom::CustomData>()?;
39    m.add_class::<crate::signal::Signal>()?;
40    m.add_class::<crate::python::clock::TestClock_Py>()?;
41    m.add_class::<crate::python::clock::LiveClock_Py>()?;
42    m.add_class::<crate::msgbus::BusMessage>()?;
43    m.add_class::<crate::msgbus::MessageBus>()?;
44    m.add_class::<crate::msgbus::listener::MessageBusListener>()?;
45    m.add_class::<crate::python::handler::PythonMessageHandler>()?;
46    m.add_class::<crate::enums::ComponentState>()?;
47    m.add_class::<crate::enums::ComponentTrigger>()?;
48    m.add_class::<crate::enums::LogColor>()?;
49    m.add_class::<crate::enums::LogLevel>()?;
50    m.add_class::<crate::enums::LogFormat>()?;
51    m.add_class::<crate::logging::logger::LoggerConfig>()?;
52    m.add_class::<crate::logging::logger::LogGuard>()?;
53    m.add_class::<crate::logging::writer::FileWriterConfig>()?;
54    m.add_function(wrap_pyfunction!(logging::py_init_tracing, m)?)?;
55    m.add_function(wrap_pyfunction!(logging::py_init_logging, m)?)?;
56    m.add_function(wrap_pyfunction!(logging::py_logger_flush, m)?)?;
57    m.add_function(wrap_pyfunction!(logging::py_logger_log, m)?)?;
58    m.add_function(wrap_pyfunction!(logging::py_log_header, m)?)?;
59    m.add_function(wrap_pyfunction!(logging::py_log_sysinfo, m)?)?;
60    m.add_function(wrap_pyfunction!(
61        logging::py_logging_clock_set_static_mode,
62        m
63    )?)?;
64    m.add_function(wrap_pyfunction!(
65        logging::py_logging_clock_set_realtime_mode,
66        m
67    )?)?;
68    m.add_function(wrap_pyfunction!(
69        logging::py_logging_clock_set_static_time,
70        m
71    )?)?;
72    m.add_function(wrap_pyfunction!(xrate::py_get_exchange_rate, m)?)?;
73
74    Ok(())
75}