Loading ARCHITECTURE.md +0 −5 Original line number Diff line number Diff line Loading @@ -9,17 +9,12 @@ - `xylem-lib` (Rust code) - Utility functions - Code for handling user input, ingesting configuration data, running workflows, etc... - `xylem-py` (Python library) - 🚧 Under construction - Export Rust code as Python library using [PyO3/Maturin](https://github.com/PyO3/maturin) - Export select `xylem-lib` functions as Python functions ## Diagram ```mermaid graph LR a[Xylem] --> b[xylem-cli/] a --> c[xylem-lib/] a --> d[xylem-py/] b --> e[CLI application] c --> f[Rust crate] d --> g[Python</br>package] Loading xylem-py/Cargo.tomldeleted 100644 → 0 +0 −15 Original line number Diff line number Diff line [package] name = "xylem-py" version.workspace = true authors.workspace = true description.workspace = true edition = "2021" [lib] name = "xylem" crate-type = ["cdylib"] [dependencies] xylem-lib = { path = "../xylem-lib" } pyo3 = { version = "0.22.2", features = ["abi3-py310", "extension-module"] } rand = "0.8.5" xylem-py/pyproject.tomldeleted 100644 → 0 +0 −7 Original line number Diff line number Diff line [build-system] requires = ["maturin>=1.0,<2.0"] build-backend = "maturin" [tool.maturin] # "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so) features = ["pyo3/extension-module"] No newline at end of file xylem-py/src/lib.rsdeleted 100644 → 0 +0 −42 Original line number Diff line number Diff line use xylem_lib::add_forward_slash as _add_forward_slash; use pyo3::prelude::*; use rand::Rng; use std::cmp::Ordering; use std::{io, path::PathBuf}; #[pyfunction] fn add_forward_slash(value: &str) -> String { let path = PathBuf::from(value); _add_forward_slash(path).into_os_string().into_string().unwrap() } #[pyfunction] fn guess_the_number() { println!("Guess the number!"); let secret_number = rand::thread_rng().gen_range(1..101); loop { println!("Please input your guess."); let mut guess = String::new(); io::stdin().read_line(&mut guess).expect("Failed to read line"); let guess: u32 = match guess.trim().parse() { | Ok(num) => num, | Err(_) => continue, }; println!("You guessed: {}", guess); match guess.cmp(&secret_number) { | Ordering::Less => println!("Too small!"), | Ordering::Greater => println!("Too big!"), | Ordering::Equal => { println!("You win!"); break; } } } } #[pymodule] fn xylem(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(add_forward_slash, m)?)?; m.add_function(wrap_pyfunction!(guess_the_number, m)?)?; Ok(()) } Loading
ARCHITECTURE.md +0 −5 Original line number Diff line number Diff line Loading @@ -9,17 +9,12 @@ - `xylem-lib` (Rust code) - Utility functions - Code for handling user input, ingesting configuration data, running workflows, etc... - `xylem-py` (Python library) - 🚧 Under construction - Export Rust code as Python library using [PyO3/Maturin](https://github.com/PyO3/maturin) - Export select `xylem-lib` functions as Python functions ## Diagram ```mermaid graph LR a[Xylem] --> b[xylem-cli/] a --> c[xylem-lib/] a --> d[xylem-py/] b --> e[CLI application] c --> f[Rust crate] d --> g[Python</br>package] Loading
xylem-py/Cargo.tomldeleted 100644 → 0 +0 −15 Original line number Diff line number Diff line [package] name = "xylem-py" version.workspace = true authors.workspace = true description.workspace = true edition = "2021" [lib] name = "xylem" crate-type = ["cdylib"] [dependencies] xylem-lib = { path = "../xylem-lib" } pyo3 = { version = "0.22.2", features = ["abi3-py310", "extension-module"] } rand = "0.8.5"
xylem-py/pyproject.tomldeleted 100644 → 0 +0 −7 Original line number Diff line number Diff line [build-system] requires = ["maturin>=1.0,<2.0"] build-backend = "maturin" [tool.maturin] # "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so) features = ["pyo3/extension-module"] No newline at end of file
xylem-py/src/lib.rsdeleted 100644 → 0 +0 −42 Original line number Diff line number Diff line use xylem_lib::add_forward_slash as _add_forward_slash; use pyo3::prelude::*; use rand::Rng; use std::cmp::Ordering; use std::{io, path::PathBuf}; #[pyfunction] fn add_forward_slash(value: &str) -> String { let path = PathBuf::from(value); _add_forward_slash(path).into_os_string().into_string().unwrap() } #[pyfunction] fn guess_the_number() { println!("Guess the number!"); let secret_number = rand::thread_rng().gen_range(1..101); loop { println!("Please input your guess."); let mut guess = String::new(); io::stdin().read_line(&mut guess).expect("Failed to read line"); let guess: u32 = match guess.trim().parse() { | Ok(num) => num, | Err(_) => continue, }; println!("You guessed: {}", guess); match guess.cmp(&secret_number) { | Ordering::Less => println!("Too small!"), | Ordering::Greater => println!("Too big!"), | Ordering::Equal => { println!("You win!"); break; } } } } #[pymodule] fn xylem(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(add_forward_slash, m)?)?; m.add_function(wrap_pyfunction!(guess_the_number, m)?)?; Ok(()) }