Skip to content

Commit

Permalink
Version should be string
Browse files Browse the repository at this point in the history
  • Loading branch information
baseplate-admin committed May 12, 2024
1 parent 7abe6d8 commit c46a0ef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 3 additions & 2 deletions resvg_py.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Literal


__version__ : str

def svg_to_bytes(
svg_string: str | None = None,
svg_path: str | None = None,
Expand Down Expand Up @@ -56,5 +59,3 @@ def svg_to_bytes(
"""

...

def version() -> str: ...
11 changes: 8 additions & 3 deletions src/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Based on
use pyo3::prelude::*;
use resvg;


#[derive(Clone, Copy, PartialEq, Debug)]
enum FitTo {
/// Keep original size.
Expand Down Expand Up @@ -351,13 +352,17 @@ fn svg_to_bytes(

#[pyfunction]
#[pyo3(name = "version")]
fn version() -> PyResult<String> {
Ok(env!("CARGO_PKG_VERSION").to_owned())
fn get_version() -> &'static str {
static VERSION : std::sync::OnceLock<String> = 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(())
}

0 comments on commit c46a0ef

Please sign in to comment.