diff mbox series

[2/3] lib/oeqa/files/maturin: update guessing_game

Message ID 81cc096296fc24445357b353a4c73435e268001c.1769028980.git.tim.orling@konsulko.com
State New
Headers show
Series [1/3] python3-maturin: upgrade 1.10.2 -> 1.11.5 | expand

Commit Message

Tim Orling Jan. 21, 2026, 9:07 p.m. UTC
From: Tim Orling <tim.orling@konsulko.com>

Update to include changes in upstream Maturin Tutorial [1]
and for newer Rust and Python.

Cargo.toml:
* version: 0.1.0 -> 0.3.0 (to align with [2])
* edition: 2021 -> 2024
* Dependencies:
  - rand: 0.8.5 -> 0.9.0
  - pyo3: 0.21.2 -> 0.27.2
  - abi3-py38 -> abi3-py39 (Python 3.8 reached EOL in October 2024)

pyproject.toml:
* restrict maturin to >=1.7 to ensure PyO3 27.0+ and python 3.13+ support

src/lib.rs:
* rand 0.9 API change: rand::thread_rng() was removed. Use rand::rng() or
  the convenience function rand::random_range().
* PyO3 0.27 has breaking API changes from 0.21. The #[pymodule] function
  signature changed from fn module_name(py: Python, m: &PyModule) to
  fn module_name(m: &Bound<'_, PyModule>).

With help from Claude.ai

[1] https://www.maturin.rs/tutorial.html
[2] https://github.com/moto-timo/guessing-game/releases/tag/v0.3.0

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 meta/lib/oeqa/files/maturin/guessing-game/Cargo.toml | 12 ++++++------
 .../oeqa/files/maturin/guessing-game/pyproject.toml  |  2 +-
 meta/lib/oeqa/files/maturin/guessing-game/src/lib.rs |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/files/maturin/guessing-game/Cargo.toml b/meta/lib/oeqa/files/maturin/guessing-game/Cargo.toml
index a78ada2593..5c0c06db4b 100644
--- a/meta/lib/oeqa/files/maturin/guessing-game/Cargo.toml
+++ b/meta/lib/oeqa/files/maturin/guessing-game/Cargo.toml
@@ -1,7 +1,7 @@ 
 [package]
 name = "guessing-game"
-version = "0.1.0"
-edition = "2021"
+version = "0.3.0"
+edition = "2024"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
@@ -11,10 +11,10 @@  name = "guessing_game"
 crate-type = ["cdylib"]
 
 [dependencies]
-rand = "0.8.4"
+rand = "0.9.0"
 
 [dependencies.pyo3]
-version = "0.24.1"
-# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8
-features = ["abi3-py38"]
+version = "0.27.2"
+# "abi3-py39" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.9
+features = ["abi3-py39"]
 
diff --git a/meta/lib/oeqa/files/maturin/guessing-game/pyproject.toml b/meta/lib/oeqa/files/maturin/guessing-game/pyproject.toml
index ff35abc472..ecd34372a5 100644
--- a/meta/lib/oeqa/files/maturin/guessing-game/pyproject.toml
+++ b/meta/lib/oeqa/files/maturin/guessing-game/pyproject.toml
@@ -1,5 +1,5 @@ 
 [build-system]
-requires = ["maturin>=1.0,<2.0"]
+requires = ["maturin>=1.7,<2.0"]
 build-backend = "maturin"
 
 [tool.maturin]
diff --git a/meta/lib/oeqa/files/maturin/guessing-game/src/lib.rs b/meta/lib/oeqa/files/maturin/guessing-game/src/lib.rs
index 6828466ed1..0c757c291f 100644
--- a/meta/lib/oeqa/files/maturin/guessing-game/src/lib.rs
+++ b/meta/lib/oeqa/files/maturin/guessing-game/src/lib.rs
@@ -7,7 +7,7 @@  use std::io;
 fn guess_the_number() {
     println!("Guess the number!");
 
-    let secret_number = rand::thread_rng().gen_range(1..101);
+    let secret_number = rand::rng().random_range(1..101);
 
     loop {
         println!("Please input your guess.");
@@ -40,7 +40,7 @@  fn guess_the_number() {
 /// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
 /// import the module.
 #[pymodule]
-fn guessing_game(_py: Python, m: &PyModule) -> PyResult<()> {
+fn guessing_game(m: &Bound<'_, PyModule>) -> PyResult<()> {
     m.add_function(wrap_pyfunction!(guess_the_number, m)?)?;
 
     Ok(())