Skip to content

Commit

Permalink
Fix to work with latest PyO3
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrasser committed Oct 3, 2023
1 parent 2cf6d64 commit 53cba2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["maturin>=0.14,<0.15"]
requires = ["maturin~=1.3.0"]
build-backend = "maturin"

[project]
name = "pyoxipng"
requires-python = ">=3.7"
requires-python = ">=3.8"
version = "8.0.0"
description = "Python wrapper for multithreaded .png image file optimizer oxipng"
readme = "README.md"
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ create_exception!(oxipng, PngError, PyException);
/// Optimize the png file at the given input location. Optionally send it to the
/// given output location.
#[pyfunction]
#[pyo3(text_signature = "(input, output, **kwargs)")]
fn optimize(input: &PyAny, output: Option<&PyAny>, kwds: Option<&PyDict>) -> PyResult<()> {
#[pyo3(signature = (input, output=None, **kwargs))]
fn optimize(input: &PyAny, output: Option<&PyAny>, kwargs: Option<&PyDict>) -> PyResult<()> {
let inpath = PathBuf::from(input.str()?.to_str()?);
let outpath = if let Some(out) = output {
Some(PathBuf::from(out.str()?.to_str()?))
Expand All @@ -25,15 +25,15 @@ fn optimize(input: &PyAny, output: Option<&PyAny>, kwds: Option<&PyDict>) -> PyR
let inpath = op::InFile::Path(inpath);
let outpath = op::OutFile::Path(outpath);

op::optimize(&inpath, &outpath, &parse::parse_kw_opts(kwds)?)
op::optimize(&inpath, &outpath, &parse::parse_kw_opts(kwargs)?)
.or_else(|err| Err(PngError::new_err(parse::png_error_to_string(&err))))?;
Ok(())
}

#[pyfunction]
#[pyo3(text_signature = "(data, **kwargs)")]
fn optimize_from_memory(data: &PyBytes, kwds: Option<&PyDict>) -> PyResult<Py<PyBytes>> {
let output = op::optimize_from_memory(data.as_bytes(), &parse::parse_kw_opts(kwds)?)
#[pyo3(signature = (data, **kwargs))]
fn optimize_from_memory(data: &PyBytes, kwargs: Option<&PyDict>) -> PyResult<Py<PyBytes>> {
let output = op::optimize_from_memory(data.as_bytes(), &parse::parse_kw_opts(kwargs)?)
.or_else(|err| Err(PngError::new_err(parse::png_error_to_string(&err))))?;
Python::with_gil(|py| {
let bytes: Py<PyBytes> = PyBytes::new(py, &*output).into();
Expand Down

0 comments on commit 53cba2d

Please sign in to comment.