diff --git a/Cargo.lock b/Cargo.lock index 82683cc..86b3d8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,12 +128,6 @@ dependencies = [ "rust_decimal", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitvec" version = "1.0.1" @@ -253,7 +247,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets", ] [[package]] @@ -284,7 +278,7 @@ version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 2.0.58", @@ -435,12 +429,6 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -522,16 +510,6 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.21" @@ -574,29 +552,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets 0.48.5", -] - [[package]] name = "pest" version = "2.7.9" @@ -758,15 +713,13 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a8b1990bd018761768d5e608a13df8bd1ac5f678456e0f301bb93e5f3ea16b" +version = "0.22.0-dev" +source = "git+https://github.com/PyO3/pyo3#3e4b3c5c52e06d6003a4a7be200ad8feb21e50ad" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -776,9 +729,8 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "650dca34d463b6cdbdb02b1d71bfd6eb6b6816afc708faebb3bac1380ff4aef7" +version = "0.22.0-dev" +source = "git+https://github.com/PyO3/pyo3#3e4b3c5c52e06d6003a4a7be200ad8feb21e50ad" dependencies = [ "once_cell", "target-lexicon", @@ -786,9 +738,8 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a7da8fc04a8a2084909b59f29e1b8474decac98b951d77b80b26dc45f046ad" +version = "0.22.0-dev" +source = "git+https://github.com/PyO3/pyo3#3e4b3c5c52e06d6003a4a7be200ad8feb21e50ad" dependencies = [ "libc", "pyo3-build-config", @@ -796,9 +747,8 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8a199fce11ebb28e3569387228836ea98110e43a804a530a9fd83ade36d513" +version = "0.22.0-dev" +source = "git+https://github.com/PyO3/pyo3#3e4b3c5c52e06d6003a4a7be200ad8feb21e50ad" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -808,11 +758,10 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fbbfd7eb553d10036513cb122b888dcd362a945a00b06c165f2ab480d4cc3b" +version = "0.22.0-dev" +source = "git+https://github.com/PyO3/pyo3#3e4b3c5c52e06d6003a4a7be200ad8feb21e50ad" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "pyo3-build-config", "quote", @@ -864,15 +813,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags", -] - [[package]] name = "regex" version = "1.10.4" @@ -962,12 +902,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "seahash" version = "4.1.0" @@ -1022,12 +956,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - [[package]] name = "strsim" version = "0.11.1" @@ -1255,7 +1183,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets", ] [[package]] @@ -1264,22 +1192,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1288,93 +1201,51 @@ version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.4" diff --git a/Cargo.toml b/Cargo.toml index f3a6ace..39313f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,8 @@ env_logger = "0.11.0" log = "0.4.20" pest = "2.7.6" pest_derive = "2.7.6" -pyo3 = "0.21.0" +# pyo3 = "0.21.0" +pyo3 = { git = "https://github.com/PyO3/pyo3" } rust_decimal = "1.33.1" [lib] diff --git a/python/bean_rs/bean_rs.pyi b/python/bean_rs/bean_rs.pyi index 3231d7a..c4ea311 100644 --- a/python/bean_rs/bean_rs.pyi +++ b/python/bean_rs/bean_rs.pyi @@ -1,4 +1,4 @@ -import datetime +from bean_rs._bean_rs import Directive class Options: title: str @@ -7,9 +7,6 @@ class Options: class BeanError(Exception): pass -class Directive: - date: datetime.date - class Ledger: dirs: list[Directive] errs: list[BeanError] diff --git a/python/tests/test_load.py b/python/tests/test_load.py index 97a1bc2..53fe1b8 100644 --- a/python/tests/test_load.py +++ b/python/tests/test_load.py @@ -1,6 +1,13 @@ from bean_rs import load +from bean_rs._bean_rs import Transaction def test_load() -> None: ledger = load("example.bean") assert ledger.opts.operating_currency == "GBP" + for d in ledger.dirs: + match d[0]: # each element in enum is single-element tuple + case Transaction(payee='"Shop"', narration=narration): + assert narration == '"More food"' + case _: + pass diff --git a/src/data.rs b/src/data.rs index 0cf689f..dc3ae43 100644 --- a/src/data.rs +++ b/src/data.rs @@ -116,6 +116,7 @@ impl Amount { } } +#[pyclass] #[derive(Clone, Debug, PartialEq)] pub struct ConfigCustom { pub date: NaiveDate, @@ -161,6 +162,7 @@ impl fmt::Display for Metadata { } } +#[pyclass] #[derive(Clone, Debug, PartialEq)] pub struct Commodity { pub date: NaiveDate, @@ -211,6 +213,7 @@ impl fmt::Display for Commodity { } } +#[pyclass] #[derive(Debug, Clone, PartialEq)] pub struct Open { pub date: NaiveDate, @@ -267,6 +270,7 @@ impl fmt::Display for Open { } } +#[pyclass] #[derive(Debug, Clone, PartialEq)] pub struct Close { pub date: NaiveDate, @@ -302,6 +306,7 @@ impl fmt::Display for Close { } } +#[pyclass] #[derive(Debug, Clone, PartialEq)] pub struct Balance { pub date: NaiveDate, @@ -342,6 +347,7 @@ impl fmt::Display for Balance { } } +#[pyclass] #[derive(Debug, Clone, PartialEq)] pub struct Pad { pub date: NaiveDate, @@ -381,6 +387,7 @@ impl fmt::Display for Pad { } } +#[pyclass] #[derive(Clone, Debug, PartialEq)] pub struct Price { pub date: NaiveDate, @@ -421,6 +428,7 @@ impl fmt::Display for Price { } } +#[pyclass] #[derive(Clone, Debug, PartialEq)] pub struct Document { pub date: NaiveDate, @@ -460,6 +468,7 @@ impl fmt::Display for Document { } } +#[pyclass] #[derive(Clone, Debug, PartialEq)] pub struct Note { pub date: NaiveDate, @@ -499,6 +508,7 @@ impl fmt::Display for Note { } } +#[pyclass] #[derive(Clone, Debug, PartialEq)] pub struct Query { pub date: NaiveDate, @@ -588,11 +598,14 @@ impl fmt::Display for Posting { } } +#[pyclass] #[derive(Debug, Clone, PartialEq)] pub struct Transaction { pub date: NaiveDate, pub ty: String, + #[pyo3(get)] pub payee: Option, + #[pyo3(get)] pub narration: String, pub tag: Option, // TODO can have multiple pub link: Option, // TODO can have multiple @@ -734,6 +747,7 @@ impl fmt::Display for Transaction { /// The "ledger" is made up of Directives /// Most operations will be done by looping through a Vec of these +#[pyclass] #[derive(Clone, Debug)] pub enum Directive { ConfigCustom(ConfigCustom), diff --git a/src/ledger.rs b/src/ledger.rs index c0e1a22..8f25efc 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -5,6 +5,7 @@ use crate::error::BeanError; #[pyclass] pub struct Ledger { + #[pyo3(get)] pub dirs: Vec, #[pyo3(get)] pub errs: Vec, diff --git a/src/lib.rs b/src/lib.rs index d3131b6..89ce013 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ pub mod utils; use pyo3::prelude::*; -use data::AccBal; +use data::{AccBal, Directive, Transaction}; use crate::error::BeanError; use crate::ledger::Ledger; @@ -55,5 +55,7 @@ fn py_load(path: &str) -> Ledger { #[pymodule] fn _bean_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(py_load, m)?)?; + m.add_class::()?; + m.add_class::()?; Ok(()) }