Skip to content

Commit

Permalink
uprev
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Nov 10, 2022
1 parent 7606c66 commit 131cf97
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 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 = "rtoml"
version = "0.8.0"
version = "0.9.0"
authors = ["Samuel Colvin <[email protected]>"]
edition = "2018"

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Actions Status](https://github.com/samuelcolvin/rtoml/workflows/CI/badge.svg)](https://github.com/samuelcolvin/rtoml/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)
[![Coverage](https://codecov.io/gh/samuelcolvin/rtoml/branch/main/graph/badge.svg)](https://codecov.io/gh/samuelcolvin/rtoml)
[![pypi](https://img.shields.io/pypi/v/rtoml.svg)](https://pypi.python.org/pypi/rtoml)
[![versions](https://img.shields.io/pypi/pyversions/rtoml.svg)](https://github.com/samuelcolvin/rtoml)
[![license](https://img.shields.io/github/license/samuelcolvin/rtoml.svg)](https://github.com/samuelcolvin/rtoml/blob/main/LICENSE)


Expand Down
5 changes: 3 additions & 2 deletions rtoml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from . import _rtoml

__all__ = 'VERSION', 'TomlParsingError', 'TomlSerializationError', 'load', 'loads', 'dumps', 'dump'
__all__ = '__version__', 'TomlParsingError', 'TomlSerializationError', 'load', 'loads', 'dumps', 'dump'

# VERSION is set in Cargo.toml
VERSION = _rtoml.VERSION
VERSION = _rtoml.__version__
__version__ = _rtoml.__version__
TomlParsingError = _rtoml.TomlParsingError
TomlSerializationError = _rtoml.TomlSerializationError

Expand Down
2 changes: 1 addition & 1 deletion rtoml/_rtoml.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

VERSION: str
__version__: str

def deserialize(toml: str) -> Any: ...
def serialize(obj: Any) -> str: ...
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod de;
mod py_type;
mod ser;

const VERSION: &str = env!("CARGO_PKG_VERSION");
create_exception!(_rtoml, TomlParsingError, PyValueError);
create_exception!(_rtoml, TomlSerializationError, PyValueError);

Expand Down Expand Up @@ -46,11 +45,24 @@ fn serialize_pretty(py: Python, obj: &PyAny) -> PyResult<String> {
}
}

pub fn get_version() -> String {
let version = env!("CARGO_PKG_VERSION").to_string();
// cargo uses "1.0-alpha1" etc. while python uses "1.0.0a1", this is not full compatibility,
// but it's good enough for now
// see https://docs.rs/semver/1.0.9/semver/struct.Version.html#method.parse for rust spec
// see https://peps.python.org/pep-0440/ for python spec
// it seems the dot after "alpha/beta" e.g. "-alpha.1" is not necessary, hence why this works
version.replace("-alpha", "a").replace("-beta", "b")
}

#[pymodule]
fn _rtoml(py: Python, m: &PyModule) -> PyResult<()> {
m.add("TomlParsingError", py.get_type::<TomlParsingError>())?;
m.add("TomlSerializationError", py.get_type::<TomlSerializationError>())?;
m.add("VERSION", VERSION)?;
let version = get_version();
m.add("__version__", version.clone())?;
// keep VERSION for compatibility
m.add("VERSION", version)?;
m.add_wrapped(wrap_pyfunction!(deserialize))?;
m.add_wrapped(wrap_pyfunction!(serialize))?;
m.add_wrapped(wrap_pyfunction!(serialize_pretty))?;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def test_example():


def test_version():
assert isinstance(rtoml.VERSION, str)
print('rtoml VERSION:', rtoml.VERSION)
assert isinstance(rtoml.__version__, str)
print('rtoml __version__:', rtoml.__version__)

0 comments on commit 131cf97

Please sign in to comment.