From c46a0efe5aa73f0acccfc0867a7be333d72d345f Mon Sep 17 00:00:00 2001 From: baseplate-admin <61817579+baseplate-admin@users.noreply.github.com> Date: Sun, 12 May 2024 15:37:48 +0600 Subject: [PATCH] Version should be string Thanks : https://github.com/emmett-framework/granian/blob/d500b49a3db1de380f0a1f022263066a79c77af1/src/lib.rs#L27-L44 --- Cargo.lock | 2 +- Cargo.toml | 2 +- pyproject.toml | 2 +- resvg_py.pyi | 5 +++-- src/rust/lib.rs | 11 ++++++++--- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4162ed..7a8ed30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "resvg_py" -version = "0.1.4" +version = "0.1.5" dependencies = [ "log", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index 4814221..3faf1dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "resvg_py" -version = "0.1.4" +version = "0.1.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/pyproject.toml b/pyproject.toml index c352425..a909cc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "resvg-py" -version = "0.1.4" +version = "0.1.5" description = "" authors = ["baseplate-admin <61817579+baseplate-admin@users.noreply.github.com>"] readme = "README.md" diff --git a/resvg_py.pyi b/resvg_py.pyi index 3722250..d073074 100644 --- a/resvg_py.pyi +++ b/resvg_py.pyi @@ -1,5 +1,8 @@ from typing import Literal + +__version__ : str + def svg_to_bytes( svg_string: str | None = None, svg_path: str | None = None, @@ -56,5 +59,3 @@ def svg_to_bytes( """ ... - -def version() -> str: ... diff --git a/src/rust/lib.rs b/src/rust/lib.rs index eca5883..f6cdc37 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -7,6 +7,7 @@ Based on use pyo3::prelude::*; use resvg; + #[derive(Clone, Copy, PartialEq, Debug)] enum FitTo { /// Keep original size. @@ -351,13 +352,17 @@ fn svg_to_bytes( #[pyfunction] #[pyo3(name = "version")] -fn version() -> PyResult { - Ok(env!("CARGO_PKG_VERSION").to_owned()) +fn get_version() -> &'static str { + static VERSION : std::sync::OnceLock = std::sync::OnceLock::new(); + + VERSION.get_or_init(||{ + env!("CARGO_PKG_VERSION").to_owned() + }) } /// A Python module implemented in Rust. #[pymodule] fn resvg_py(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add("__version__",get_version())?; m.add_function(wrap_pyfunction!(svg_to_bytes, m)?)?; - m.add_function(wrap_pyfunction!(version, m)?)?; Ok(()) }