pykeramics/lib.rs
1/* Copyright 2024-2025 Joachim Metz <joachim.metz@gmail.com>
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may
5 * obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 * License for the specific language governing permissions and limitations
11 * under the License.
12 */
13
14use pyo3::prelude::*;
15use pyo3::types::PyDict;
16use pyo3::wrap_pymodule;
17
18mod datetime;
19mod vfs;
20
21/// Keramics Python module.
22#[pymodule]
23fn pykeramics(python: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
24 module.add("__version__", env!("CARGO_PKG_VERSION"))?;
25 module.add_wrapped(wrap_pymodule!(datetime::datetime))?;
26 module.add_wrapped(wrap_pymodule!(vfs::vfs))?;
27
28 let sys = PyModule::import(python, "sys")?;
29 let sys_modules: Bound<'_, PyDict> = sys.getattr("modules")?.downcast_into()?;
30 sys_modules.set_item("pykeramics.datetime", module.getattr("datetime")?)?;
31 sys_modules.set_item("pykeramics.vfs", module.getattr("vfs")?)?;
32
33 Ok(())
34}