Skip to content

Commit

Permalink
use final PyO3 0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jun 24, 2024
1 parent e1b18fe commit c524a22
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 59 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resolver = "2"

[workspace.package]
authors = ["Samuel Colvin <samuel@pydantic.dev>"]
version = "0.4.2"
version = "0.5.0"
edition = "2021"
license = "MIT"
keywords = ["JSON", "parsing", "deserialization", "iter"]
Expand All @@ -30,7 +30,3 @@ debug = true
[workspace.dependencies]
pyo3 = { version = "0.22.0", default-features = false}
pyo3-build-config = { version = "0.22.0", default-features = false}

[patch.crates-io]
pyo3 = { git = "https://github.com/pyo3/pyo3", branch = "release-0.22" }
pyo3-build-config = { git = "https://github.com/pyo3/pyo3", branch = "release-0.22" }
2 changes: 1 addition & 1 deletion crates/jiter-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = {workspace = true}
repository = {workspace = true}

[dependencies]
pyo3 = { workspace = true, default-features = true, features = ["num-bigint", "auto-initialize"] }
pyo3 = { workspace = true, default-features = true, features = ["num-bigint"] }
jiter = { path = "../jiter", features = ["python"] }

[features]
Expand Down
107 changes: 54 additions & 53 deletions crates/jiter-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,6 @@ use std::sync::OnceLock;

use pyo3::prelude::*;

use jiter::{map_json_error, LosslessFloat, PartialMode, PythonParse, StringCacheMode};

#[allow(clippy::fn_params_excessive_bools)]
#[pyfunction(
signature = (
json_data,
/,
*,
allow_inf_nan=true,
cache_mode=StringCacheMode::All,
partial_mode=PartialMode::Off,
catch_duplicate_keys=false,
lossless_floats=false,
)
)]
pub fn from_json<'py>(
py: Python<'py>,
json_data: &[u8],
allow_inf_nan: bool,
cache_mode: StringCacheMode,
partial_mode: PartialMode,
catch_duplicate_keys: bool,
lossless_floats: bool,
) -> PyResult<Bound<'py, PyAny>> {
let parse_builder = PythonParse {
allow_inf_nan,
cache_mode,
partial_mode,
catch_duplicate_keys,
lossless_floats,
};
parse_builder
.python_parse(py, json_data)
.map_err(|e| map_json_error(json_data, &e))
}

pub fn get_jiter_version() -> &'static str {
static JITER_VERSION: OnceLock<String> = OnceLock::new();

Expand All @@ -52,23 +16,60 @@ pub fn get_jiter_version() -> &'static str {
})
}

#[pyfunction]
pub fn cache_clear(py: Python<'_>) {
jiter::cache_clear(py);
}
#[pymodule]
mod jiter_python {
use super::*;

#[pyfunction]
pub fn cache_usage(py: Python<'_>) -> usize {
jiter::cache_usage(py)
}
use jiter::{map_json_error, LosslessFloat, PartialMode, PythonParse, StringCacheMode};

#[pymodule]
#[pyo3(name = "jiter")]
fn jiter_python(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__version__", get_jiter_version())?;
m.add_function(wrap_pyfunction!(from_json, m)?)?;
m.add_function(wrap_pyfunction!(cache_clear, m)?)?;
m.add_function(wrap_pyfunction!(cache_usage, m)?)?;
m.add_class::<LosslessFloat>()?;
Ok(())
#[allow(clippy::fn_params_excessive_bools)]
#[pyfunction(
signature = (
json_data,
/,
*,
allow_inf_nan=true,
cache_mode=StringCacheMode::All,
partial_mode=PartialMode::Off,
catch_duplicate_keys=false,
lossless_floats=false,
)
)]
pub fn from_json<'py>(
py: Python<'py>,
json_data: &[u8],
allow_inf_nan: bool,
cache_mode: StringCacheMode,
partial_mode: PartialMode,
catch_duplicate_keys: bool,
lossless_floats: bool,
) -> PyResult<Bound<'py, PyAny>> {
let parse_builder = PythonParse {
allow_inf_nan,
cache_mode,
partial_mode,
catch_duplicate_keys,
lossless_floats,
};
parse_builder
.python_parse(py, json_data)
.map_err(|e| map_json_error(json_data, &e))
}

#[pyfunction]
pub fn cache_clear(py: Python<'_>) {
jiter::cache_clear(py);
}

#[pyfunction]
pub fn cache_usage(py: Python<'_>) -> usize {
jiter::cache_usage(py)
}

#[pymodule_init]
fn init_jiter_python(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("__version__", get_jiter_version())?;
m.add_class::<LosslessFloat>()?;
Ok(())
}
}

0 comments on commit c524a22

Please sign in to comment.