UPDATE: Adds python bindings (#90)

* UPDATE: Adds python bindings

Exclude pyroncalc and wasm from test coverage
This commit is contained in:
Nicolás Hatcher Andrés
2024-09-21 11:58:50 +02:00
committed by GitHub
parent 00b5b65588
commit 11df4a55c7
18 changed files with 2049 additions and 14 deletions

2
bindings/python/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
target/*
venv/*

884
bindings/python/Cargo.lock generated Normal file
View File

@@ -0,0 +1,884 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bumpalo"
version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bzip2"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8"
dependencies = [
"bzip2-sys",
"libc",
]
[[package]]
name = "bzip2-sys"
version = "0.1.11+1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets",
]
[[package]]
name = "chrono-tz"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbc529705a6e0028189c83f0a5dd9fb214105116f7e3c0eeab7ff0369766b0d1"
dependencies = [
"chrono",
"chrono-tz-build",
"phf",
]
[[package]]
name = "chrono-tz-build"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9998fb9f7e9b2111641485bf8beb32f92945f97f92a3d061f744cfef335f751"
dependencies = [
"parse-zoneinfo",
"phf",
"phf_codegen",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "crc32fast"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "flate2"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]]
name = "getrandom"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "iana-time-zone"
version = "0.1.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "indoc"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "ironcalc"
version = "0.1.0"
dependencies = [
"chrono",
"ironcalc_base",
"itertools",
"roxmltree",
"serde",
"serde_json",
"thiserror",
"zip",
]
[[package]]
name = "ironcalc_base"
version = "0.1.0"
dependencies = [
"chrono",
"chrono-tz",
"js-sys",
"once_cell",
"rand",
"regex",
"ryu",
"serde",
"serde_json",
"serde_repr",
]
[[package]]
name = "itertools"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "js-sys"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[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.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
[[package]]
name = "miniz_oxide"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
dependencies = [
"adler",
]
[[package]]
name = "num-traits"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]]
name = "parse-zoneinfo"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41"
dependencies = [
"regex",
]
[[package]]
name = "phf"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [
"phf_shared",
]
[[package]]
name = "phf_codegen"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
dependencies = [
"phf_generator",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_shared"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
dependencies = [
"siphasher",
]
[[package]]
name = "pkg-config"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "pyo3"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e681a6cfdc4adcc93b4d3cf993749a4552018ee0a9b65fc0ccfad74352c72a38"
dependencies = [
"cfg-if",
"indoc",
"libc",
"memoffset",
"parking_lot",
"pyo3-build-config",
"pyo3-ffi",
"pyo3-macros",
"unindent",
]
[[package]]
name = "pyo3-build-config"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "076c73d0bc438f7a4ef6fdd0c3bb4732149136abd952b110ac93e4edb13a6ba5"
dependencies = [
"once_cell",
"target-lexicon",
]
[[package]]
name = "pyo3-ffi"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e53cee42e77ebe256066ba8aa77eff722b3bb91f3419177cf4cd0f304d3284d9"
dependencies = [
"libc",
"pyo3-build-config",
]
[[package]]
name = "pyo3-macros"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfeb4c99597e136528c6dd7d5e3de5434d1ceaf487436a3f03b2d56b6fc9efd1"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
"quote",
"syn 1.0.109",
]
[[package]]
name = "pyo3-macros-backend"
version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "947dc12175c254889edc0c02e399476c2f652b4b9ebd123aa655c224de259536"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "pyroncalc"
version = "0.1.0"
dependencies = [
"ironcalc",
"pyo3",
"serde",
"serde_json",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "roxmltree"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf7d7b1ea646d380d0e8153158063a6da7efe30ddbf3184042848e3f8a6f671"
dependencies = [
"xmlparser",
]
[[package]]
name = "ryu"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "serde_json"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_repr"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "smallvec"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "target-lexicon"
version = "0.12.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a"
[[package]]
name = "thiserror"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
]
[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unindent"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.39",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.39",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"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_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[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_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[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_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "xmlparser"
version = "0.13.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4"
[[package]]
name = "zip"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815"
dependencies = [
"byteorder",
"bzip2",
"crc32fast",
"flate2",
"thiserror",
"time",
]

View File

@@ -0,0 +1,24 @@
[package]
name = "pyroncalc"
version = "0.1.2"
edition = "2021"
[lib]
name = "ironcalc"
crate-type = ["cdylib"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
xlsx = { package= "ironcalc", path = "../../xlsx", version = "0.2.0" }
pyo3 = { version = "0.22.3", features = ["extension-module"] }
[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
[tool.maturin]
features = ["pyo3/extension-module"]

View File

@@ -0,0 +1,191 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2023 EqualTo GmbH, 2023 Nicolás Hatcher
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) 2023 EqualTo GmbH, 2023 Nicolás Hatcher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

31
bindings/python/README.md Normal file
View File

@@ -0,0 +1,31 @@
# IronCalc python bindings
With IronCalc you can create, read and manipulate xlsx files.
You can manage sheets, add, remove, delete rename.
You can add cell values, retrieve them and most importantly you can evaluate spreadsheets.
## Installation
```bash
pip install ironcalc
```
## Compile and test
To compile this and test it:
```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install maturin
$ maturin develop
$ cd examples
examples $ python example.py
```
From there if you use `python` you can `import ironcalc`. You can either create a new file, read it from a JSON string or import from Excel.
Hopefully the API is straightforward.

View File

@@ -0,0 +1,14 @@
project = 'IronCalc'
author = 'Nicolás Hatcher'
release = '0.1'
version = '0.1.2'
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon']
templates_path = ['_templates']
exclude_patterns = []
html_theme = 'alabaster'

View File

@@ -0,0 +1,7 @@
Welcome to ProjectName's documentation!
======================================
.. toctree::
:maxdepth: 2
:caption: Contents:

View File

@@ -0,0 +1,36 @@
[project]
name = "ironcalc"
version = "0.1.2"
description = "Create, edit and evaluate Excel spreadsheets"
requires-python = ">=3.10"
keywords = [
"xlsx",
"spreadsheet",
]
classifiers = [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: Apache Software License",
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Office/Business :: Financial :: Spreadsheet",
]
authors = [
{ name = "Nicolás Hatcher", email = "nicolas@theuniverse.today" },
]
[project.urls]
Homepage = "https://www.ironcalc.com/"
Source = "https://github.com/ironcalc/ironcalc"
Tracker = "https://github.com/ironcalc/ironcalc/issues"
[build-system]
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"
[tool.maturin]
features = ["pyo3/extension-module"]

259
bindings/python/src/lib.rs Normal file
View File

@@ -0,0 +1,259 @@
use pyo3::exceptions::PyException;
use pyo3::{create_exception, prelude::*, wrap_pyfunction};
use types::{PySheetProperty, PyStyle};
use xlsx::base::types::Style;
use xlsx::base::Model;
use xlsx::export::{save_to_icalc, save_to_xlsx};
use xlsx::import;
mod types;
create_exception!(_ironcalc, WorkbookError, PyException);
/// This is a model implementing the 'raw' API
#[pyclass]
pub struct PyModel {
model: Model,
}
#[pymethods]
impl PyModel {
/// Saves the model to an xlsx file
pub fn save_to_xlsx(&self, file: &str) -> PyResult<()> {
save_to_xlsx(&self.model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
}
/// Saves the model to file in the internal binary ic format
pub fn save_to_icalc(&self, file: &str) -> PyResult<()> {
save_to_icalc(&self.model, file).map_err(|e| WorkbookError::new_err(e.to_string()))
}
/// Evaluates the workbook
pub fn evaluate(&mut self) {
self.model.evaluate()
}
// Set values
/// Set an input
pub fn set_user_input(
&mut self,
sheet: u32,
row: i32,
column: i32,
value: &str,
) -> PyResult<()> {
self.model
.set_user_input(sheet, row, column, value.to_string())
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn clear_cell_contents(&mut self, sheet: u32, row: i32, column: i32) -> PyResult<()> {
self.model
.cell_clear_contents(sheet, row, column)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
// Get values
/// Get formatted value
pub fn get_formatted_cell_value(&self, sheet: u32, row: i32, column: i32) -> PyResult<String> {
self.model
.get_formatted_cell_value(sheet, row, column)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
// Set styles
pub fn set_cell_style(
&mut self,
sheet: u32,
row: i32,
column: i32,
py_style: &PyStyle,
) -> PyResult<()> {
let style: Style = py_style.into();
self.model
.set_cell_style(sheet, row, column, &style)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
// Get styles
pub fn get_cell_style(&self, sheet: u32, row: i32, column: i32) -> PyResult<PyStyle> {
let style = self
.model
.get_style_for_cell(sheet, row, column)
.map_err(|e| WorkbookError::new_err(e.to_string()))?;
Ok(style.into())
}
// column widths, row heights
// insert/delete rows/columns
pub fn insert_rows(&mut self, sheet: u32, row: i32, row_count: i32) -> PyResult<()> {
self.model
.insert_rows(sheet, row, row_count)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn insert_columns(&mut self, sheet: u32, column: i32, column_count: i32) -> PyResult<()> {
self.model
.insert_columns(sheet, column, column_count)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn delete_rows(&mut self, sheet: u32, row: i32, row_count: i32) -> PyResult<()> {
self.model
.delete_rows(sheet, row, row_count)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn delete_columns(&mut self, sheet: u32, column: i32, column_count: i32) -> PyResult<()> {
self.model
.delete_columns(sheet, column, column_count)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn get_column_width(&self, sheet: u32, column: i32) -> PyResult<f64> {
self.model
.get_column_width(sheet, column)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn get_row_height(&self, sheet: u32, row: i32) -> PyResult<f64> {
self.model
.get_row_height(sheet, row)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn set_column_width(&mut self, sheet: u32, column: i32, width: f64) -> PyResult<()> {
self.model
.set_column_width(sheet, column, width)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn set_row_height(&mut self, sheet: u32, row: i32, height: f64) -> PyResult<()> {
self.model
.set_row_height(sheet, row, height)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
// frozen rows/columns
pub fn get_frozen_columns_count(&self, sheet: u32) -> PyResult<i32> {
self.model
.get_frozen_columns_count(sheet)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn get_frozen_rows_count(&self, sheet: u32) -> PyResult<i32> {
self.model
.get_frozen_rows_count(sheet)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn set_frozen_columns_count(&mut self, sheet: u32, column_count: i32) -> PyResult<()> {
self.model
.set_frozen_columns(sheet, column_count)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn set_frozen_rows_count(&mut self, sheet: u32, row_count: i32) -> PyResult<()> {
self.model
.set_frozen_rows(sheet, row_count)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
// Manipulate sheets (add/remove/rename/change color)
pub fn get_worksheets_properties(&self) -> PyResult<Vec<PySheetProperty>> {
Ok(self
.model
.get_worksheets_properties()
.into_iter()
.map(|s| PySheetProperty {
name: s.name,
state: s.state,
sheet_id: s.sheet_id,
color: s.color,
})
.collect())
}
pub fn set_sheet_color(&mut self, sheet: u32, color: &str) -> PyResult<()> {
self.model
.set_sheet_color(sheet, color)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn add_sheet(&mut self, sheet_name: &str) -> PyResult<()> {
self.model
.add_sheet(sheet_name)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn new_sheet(&mut self) {
self.model.new_sheet();
}
pub fn delete_sheet(&mut self, sheet: u32) -> PyResult<()> {
self.model
.delete_sheet(sheet)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn rename_sheet(&mut self, sheet: u32, new_name: &str) -> PyResult<()> {
self.model
.rename_sheet_by_index(sheet, new_name)
.map_err(|e| WorkbookError::new_err(e.to_string()))
}
pub fn test_panic(&self) -> PyResult<()> {
panic!("This function panics for testing panic handling");
}
}
/// Create methods
/// Loads a function from an xlsx file
#[pyfunction]
pub fn load_from_xlsx(file_path: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
let model = import::load_from_xlsx(file_path, locale, tz)
.map_err(|e| WorkbookError::new_err(e.to_string()))?;
Ok(PyModel { model })
}
/// Loads a function from icalc binary representation
#[pyfunction]
pub fn load_from_icalc(file_name: &str) -> PyResult<PyModel> {
let model =
import::load_from_icalc(file_name).map_err(|e| WorkbookError::new_err(e.to_string()))?;
Ok(PyModel { model })
}
/// Creates an empty model
#[pyfunction]
pub fn create(name: &str, locale: &str, tz: &str) -> PyResult<PyModel> {
let model =
Model::new_empty(name, locale, tz).map_err(|e| WorkbookError::new_err(e.to_string()))?;
Ok(PyModel { model })
}
#[pyfunction]
pub fn test_panic() {
panic!("This function panics for testing panic handling");
}
#[pymodule]
fn ironcalc(m: &Bound<'_, PyModule>) -> PyResult<()> {
// Add the package version to the module
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
// Add the functions to the module using the `?` operator
m.add_function(wrap_pyfunction!(create, m)?)?;
m.add_function(wrap_pyfunction!(load_from_xlsx, m)?)?;
m.add_function(wrap_pyfunction!(load_from_icalc, m)?)?;
m.add_function(wrap_pyfunction!(test_panic, m)?)?;
Ok(())
}

View File

@@ -0,0 +1,428 @@
use pyo3::prelude::*;
use xlsx::base::types::{
Alignment, Border, BorderItem, BorderStyle, Fill, Font, FontScheme, HorizontalAlignment, Style,
VerticalAlignment,
};
#[derive(Clone)]
#[pyclass]
pub struct PySheetProperty {
#[pyo3(get)]
pub name: String,
#[pyo3(get)]
pub state: String,
#[pyo3(get)]
pub sheet_id: u32,
#[pyo3(get)]
pub color: Option<String>,
}
#[pyclass]
#[derive(Clone)]
pub struct Cell {
#[pyo3(get, set)]
pub row: i32,
#[pyo3(get, set)]
pub column: i32,
}
#[pyclass(eq, eq_int)]
#[derive(PartialEq, Clone)]
pub enum PyHorizontalAlignment {
Center,
CenterContinuous,
Distributed,
Fill,
General,
Justify,
Left,
Right,
}
#[pyclass(eq, eq_int)]
#[derive(PartialEq, Clone)]
pub enum PyVerticalAlignment {
Bottom,
Center,
Distributed,
Justify,
Top,
}
#[pyclass]
#[derive(Clone)]
pub struct PyAlignment {
#[pyo3(get)]
pub horizontal: PyHorizontalAlignment,
#[pyo3(get)]
pub vertical: PyVerticalAlignment,
#[pyo3(get)]
pub wrap_text: bool,
}
#[pyclass]
#[derive(Clone)]
pub struct PyStyle {
#[pyo3(get)]
pub alignment: Option<PyAlignment>,
#[pyo3(get)]
pub num_fmt: String,
#[pyo3(get)]
pub fill: PyFill,
#[pyo3(get)]
pub font: PyFont,
#[pyo3(get)]
pub border: PyBorder,
#[pyo3(get)]
pub quote_prefix: bool,
}
#[pyclass(eq, eq_int)]
#[derive(PartialEq, Clone)]
pub enum PyBorderStyle {
Thin,
Medium,
Thick,
Double,
Dotted,
SlantDashDot,
MediumDashed,
MediumDashDotDot,
MediumDashDot,
}
#[pyclass]
#[derive(Clone)]
pub struct PyBorderItem {
#[pyo3(get)]
pub style: PyBorderStyle,
#[pyo3(get)]
pub color: Option<String>,
}
#[pyclass]
#[derive(Clone)]
pub struct PyBorder {
#[pyo3(get)]
pub diagonal_up: bool,
#[pyo3(get)]
pub diagonal_down: bool,
#[pyo3(get)]
pub left: Option<PyBorderItem>,
#[pyo3(get)]
pub right: Option<PyBorderItem>,
#[pyo3(get)]
pub top: Option<PyBorderItem>,
#[pyo3(get)]
pub bottom: Option<PyBorderItem>,
#[pyo3(get)]
pub diagonal: Option<PyBorderItem>,
}
#[pyclass(eq, eq_int)]
#[derive(PartialEq, Clone)]
pub enum PyFontScheme {
Minor,
Major,
None,
}
#[pyclass]
#[derive(Clone)]
pub struct PyFont {
#[pyo3(get)]
pub strike: bool,
#[pyo3(get)]
pub u: bool,
#[pyo3(get)]
pub b: bool,
#[pyo3(get)]
pub i: bool,
#[pyo3(get)]
pub sz: i32,
#[pyo3(get)]
pub color: Option<String>,
#[pyo3(get)]
pub name: String,
#[pyo3(get)]
pub family: i32,
#[pyo3(get)]
pub scheme: PyFontScheme,
}
#[pyclass]
#[derive(Clone)]
pub struct PyFill {
#[pyo3(get)]
pub pattern_type: String,
#[pyo3(get)]
pub fg_color: Option<String>,
#[pyo3(get)]
pub bg_color: Option<String>,
}
// Conversions from references to Py* types to non-Py types
// Enums
impl From<PyHorizontalAlignment> for HorizontalAlignment {
fn from(py_align: PyHorizontalAlignment) -> Self {
match py_align {
PyHorizontalAlignment::Center => HorizontalAlignment::Center,
PyHorizontalAlignment::CenterContinuous => HorizontalAlignment::CenterContinuous,
PyHorizontalAlignment::Distributed => HorizontalAlignment::Distributed,
PyHorizontalAlignment::Fill => HorizontalAlignment::Fill,
PyHorizontalAlignment::General => HorizontalAlignment::General,
PyHorizontalAlignment::Justify => HorizontalAlignment::Justify,
PyHorizontalAlignment::Left => HorizontalAlignment::Left,
PyHorizontalAlignment::Right => HorizontalAlignment::Right,
}
}
}
impl From<PyVerticalAlignment> for VerticalAlignment {
fn from(py_align: PyVerticalAlignment) -> Self {
match py_align {
PyVerticalAlignment::Bottom => VerticalAlignment::Bottom,
PyVerticalAlignment::Center => VerticalAlignment::Center,
PyVerticalAlignment::Distributed => VerticalAlignment::Distributed,
PyVerticalAlignment::Justify => VerticalAlignment::Justify,
PyVerticalAlignment::Top => VerticalAlignment::Top,
}
}
}
impl From<PyFontScheme> for FontScheme {
fn from(py_scheme: PyFontScheme) -> Self {
match py_scheme {
PyFontScheme::Minor => FontScheme::Minor,
PyFontScheme::Major => FontScheme::Major,
PyFontScheme::None => FontScheme::None,
}
}
}
impl From<&PyBorderStyle> for BorderStyle {
fn from(py_style: &PyBorderStyle) -> Self {
match *py_style {
PyBorderStyle::Thin => BorderStyle::Thin,
PyBorderStyle::Medium => BorderStyle::Medium,
PyBorderStyle::Thick => BorderStyle::Thick,
PyBorderStyle::Double => BorderStyle::Double,
PyBorderStyle::Dotted => BorderStyle::Dotted,
PyBorderStyle::SlantDashDot => BorderStyle::SlantDashDot,
PyBorderStyle::MediumDashed => BorderStyle::MediumDashed,
PyBorderStyle::MediumDashDotDot => BorderStyle::MediumDashDotDot,
PyBorderStyle::MediumDashDot => BorderStyle::MediumDashDot,
}
}
}
// Structs
impl From<&PyFill> for Fill {
fn from(py_fill: &PyFill) -> Self {
Fill {
pattern_type: py_fill.pattern_type.clone(),
fg_color: py_fill.fg_color.clone(),
bg_color: py_fill.bg_color.clone(),
}
}
}
impl From<&PyFont> for Font {
fn from(py_font: &PyFont) -> Self {
Font {
strike: py_font.strike,
u: py_font.u,
b: py_font.b,
i: py_font.i,
sz: py_font.sz,
color: py_font.color.clone(),
name: py_font.name.clone(),
family: py_font.family,
scheme: py_font.scheme.clone().into(),
}
}
}
impl From<&PyBorderItem> for BorderItem {
fn from(py_item: &PyBorderItem) -> Self {
BorderItem {
style: (&py_item.style).into(),
color: py_item.color.clone(),
}
}
}
impl From<&PyBorder> for Border {
fn from(py_border: &PyBorder) -> Self {
Border {
diagonal_up: py_border.diagonal_up,
diagonal_down: py_border.diagonal_down,
left: py_border.left.as_ref().map(|item| item.into()),
right: py_border.right.as_ref().map(|item| item.into()),
top: py_border.top.as_ref().map(|item| item.into()),
bottom: py_border.bottom.as_ref().map(|item| item.into()),
diagonal: py_border.diagonal.as_ref().map(|item| item.into()),
}
}
}
impl From<&PyAlignment> for Alignment {
fn from(py_align: &PyAlignment) -> Self {
Alignment {
horizontal: py_align.horizontal.clone().into(),
vertical: py_align.vertical.clone().into(),
wrap_text: py_align.wrap_text,
}
}
}
impl From<&PyStyle> for Style {
fn from(py_style: &PyStyle) -> Self {
Style {
alignment: py_style.alignment.as_ref().map(|a| a.into()),
num_fmt: py_style.num_fmt.clone(),
fill: (&py_style.fill).into(),
font: (&py_style.font).into(),
border: (&py_style.border).into(),
quote_prefix: py_style.quote_prefix,
}
}
}
// From non-Py to Py
impl From<Fill> for PyFill {
fn from(fill: Fill) -> Self {
PyFill {
pattern_type: fill.pattern_type,
fg_color: fill.fg_color,
bg_color: fill.bg_color,
}
}
}
// From non-Py to Py
impl From<HorizontalAlignment> for PyHorizontalAlignment {
fn from(align: HorizontalAlignment) -> Self {
match align {
HorizontalAlignment::Center => PyHorizontalAlignment::Center,
HorizontalAlignment::CenterContinuous => PyHorizontalAlignment::CenterContinuous,
HorizontalAlignment::Distributed => PyHorizontalAlignment::Distributed,
HorizontalAlignment::Fill => PyHorizontalAlignment::Fill,
HorizontalAlignment::General => PyHorizontalAlignment::General,
HorizontalAlignment::Justify => PyHorizontalAlignment::Justify,
HorizontalAlignment::Left => PyHorizontalAlignment::Left,
HorizontalAlignment::Right => PyHorizontalAlignment::Right,
}
}
}
// From non-Py to Py
impl From<VerticalAlignment> for PyVerticalAlignment {
fn from(align: VerticalAlignment) -> Self {
match align {
VerticalAlignment::Bottom => PyVerticalAlignment::Bottom,
VerticalAlignment::Center => PyVerticalAlignment::Center,
VerticalAlignment::Distributed => PyVerticalAlignment::Distributed,
VerticalAlignment::Justify => PyVerticalAlignment::Justify,
VerticalAlignment::Top => PyVerticalAlignment::Top,
}
}
}
// From non-Py to Py
impl From<FontScheme> for PyFontScheme {
fn from(scheme: FontScheme) -> Self {
match scheme {
FontScheme::Minor => PyFontScheme::Minor,
FontScheme::Major => PyFontScheme::Major,
FontScheme::None => PyFontScheme::None,
}
}
}
// From non-Py to Py
impl From<BorderStyle> for PyBorderStyle {
fn from(style: BorderStyle) -> Self {
match style {
BorderStyle::Thin => PyBorderStyle::Thin,
BorderStyle::Medium => PyBorderStyle::Medium,
BorderStyle::Thick => PyBorderStyle::Thick,
BorderStyle::Double => PyBorderStyle::Double,
BorderStyle::Dotted => PyBorderStyle::Dotted,
BorderStyle::SlantDashDot => PyBorderStyle::SlantDashDot,
BorderStyle::MediumDashed => PyBorderStyle::MediumDashed,
BorderStyle::MediumDashDotDot => PyBorderStyle::MediumDashDotDot,
BorderStyle::MediumDashDot => PyBorderStyle::MediumDashDot,
}
}
}
// From non-Py to Py
impl From<Font> for PyFont {
fn from(font: Font) -> Self {
PyFont {
strike: font.strike,
u: font.u,
b: font.b,
i: font.i,
sz: font.sz,
color: font.color,
name: font.name,
family: font.family,
scheme: font.scheme.into(),
}
}
}
// From non-Py to Py
impl From<BorderItem> for PyBorderItem {
fn from(item: BorderItem) -> Self {
PyBorderItem {
style: item.style.into(),
color: item.color,
}
}
}
// From non-Py to Py
impl From<Border> for PyBorder {
fn from(border: Border) -> Self {
PyBorder {
diagonal_up: border.diagonal_up,
diagonal_down: border.diagonal_down,
left: border.left.map(|item| item.into()),
right: border.right.map(|item| item.into()),
top: border.top.map(|item| item.into()),
bottom: border.bottom.map(|item| item.into()),
diagonal: border.diagonal.map(|item| item.into()),
}
}
}
// From non-Py to Py
impl From<Alignment> for PyAlignment {
fn from(align: Alignment) -> Self {
PyAlignment {
horizontal: align.horizontal.into(),
vertical: align.vertical.into(),
wrap_text: align.wrap_text,
}
}
}
// From non-Py to Py
impl From<Style> for PyStyle {
fn from(style: Style) -> Self {
PyStyle {
alignment: style.alignment.map(|a| a.into()),
num_fmt: style.num_fmt,
fill: style.fill.into(),
font: style.font.into(),
border: style.border.into(),
quote_prefix: style.quote_prefix,
}
}
}