diff --git a/.github/workflows/static-checks.yml b/.github/workflows/static-checks.yml index 2ec8be7..002530c 100644 --- a/.github/workflows/static-checks.yml +++ b/.github/workflows/static-checks.yml @@ -54,7 +54,7 @@ jobs: run: cargo fmt --check - name: Run clippy - run: cargo clippy --no-default-features -- -D warnings + run: cargo clippy --all-targets --no-default-features -- -D warnings cargo-deny: name: Cargo Deny diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 965fe27..45bc04e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,6 +39,22 @@ repos: entry: uv run --frozen --offline lint-imports language: system pass_filenames: false + - repo: local + hooks: + - id: cargo-fmt + name: cargo-fmt + always_run: true + entry: uv run --frozen cargo fmt --check + language: system + pass_filenames: false + - repo: local + hooks: + - id: clippy + name: clippy + always_run: true + entry: uv run --frozen cargo clippy --all-targets --no-default-features -- -D warnings + language: system + pass_filenames: false - repo: https://github.com/codespell-project/codespell rev: v2.4.2 hooks: diff --git a/src/convert.rs b/src/convert.rs index faf1ffd..b4576ed 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -111,8 +111,8 @@ mod tests { #[test] fn test_py_to_yaml_none() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let none = py.None().into_bound(py); let val = py_to_yaml_value(&none).unwrap(); assert_eq!(val, Value::Null); @@ -121,8 +121,8 @@ mod tests { #[test] fn test_py_to_yaml_bool() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let t = true.into_pyobject(py).unwrap(); assert_eq!(py_to_yaml_value(t.as_any()).unwrap(), Value::Bool(true)); let f = false.into_pyobject(py).unwrap(); @@ -132,8 +132,8 @@ mod tests { #[test] fn test_py_to_yaml_int() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let i = 42i64.into_pyobject(py).unwrap().into_any(); let val = py_to_yaml_value(&i).unwrap(); assert_eq!(val, Value::Number(42.into())); @@ -142,8 +142,8 @@ mod tests { #[test] fn test_py_to_yaml_large_unsigned_int() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { // i64::MAX + 1 is a valid u64 but overflows i64 let large = (i64::MAX as u64 + 1).into_pyobject(py).unwrap().into_any(); let val = py_to_yaml_value(&large).unwrap(); @@ -156,12 +156,12 @@ mod tests { #[test] fn test_py_to_yaml_float_finite() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { - let f = 3.14f64.into_pyobject(py).unwrap().into_any(); + pyo3::Python::initialize(); + Python::attach(|py| { + let f = 3.15f64.into_pyobject(py).unwrap().into_any(); let val = py_to_yaml_value(&f).unwrap(); match val { - Value::Number(n) => assert_eq!(n.as_f64().unwrap(), 3.14), + Value::Number(n) => assert_eq!(n.as_f64().unwrap(), 3.15), _ => panic!("expected Number"), } }); @@ -169,8 +169,8 @@ mod tests { #[test] fn test_py_to_yaml_float_nan() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let nan = f64::NAN.into_pyobject(py).unwrap().into_any(); let val = py_to_yaml_value(&nan).unwrap(); match val { @@ -182,8 +182,8 @@ mod tests { #[test] fn test_py_to_yaml_float_inf() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let inf = f64::INFINITY.into_pyobject(py).unwrap().into_any(); let val = py_to_yaml_value(&inf).unwrap(); match val { @@ -195,8 +195,8 @@ mod tests { #[test] fn test_py_to_yaml_float_neg_inf() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let neg_inf = f64::NEG_INFINITY.into_pyobject(py).unwrap().into_any(); let val = py_to_yaml_value(&neg_inf).unwrap(); match val { @@ -211,8 +211,8 @@ mod tests { #[test] fn test_py_to_yaml_string() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let s = "hello".into_pyobject(py).unwrap().into_any(); assert_eq!(py_to_yaml_value(&s).unwrap(), Value::String("hello".into())); }); @@ -220,9 +220,9 @@ mod tests { #[test] fn test_py_to_yaml_list() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { - let list = PyList::new(py, &[1i64, 2, 3]).unwrap(); + pyo3::Python::initialize(); + Python::attach(|py| { + let list = PyList::new(py, [1i64, 2, 3]).unwrap(); let val = py_to_yaml_value(list.as_any()).unwrap(); assert_eq!( val, @@ -237,8 +237,8 @@ mod tests { #[test] fn test_py_to_yaml_dict() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let dict = PyDict::new(py); dict.set_item("key", "value").unwrap(); let val = py_to_yaml_value(dict.as_any()).unwrap(); @@ -250,8 +250,8 @@ mod tests { #[test] fn test_py_to_yaml_unsupported_type_rejected() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let set = py.eval(pyo3::ffi::c_str!("set()"), None, None).unwrap(); assert!(py_to_yaml_value(&set).is_err()); }); @@ -259,8 +259,8 @@ mod tests { #[test] fn test_yaml_to_py_null() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let obj = yaml_value_to_py(py, &Value::Null).unwrap(); assert!(obj.bind(py).is_none()); }); @@ -268,8 +268,8 @@ mod tests { #[test] fn test_yaml_to_py_bool() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let obj = yaml_value_to_py(py, &Value::Bool(true)).unwrap(); assert!(obj.extract::(py).unwrap()); }); @@ -277,8 +277,8 @@ mod tests { #[test] fn test_yaml_to_py_number_i64() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let obj = yaml_value_to_py(py, &Value::Number(42.into())).unwrap(); assert_eq!(obj.extract::(py).unwrap(), 42); }); @@ -286,8 +286,8 @@ mod tests { #[test] fn test_yaml_to_py_string() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let obj = yaml_value_to_py(py, &Value::String("hello".into())).unwrap(); assert_eq!(obj.extract::(py).unwrap(), "hello"); }); @@ -295,8 +295,8 @@ mod tests { #[test] fn test_yaml_to_py_sequence() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let seq = Value::Sequence(vec![Value::Number(1.into()), Value::Number(2.into())]); let obj = yaml_value_to_py(py, &seq).unwrap(); let list = obj.extract::>(py).unwrap(); @@ -306,8 +306,8 @@ mod tests { #[test] fn test_yaml_to_py_tagged_strips_tag() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let tagged = Value::Tagged(Box::new(serde_yaml::value::TaggedValue { tag: serde_yaml::value::Tag::new("!custom"), value: Value::String("inner".into()), diff --git a/src/types.rs b/src/types.rs index 35401a7..0cc74df 100644 --- a/src/types.rs +++ b/src/types.rs @@ -268,8 +268,8 @@ mod tests { #[test] fn test_route_negative_int_error_message() { - pyo3::prepare_freethreaded_python(); - Python::with_gil(|py| { + pyo3::Python::initialize(); + Python::attach(|py| { let neg = (-1i64).into_pyobject(py).unwrap().into_any(); let parts = vec![neg]; let list = pyo3::types::PyList::new(py, &parts).unwrap();