diff --git a/Cargo.lock b/Cargo.lock index c5d9d93..a858994 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,6 +118,36 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "attribute-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0053e96dd3bec5b4879c23a138d6ef26f2cb936c9cdc96274ac2b9ed44b5bb54" +dependencies = [ + "attribute-derive-macro", + "derive-where", + "manyhow", + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "attribute-derive-macro" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463b53ad0fd5b460af4b1915fe045ff4d946d025fb6c4dc3337752eaa980f71b" +dependencies = [ + "collection_literals", + "interpolator", + "manyhow", + "proc-macro-utils", + "proc-macro2", + "quote", + "quote-use", + "syn 2.0.87", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -199,10 +229,10 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.1", "cexpr", "clang-sys", - "itertools", + "itertools 0.10.5", "lazy_static", "lazycell", "log", @@ -210,7 +240,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn 2.0.87", "which", @@ -245,9 +275,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.6.0" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "block-buffer" @@ -258,6 +288,17 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "bstr" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "buffered-io" version = "0.5.4" @@ -286,6 +327,15 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" +[[package]] +name = "castaway" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.1.6" @@ -348,7 +398,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" dependencies = [ "termcolor", - "unicode-width", + "unicode-width 0.1.13", +] + +[[package]] +name = "collection_literals" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b3f65b8fb8e88ba339f7d23a390fe1b0896217da05e2a66c584c9b29a91df8" + +[[package]] +name = "compact_str" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "static_assertions", ] [[package]] @@ -604,6 +674,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "derive-where" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "510c292c8cf384b1a340b816a9a6cf2599eb8f566a44949024af88418000c50b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "diff" version = "0.1.13" @@ -1107,6 +1188,8 @@ dependencies = [ "portable-atomic", "rand", "reqwless", + "ruff_python_ast 0.0.0 (git+https://github.com/astral-sh/ruff)", + "ruff_python_parser", "static_cell", "thiserror 2.0.12", ] @@ -1253,6 +1336,38 @@ dependencies = [ "zeroize", ] +[[package]] +name = "get-size-derive2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aac2af9f9a6a50e31b1e541d05b7925add83d3982c2793193fe9d4ee584323c" +dependencies = [ + "attribute-derive", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "get-size2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a0312efd19e1c45922dfcc2d6806d3ffc4bca261f89f31fcc4f63f438d885" +dependencies = [ + "compact_str", + "get-size-derive2", + "hashbrown 0.15.4", + "smallvec", +] + +[[package]] +name = "getopts" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1" +dependencies = [ + "unicode-width 0.2.1", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -1340,6 +1455,12 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" + [[package]] name = "heapless" version = "0.6.1" @@ -1376,6 +1497,12 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -1434,7 +1561,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", ] [[package]] @@ -1446,6 +1573,12 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "interpolator" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71dd52191aae121e8611f1e8dc3e324dd0dd1dee1e6dd91d10ee07a3cfb4d9d8" + [[package]] name = "io-kit-sys" version = "0.4.1" @@ -1456,6 +1589,18 @@ dependencies = [ "mach2", ] +[[package]] +name = "is-macro" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d57a3e447e24c22647738e4607f1df1e0ec6f72e16182c4cd199f647cdfb0e4" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "is-terminal" version = "0.4.12" @@ -1476,6 +1621,21 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "jobserver" version = "0.1.32" @@ -1496,7 +1656,7 @@ dependencies = [ "diff", "ena", "is-terminal", - "itertools", + "itertools 0.10.5", "lalrpop-util", "petgraph", "regex", @@ -1556,7 +1716,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.1", "libc", ] @@ -1604,9 +1764,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "mach2" @@ -1623,6 +1783,29 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" +[[package]] +name = "manyhow" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b33efb3ca6d3b07393750d4030418d594ab1139cee518f0dc88db70fec873587" +dependencies = [ + "manyhow-macros", + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "manyhow-macros" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46fce34d199b78b6e6073abf984c9cf5fd3e9330145a93ee0738a7443e371495" +dependencies = [ + "proc-macro-utils", + "proc-macro2", + "quote", +] + [[package]] name = "memchr" version = "2.7.4" @@ -1840,13 +2023,51 @@ dependencies = [ "indexmap", ] +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_shared 0.11.3", +] + +[[package]] +name = "phf_codegen" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" +dependencies = [ + "phf_generator", + "phf_shared 0.11.3", +] + +[[package]] +name = "phf_generator" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" +dependencies = [ + "phf_shared 0.11.3", + "rand", +] + [[package]] name = "phf_shared" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" dependencies = [ - "siphasher", + "siphasher 0.3.11", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher 1.0.1", ] [[package]] @@ -1993,22 +2214,55 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-utils" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeaf08a13de400bc215877b5bdc088f241b12eb42f0a548d3390dc1c56bb7071" +dependencies = [ + "proc-macro2", + "quote", + "smallvec", +] + [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "quote-use" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9619db1197b497a36178cfc736dc96b271fe918875fbf1344c436a7e93d0321e" +dependencies = [ + "quote", + "quote-use-macros", +] + +[[package]] +name = "quote-use-macros" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "82ebfb7faafadc06a7ab141a6f67bcfb24cb8beb158c6fe933f2f035afa99f35" dependencies = [ + "proc-macro-utils", "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] @@ -2057,7 +2311,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.1", ] [[package]] @@ -2161,6 +2415,116 @@ dependencies = [ "crc-any", ] +[[package]] +name = "ruff_python_ast" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668#9bee8376a17401f9736b45fdefffb62edc2f1668" +dependencies = [ + "aho-corasick", + "bitflags 2.9.1", + "compact_str", + "get-size2", + "is-macro", + "itertools 0.14.0", + "memchr", + "ruff_python_trivia 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "ruff_source_file 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "rustc-hash 2.1.1", + "thiserror 2.0.12", +] + +[[package]] +name = "ruff_python_ast" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff#4dd2c03144828caf4e49c2ec61280e0311b10aaf" +dependencies = [ + "aho-corasick", + "bitflags 2.9.1", + "compact_str", + "is-macro", + "itertools 0.14.0", + "memchr", + "ruff_python_trivia 0.0.0 (git+https://github.com/astral-sh/ruff)", + "ruff_source_file 0.0.0 (git+https://github.com/astral-sh/ruff)", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff)", + "rustc-hash 2.1.1", + "thiserror 2.0.12", +] + +[[package]] +name = "ruff_python_parser" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668#9bee8376a17401f9736b45fdefffb62edc2f1668" +dependencies = [ + "bitflags 2.9.1", + "bstr", + "compact_str", + "get-size2", + "memchr", + "ruff_python_ast 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "ruff_python_trivia 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "rustc-hash 2.1.1", + "static_assertions", + "unicode-ident", + "unicode-normalization", + "unicode_names2", +] + +[[package]] +name = "ruff_python_trivia" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668#9bee8376a17401f9736b45fdefffb62edc2f1668" +dependencies = [ + "itertools 0.14.0", + "ruff_source_file 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", + "unicode-ident", +] + +[[package]] +name = "ruff_python_trivia" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff#4dd2c03144828caf4e49c2ec61280e0311b10aaf" +dependencies = [ + "itertools 0.14.0", + "ruff_source_file 0.0.0 (git+https://github.com/astral-sh/ruff)", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff)", + "unicode-ident", +] + +[[package]] +name = "ruff_source_file" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668#9bee8376a17401f9736b45fdefffb62edc2f1668" +dependencies = [ + "memchr", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668)", +] + +[[package]] +name = "ruff_source_file" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff#4dd2c03144828caf4e49c2ec61280e0311b10aaf" +dependencies = [ + "memchr", + "ruff_text_size 0.0.0 (git+https://github.com/astral-sh/ruff)", +] + +[[package]] +name = "ruff_text_size" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff?rev=9bee8376a17401f9736b45fdefffb62edc2f1668#9bee8376a17401f9736b45fdefffb62edc2f1668" +dependencies = [ + "get-size2", +] + +[[package]] +name = "ruff_text_size" +version = "0.0.0" +source = "git+https://github.com/astral-sh/ruff#4dd2c03144828caf4e49c2ec61280e0311b10aaf" + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -2173,6 +2537,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" + [[package]] name = "rustc_version" version = "0.2.3" @@ -2197,7 +2567,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.1", "errno", "libc", "linux-raw-sys", @@ -2243,6 +2613,12 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + [[package]] name = "scopeguard" version = "1.2.0" @@ -2309,7 +2685,7 @@ version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de7c4f0cce25b9b3518eea99618112f9ee4549f974480c8f43d3c06f03c131a0" dependencies = [ - "bitflags 2.6.0", + "bitflags 2.9.1", "cfg-if", "core-foundation-sys", "io-kit-sys", @@ -2355,6 +2731,12 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "smallvec" version = "1.13.2" @@ -2400,6 +2782,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "static_cell" version = "2.1.0" @@ -2418,7 +2806,7 @@ dependencies = [ "new_debug_unreachable", "once_cell", "parking_lot", - "phf_shared", + "phf_shared 0.10.0", "precomputed-hash", ] @@ -2543,6 +2931,21 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinyvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.39.1" @@ -2604,18 +3007,55 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "unicode-width" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" + [[package]] name = "unicode-xid" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "unicode_names2" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1673eca9782c84de5f81b82e4109dcfb3611c8ba0d52930ec4a9478f547b2dd" +dependencies = [ + "phf", + "unicode_names2_generator", +] + +[[package]] +name = "unicode_names2_generator" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91e5b84611016120197efd7dc93ef76774f4e084cd73c9fb3ea4a86c570c56e" +dependencies = [ + "getopts", + "log", + "phf_codegen", + "rand", +] + [[package]] name = "universal-hash" version = "0.5.1" diff --git a/fan-controller/Cargo.toml b/fan-controller/Cargo.toml index beb384b..ae4d833 100644 --- a/fan-controller/Cargo.toml +++ b/fan-controller/Cargo.toml @@ -52,4 +52,6 @@ debug = 2 [build-dependencies] dotenvy = "0.15.7" +ruff_python_ast = { git = "https://github.com/astral-sh/ruff", version = "0.0.0" } +ruff_python_parser = { git = "https://github.com/astral-sh/ruff", rev = "9bee8376a17401f9736b45fdefffb62edc2f1668", version = "0.0.0" } thiserror = "2.0.12" diff --git a/fan-controller/build.rs b/fan-controller/build.rs index 9d27218..9a0a666 100644 --- a/fan-controller/build.rs +++ b/fan-controller/build.rs @@ -8,10 +8,14 @@ //! updating `memory.x` ensures a rebuild of the application with the //! new memory settings. +use std::collections::HashMap; use std::env::{self, VarError}; use std::fs::{self, File}; use std::io::Write; use std::path::PathBuf; +use std::rc::Rc; + +use ruff_python_ast::{DictItem, Expr, Stmt}; #[derive(Debug, thiserror::Error)] enum BuildError { @@ -90,6 +94,66 @@ fn setup_configuration() -> Result<(), BuildError> { Ok(()) } +fn extract_abreviations() -> HashMap, Rc> { + const PATH: &str = "home-assistant/core/homeassistant/components/mqtt/abbreviations.py"; + println!("cargo::rerun-if-changed={PATH}"); + let module = fs::read_to_string(&PATH).unwrap(); + let module = ruff_python_parser::parse_module(&module).unwrap(); + let syntax = module.syntax(); + + let mut abbreviations = HashMap::new(); + for statement in &syntax.body { + //TODO can I remove clone-clowning? + let Some(assignment) = statement.clone().assign_stmt() else { + continue; + }; + + let Some(name_expression) = assignment + .targets + .first() + .cloned() + .and_then(|expression| expression.name_expr()) + else { + continue; + }; + + if name_expression.id.as_str() != "ABBREVIATIONS" { + continue; + } + + let Some(dictionary) = assignment.value.dict_expr() else { + continue; + }; + + for item in dictionary.items { + let Some(key) = item.key else { + todo!("Expected abbreviations dictionary to have a key") + }; + + let Some(key_string_literal) = key.string_literal_expr() else { + todo!("Expected key to be a string literal") + }; + + let key = key_string_literal.value.to_str(); + + let Some(value_string_literal) = item.value.string_literal_expr() else { + todo!("Expected value to be a string literal") + }; + + let value = value_string_literal.value.to_str(); + abbreviations.insert(Rc::from(value), Rc::from(key)); + } + + // Early return as we have what we want + return abbreviations; + } + + return abbreviations; +} + +/// Overengineering saving a couple of bytes from a JSON string. +/// Minimizes payload with abbreviations and removing whitespace. +/// Abbreviations are loaded from the official home assistant repository. fn setup_discovery_payload() -> Result<(), DiscoveryPayloadError> { const PATH_DISCOVER_JSON: &str = "discovery_payload.json"; //TODO validate discovery payload @@ -98,14 +162,47 @@ fn setup_discovery_payload() -> Result<(), DiscoveryPayloadError> { let mut is_in_string = false; let mut result = String::new(); + let abbreviations = extract_abreviations(); + let mut current_key = String::new(); + let mut is_in_key = true; for character in json.chars() { // Do not trim strings if character == '"' { + // End of key + if is_in_string && is_in_key { + let key = Rc::from(current_key.as_ref()); + let abbreviation = abbreviations.get(&key); + if let Some(abbreviation) = abbreviation { + println!("Abbreviation {} -> {}", key, abbreviation); + result.push_str(&abbreviation); + } else { + result.push_str(¤t_key); + } + current_key.clear(); + result.push('"'); + is_in_string = false; + is_in_key = false; + continue; + } + is_in_string = !is_in_string; + result.push('"'); continue; } - if is_in_string { + // End of value + if character == ',' || character == '}' { + is_in_key = true; + result.push(','); + continue; + } + + if !is_in_string && character.is_whitespace() { + continue; + } + + if is_in_key { + current_key.push(character); continue; } @@ -116,6 +213,7 @@ fn setup_discovery_payload() -> Result<(), DiscoveryPayloadError> { "cargo:rustc-env=FAN_CONTROLLER_DISCOVERY_PAYLOAD={}", result ); + Ok(()) } diff --git a/fan-controller/discovery_payload.json b/fan-controller/discovery_payload.json index 3aabbfd..56f74bf 100644 --- a/fan-controller/discovery_payload.json +++ b/fan-controller/discovery_payload.json @@ -1,6 +1,6 @@ { "name": "Fans", - "uniq_id": "fancontroller", + "unique_id": "fancontroller", "stat_t": "fancontroller/on/state", "cmd_t": "fancontroller/on/set", "pct_stat_t": "fancontroller/speed/percentage_state",