66from typing import List
77
88from rustimport import build_all , build_filepath , settings
9+ from rustimport .pre_processing import PyO3Template
910
1011rust_lib_template = """// rustimport:pyo3
1112
2122// #[pyfunction] and all structs annotated with #[pyclass].
2223//
2324//#[pymodule]
24- //fn {{EXTENSION_NAME}}(_py: Python, m: &PyModule) -> PyResult<()> {
25+ //fn {{EXTENSION_NAME}}(_py: Python, m: &Bound<'_, PyModule> ) -> PyResult<()> {
2526// m.add_function(wrap_pyfunction!(say_hello, m)?)?;
2627// Ok(())
2728//}
5455crate-type = ["cdylib"]
5556
5657[dependencies]
57- pyo3 = { version = "0.18.3 ", features = ["extension-module"] }
58+ pyo3 = { version = "{{PYO3_VERSION}} ", features = ["extension-module"] }
5859"""
5960
6061
@@ -75,7 +76,9 @@ def create_extension(name: str, cwd: str = '.'):
7576 with open (os .path .join (src_dir , 'lib.rs' ), 'w+' ) as f :
7677 f .write (rust_lib_template .replace ('{{EXTENSION_NAME}}' , name ))
7778 with open (os .path .join (path , 'Cargo.toml' ), 'w+' ) as f :
78- f .write (cargo_toml_template .replace ('{{EXTENSION_NAME}}' , name ))
79+ f .write (cargo_toml_template
80+ .replace ('{{EXTENSION_NAME}}' , name )
81+ .replace ('{{PYO3_VERSION}}' , PyO3Template .PYO3_VERSION ))
7982 with open (os .path .join (path , '.rustimport' ), 'w+' ) as f :
8083 f .write ("This is a marker-file to make this crate importable by rustimport." )
8184
0 commit comments