From 11acf60569b96076fb88e1e463cbec68ada12dce Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 20 Mar 2024 17:11:23 -0400 Subject: [PATCH 1/3] Update to python-parser 0.3.0 --- crates/Cargo.lock | 672 ++++++++---------- crates/driver/Cargo.toml | 4 +- crates/driver/src/print_build.rs | 14 +- crates/python_extractor/Cargo.toml | 4 +- .../src/extract_py_imports.rs | 58 +- crates/python_utilities/Cargo.toml | 4 +- crates/python_utilities/src/ast_builder.rs | 78 +- crates/python_utilities/src/ast_printer.rs | 53 +- crates/python_utilities/src/lib.rs | 7 +- 9 files changed, 413 insertions(+), 481 deletions(-) diff --git a/crates/Cargo.lock b/crates/Cargo.lock index a5187f6d..6170ea7d 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "addr2line" version = "0.19.0" @@ -28,17 +34,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "aho-corasick" version = "1.1.2" @@ -102,32 +97,6 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" -[[package]] -name = "ascii" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" - -[[package]] -name = "ascii-canvas" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" -dependencies = [ - "term", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -150,34 +119,16 @@ dependencies = [ ] [[package]] -name = "base64ct" -version = "1.6.0" +name = "base64" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - -[[package]] -name = "bit-set" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" +name = "base64ct" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bitflags" @@ -193,24 +144,29 @@ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ + "block-padding", "generic-array", ] [[package]] -name = "bstr" -version = "0.2.17" +name = "block-buffer" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ - "lazy_static", - "memchr", - "regex-automata 0.1.10", + "generic-array", ] +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + [[package]] name = "bstr" version = "1.8.0" @@ -410,7 +366,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.46", ] [[package]] @@ -431,6 +387,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "cpufeatures" version = "0.2.5" @@ -499,41 +461,36 @@ dependencies = [ ] [[package]] -name = "diff" -version = "0.1.13" +name = "derive_more" +version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "block-buffer", - "crypto-common", - "subtle", + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", ] [[package]] -name = "dirs-next" -version = "2.0.0" +name = "digest" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "cfg-if", - "dirs-sys-next", + "generic-array", ] [[package]] -name = "dirs-sys-next" -version = "0.1.2" +name = "digest" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "libc", - "redox_users", - "winapi", + "block-buffer 0.10.3", + "crypto-common", + "subtle", ] [[package]] @@ -543,12 +500,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] -name = "ena" -version = "0.14.1" +name = "embed-doc-image" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2e5d13ca2353ab7d0230988629def93914a8c4015f621f9b13ed2955614731d" +checksum = "af36f591236d9d822425cb6896595658fa558fcebf5ee8accac1d4b92c47166e" dependencies = [ - "log", + "base64", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -589,12 +549,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - [[package]] name = "flate2" version = "1.0.26" @@ -661,7 +615,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.46", ] [[package]] @@ -706,13 +660,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", ] [[package]] @@ -728,33 +682,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" dependencies = [ "aho-corasick", - "bstr 1.8.0", + "bstr", "log", - "regex-automata 0.4.4", - "regex-syntax 0.8.2", + "regex-automata", + "regex-syntax", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[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.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.2.6" @@ -782,7 +721,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -801,22 +740,12 @@ dependencies = [ "globset", "log", "memchr", - "regex-automata 0.4.4", + "regex-automata", "same-file", "walkdir", "winapi-util", ] -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "inout" version = "0.1.3" @@ -837,6 +766,19 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is-macro" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7d079e129b77477a49c5c4f1cfe9ce6c2c909ef52520693e8e811a714c7b20" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "is-terminal" version = "0.4.4" @@ -849,6 +791,15 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.10.5" @@ -874,36 +825,19 @@ dependencies = [ ] [[package]] -name = "lalrpop" -version = "0.19.8" +name = "keccak" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" dependencies = [ - "ascii-canvas", - "atty", - "bit-set", - "diff", - "ena", - "itertools", - "lalrpop-util", - "petgraph", - "pico-args", - "regex", - "regex-syntax 0.6.28", - "string_cache", - "term", - "tiny-keccak", - "unicode-xid", + "cpufeatures", ] [[package]] name = "lalrpop-util" -version = "0.19.8" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4" -dependencies = [ - "regex", -] +checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" [[package]] name = "lazy_static" @@ -976,12 +910,62 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] -name = "lz4_flex" -version = "0.9.5" +name = "malachite" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6cf7f4730c30071ba374fac86ad35b1cb7a0716f774737768667ea3fa1828e3" +dependencies = [ + "malachite-base", + "malachite-nz", + "malachite-q", +] + +[[package]] +name = "malachite-base" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b06bfa98a4b4802af5a4263b4ad4660e28e51e8490f6354eb9336c70767e1c5" +dependencies = [ + "itertools 0.9.0", + "rand 0.7.3", + "rand_chacha", + "ryu", + "sha3", +] + +[[package]] +name = "malachite-bigint" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a5110aee54537b0cef214efbebdd7df79b7408db8eef4f6a4b6db9d0d8fc01b" +dependencies = [ + "derive_more", + "malachite", + "num-integer", + "num-traits", + "paste", +] + +[[package]] +name = "malachite-nz" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a8cbbb2831780bc3b9c15a41f5b49222ef756b6730a95f3decfdd15903eb5a3" +checksum = "c89e21c64b7af5be3dc8cef16f786243faf59459fe4ba93b44efdeb264e5ade4" dependencies = [ - "twox-hash", + "embed-doc-image", + "itertools 0.9.0", + "malachite-base", +] + +[[package]] +name = "malachite-q" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3755e541d5134b5016594c9043094172c4dda9259b3ce824a7b8101941850360" +dependencies = [ + "itertools 0.9.0", + "malachite-base", + "malachite-nz", ] [[package]] @@ -1036,16 +1020,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - [[package]] name = "nom" version = "7.1.3" @@ -1056,28 +1034,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", - "serde", -] - -[[package]] -name = "num-complex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" -dependencies = [ - "num-traits", - "serde", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1122,6 +1078,12 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1152,46 +1114,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" dependencies = [ "base64ct", - "rand_core", + "rand_core 0.6.4", "subtle", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "pbkdf2" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "digest", + "digest 0.10.7", "hmac", "password-hash", "sha2", ] -[[package]] -name = "petgraph" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" -dependencies = [ - "fixedbitset", - "indexmap", -] - [[package]] name = "phf" -version = "0.10.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_shared", ] [[package]] name = "phf_codegen" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ "phf_generator", "phf_shared", @@ -1199,29 +1157,23 @@ dependencies = [ [[package]] name = "phf_generator" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ "phf_shared", - "rand", + "rand 0.8.5", ] [[package]] name = "phf_shared" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", ] -[[package]] -name = "pico-args" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" - [[package]] name = "pin-project-lite" version = "0.2.12" @@ -1241,16 +1193,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] -name = "ppv-lite86" -version = "0.2.17" +name = "pmutil" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] -name = "precomputed-hash" -version = "0.1.1" +name = "ppv-lite86" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "pretty_env_logger" @@ -1281,10 +1238,17 @@ dependencies = [ ] [[package]] -name = "radium" -version = "0.7.0" +name = "rand" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core 0.5.1", + "rand_hc", +] [[package]] name = "rand" @@ -1292,48 +1256,50 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc", - "rand_chacha", - "rand_core", + "rand_core 0.6.4", ] [[package]] name = "rand_chacha" -version = "0.3.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", ] [[package]] name = "rand_core" -version = "0.6.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ "getrandom", ] [[package]] -name = "redox_syscall" -version = "0.2.16" +name = "rand_core" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "bitflags 1.3.2", + "rand_core 0.5.1", ] [[package]] -name = "redox_users" -version = "0.4.3" +name = "redox_syscall" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", + "bitflags 1.3.2", ] [[package]] @@ -1344,16 +1310,10 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.4", - "regex-syntax 0.8.2", + "regex-automata", + "regex-syntax", ] -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" - [[package]] name = "regex-automata" version = "0.4.4" @@ -1362,15 +1322,9 @@ checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" - [[package]] name = "regex-syntax" version = "0.8.2" @@ -1389,6 +1343,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.36.16" @@ -1418,73 +1381,48 @@ dependencies = [ [[package]] name = "rustpython-ast" -version = "0.1.0" -source = "git+https://github.com/RustPython/RustPython.git?rev=b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7#b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf9438da3660e6b88bd659fdc0cd13bcff4b85c584026a48b800c75bf0f8d00" dependencies = [ - "num-bigint", - "rustpython-common", - "rustpython-compiler-core", + "is-macro", + "malachite-bigint", + "rustpython-literal", + "rustpython-parser-core", + "static_assertions", ] [[package]] -name = "rustpython-common" -version = "0.0.0" -source = "git+https://github.com/RustPython/RustPython.git?rev=b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7#b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7" +name = "rustpython-literal" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d470a3e68cd776bb7590363d75c72d94b51e917847721847ab505c98b9397a" dependencies = [ - "ascii", - "cfg-if", "hexf-parse", + "is-macro", "lexical-parse-float", - "libc", - "lock_api", - "num-bigint", - "num-complex", "num-traits", - "once_cell", - "radium", - "rand", - "siphasher", "unic-ucd-category", - "volatile", - "widestring", -] - -[[package]] -name = "rustpython-compiler-core" -version = "0.1.2" -source = "git+https://github.com/RustPython/RustPython.git?rev=b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7#b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7" -dependencies = [ - "bincode", - "bitflags 1.3.2", - "bstr 0.2.17", - "itertools", - "lz4_flex", - "num-bigint", - "num-complex", - "serde", - "static_assertions", - "thiserror", ] [[package]] name = "rustpython-parser" -version = "0.1.2" -source = "git+https://github.com/RustPython/RustPython.git?rev=b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7#b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9db993974ff12f33c5be8a801741463691502f85ead5c503277937c4077bd92a" dependencies = [ - "ahash", "anyhow", - "itertools", - "lalrpop", + "is-macro", + "itertools 0.10.5", "lalrpop-util", "log", - "num-bigint", + "malachite-bigint", "num-traits", "phf", "phf_codegen", "rustc-hash", "rustpython-ast", - "rustpython-compiler-core", - "thiserror", + "rustpython-parser-core", "tiny-keccak", "unic-emoji-char", "unic-ucd-ident", @@ -1492,10 +1430,25 @@ dependencies = [ ] [[package]] -name = "rustversion" -version = "1.0.12" +name = "rustpython-parser-core" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "5e9d560c6dd4dc774d4bbad48c770e074c178c4ed5f6fd0521fcdb639af21bdd" +dependencies = [ + "is-macro", + "memchr", + "rustpython-parser-vendored", +] + +[[package]] +name = "rustpython-parser-vendored" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ae3062d7fe5fe38073f3a1c7145ed9a04e15f6e4a596d642c7db2d5cd2b51b" +dependencies = [ + "memchr", + "once_cell", +] [[package]] name = "ryu" @@ -1518,6 +1471,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + [[package]] name = "serde" version = "1.0.197" @@ -1535,7 +1494,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.46", ] [[package]] @@ -1557,7 +1516,7 @@ checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -1568,7 +1527,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", "sha2-asm", ] @@ -1581,6 +1540,18 @@ dependencies = [ "cc", ] +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1627,19 +1598,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "string_cache" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d69e88b23f23030bf4d0e9ca7b07434f70e1c1f4d3ca7e93ce958b373654d9f" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared", - "precomputed-hash", -] - [[package]] name = "strsim" version = "0.11.0" @@ -1652,6 +1610,17 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[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.46" @@ -1675,17 +1644,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - [[package]] name = "termcolor" version = "1.2.0" @@ -1712,7 +1670,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.46", ] [[package]] @@ -1767,7 +1725,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.46", ] [[package]] @@ -1789,16 +1747,6 @@ dependencies = [ "tree-sitter", ] -[[package]] -name = "twox-hash" -version = "1.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" -dependencies = [ - "cfg-if", - "static_assertions", -] - [[package]] name = "typenum" version = "1.16.0" @@ -1875,17 +1823,11 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" -[[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 = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029df4cc8238cefc911704ff8fa210853a0f3bce2694d8f51181dd41ee0f3301" +checksum = "446c96c6dd42604779487f0a981060717156648c1706aa1f464677f03c6cc059" [[package]] name = "utf8parse" @@ -1899,12 +1841,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "volatile" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8e76fae08f03f96e166d2dfda232190638c10e0383841252416f9cfe2ae60e6" - [[package]] name = "walkdir" version = "2.5.0" @@ -1917,15 +1853,15 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] -name = "widestring" -version = "0.5.1" +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index 62ee6d5e..e903bb9e 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -18,8 +18,8 @@ thiserror = "1.0.58" lazy_static = "1.4.0" ignore = "0.4.22" globset = "0.4.14" -rustpython-parser = { git = "https://github.com/RustPython/RustPython.git", rev = "b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7"} -rustpython-ast = { git = "https://github.com/RustPython/RustPython.git", rev = "b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7", features = ["unparse"]} +rustpython-parser = "0.3.0" +rustpython-ast = { version = "0.3.0", features = ["unparse"] } pretty_env_logger = "0.5.0" log = "0.4.21" diff --git a/crates/driver/src/print_build.rs b/crates/driver/src/print_build.rs index c7240ada..481e0b27 100644 --- a/crates/driver/src/print_build.rs +++ b/crates/driver/src/print_build.rs @@ -11,7 +11,6 @@ use crate::{ to_directory, Opt, PrintBuildArgs, }; use anyhow::{anyhow, Context, Result}; -use ast::{Located, StmtKind}; use bzl_gen_build_python_utilities::{ast_builder, PythonProgram}; use bzl_gen_build_shared_types::{ build_config::{SourceConfig, TargetNameStrategy, WriteMode}, @@ -21,6 +20,7 @@ use bzl_gen_build_shared_types::{ use futures::{stream, StreamExt}; use ignore::WalkBuilder; use rustpython_parser::ast; +use ast::{Expr, Stmt}; use futures::Future; use tokio::{io::AsyncWriteExt, sync::Semaphore}; @@ -42,8 +42,8 @@ struct TargetEntry { } impl TargetEntry { - pub fn emit_build_function_call(&self) -> Result> { - let mut kw_args: Vec<(Arc, Located)> = Default::default(); + pub fn emit_build_function_call(&self) -> Result { + let mut kw_args: Vec<(Arc, Expr)> = Default::default(); kw_args.push(( Arc::new("name".to_string()), @@ -99,10 +99,10 @@ enum SrcType { List(Vec), } impl SrcType { - pub fn to_statement(&self) -> Located { + pub fn to_statement(&self) -> Expr { match self { SrcType::Glob { include, exclude } => { - let mut kw_args: Vec<(Arc, Located)> = Default::default(); + let mut kw_args: Vec<(Arc, Expr)> = Default::default(); kw_args.push(( Arc::new("include".to_string()), @@ -150,7 +150,7 @@ struct TargetEntries { impl TargetEntries { // Helper - fn load_statement(from: Arc, methods: Vec>) -> Located { + fn load_statement(from: Arc, methods: Vec>) -> Stmt { let mut fn_args = Vec::default(); fn_args.push(ast_builder::with_constant_str(from.as_ref().to_owned())); fn_args.extend( @@ -179,7 +179,7 @@ impl TargetEntries { } pub fn to_ast(&self) -> Result { - let mut program: Vec> = Vec::default(); + let mut program: Vec = Vec::default(); let mut all_load_statements: HashMap, Vec>> = HashMap::default(); for entry in self.entries.iter() { diff --git a/crates/python_extractor/Cargo.toml b/crates/python_extractor/Cargo.toml index d08a978a..53559a37 100644 --- a/crates/python_extractor/Cargo.toml +++ b/crates/python_extractor/Cargo.toml @@ -16,8 +16,8 @@ sha2 = { version = "0.10.8", features = ["asm"] } thiserror = "1.0.58" lazy_static = "1.4.0" ignore = "0.4.22" -rustpython-parser = { git = "https://github.com/RustPython/RustPython.git", rev = "b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7"} -rustpython-ast = { git = "https://github.com/RustPython/RustPython.git", rev = "b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7", features = ["unparse"]} +rustpython-parser = "0.3.0" +rustpython-ast = { version = "0.3.0", features = ["unparse"] } pretty_env_logger = "0.5.0" log = "0.4.21" encoding_rs = "0.8.33" diff --git a/crates/python_extractor/src/extract_py_imports.rs b/crates/python_extractor/src/extract_py_imports.rs index 62840e5f..e8c97de3 100644 --- a/crates/python_extractor/src/extract_py_imports.rs +++ b/crates/python_extractor/src/extract_py_imports.rs @@ -1,5 +1,6 @@ use bzl_gen_build_python_utilities::PythonProgram; -use rustpython_ast::{Located, StmtKind}; +use rustpython_parser::ast; +use ast::Stmt; pub fn extract(program: &PythonProgram) -> Vec { let mut buf = Vec::default(); @@ -29,75 +30,70 @@ pub fn extract(program: &PythonProgram) -> Vec { buf } -fn extract_from_body(body: &Vec>, buf: &mut Vec) { +fn extract_from_body(body: &Vec, buf: &mut Vec) { for element in body.iter() { - let element = &element.node; match element { - StmtKind::FunctionDef { body, .. } => extract_from_body(&body, buf), - StmtKind::AsyncFunctionDef { body, .. } => extract_from_body(&body, buf), - StmtKind::ClassDef { - name: _, - bases: _, - keywords: _, - body, - decorator_list: _, - } => extract_from_body(&body, buf), - - StmtKind::For { body, orelse, .. } => { + Stmt::FunctionDef(ast::StmtFunctionDef { body, .. }) => extract_from_body(&body, buf), + Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { body, .. }) => extract_from_body(&body, buf), + Stmt::ClassDef(ast::StmtClassDef { body, .. }) => extract_from_body(&body, buf), + Stmt::For(ast::StmtFor { body, orelse, .. }) => { extract_from_body(&body, buf); extract_from_body(&orelse, buf); } - StmtKind::AsyncFor { body, orelse, .. } => { + Stmt::AsyncFor(ast::StmtAsyncFor { body, orelse, .. }) => { extract_from_body(&body, buf); extract_from_body(&orelse, buf); } - StmtKind::While { body, orelse, .. } => { + Stmt::While(ast::StmtWhile { body, orelse, .. }) => { extract_from_body(&body, buf); extract_from_body(&orelse, buf); } - StmtKind::If { body, orelse, .. } => { + Stmt::If(ast::StmtIf { body, orelse, .. }) => { extract_from_body(&body, buf); extract_from_body(&orelse, buf); } - StmtKind::With { body, .. } => extract_from_body(&body, buf), - StmtKind::AsyncWith { body, .. } => extract_from_body(&body, buf), - StmtKind::Match { cases, .. } => { + Stmt::With(ast::StmtWith { body, .. }) => extract_from_body(&body, buf), + Stmt::AsyncWith(ast::StmtAsyncWith { body, .. }) => extract_from_body(&body, buf), + Stmt::Match(ast::StmtMatch { cases, .. }) => { for case in cases.iter() { extract_from_body(&case.body, buf); } } - StmtKind::Try { + Stmt::Try(ast::StmtTry { + range: _, body, handlers, orelse, finalbody, - } => { + }) => { for handler in handlers.iter() { - match &handler.node { - rustpython_ast::ExcepthandlerKind::ExceptHandler { body, .. } => { + match &handler.as_except_handler() { + Some(ast::ExceptHandlerExceptHandler { body, .. }) => { extract_from_body(&body, buf); - } + }, + None => {}, } } extract_from_body(&body, buf); extract_from_body(&orelse, buf); extract_from_body(&finalbody, buf); } - StmtKind::Import { names } => { + Stmt::Import(ast::StmtImport { names , .. }) => { for nme in names.iter() { - buf.push(nme.node.name.clone()); + buf.push(nme.name.to_string().clone()); } } - StmtKind::ImportFrom { + Stmt::ImportFrom(ast::StmtImportFrom { module, names, level: _, - } => { + .. + }) => { for nme in names.iter() { if let Some(module) = module.as_ref() { - buf.push(format!("{}.{}", module, nme.node.name)); + buf.push(format!("{}.{}", module, nme.name)); } else { - buf.push(nme.node.name.clone()); + buf.push(nme.name.to_string().clone()); } } } diff --git a/crates/python_utilities/Cargo.toml b/crates/python_utilities/Cargo.toml index fa747bf3..1978656d 100644 --- a/crates/python_utilities/Cargo.toml +++ b/crates/python_utilities/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" [dependencies] anyhow = "1.0.81" -rustpython-parser = { git = "https://github.com/RustPython/RustPython.git", rev = "b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7"} -rustpython-ast = { git = "https://github.com/RustPython/RustPython.git", rev = "b9ed63ed326e4ab9c97d808271ddc1d7ca05fda7", features = ["unparse"]} +rustpython-parser = "0.3.0" +rustpython-ast = { version = "0.3.0", features = ["unparse"] } diff --git a/crates/python_utilities/src/ast_builder.rs b/crates/python_utilities/src/ast_builder.rs index 6874961f..306d47c9 100644 --- a/crates/python_utilities/src/ast_builder.rs +++ b/crates/python_utilities/src/ast_builder.rs @@ -1,59 +1,59 @@ -use ast::{Expr, Located, Location, StmtKind}; use rustpython_parser::ast; +use ast::{text_size::TextRange, Expr, Stmt, TextSize}; use std::sync::Arc; -pub fn with_location(t: T) -> Located { - let location = Location::new(1, 0); - Located::new(location, location, t) +fn empty_range() -> TextRange { + TextRange::empty(TextSize::new(0)) } -pub fn with_constant_str(s: String) -> Located { - with_location({ - ast::ExprKind::Constant { - value: ast::Constant::Str(s), - kind: None, - } + +pub fn with_constant_str(s: String) -> Expr { + Expr::Constant(ast::ExprConstant { + range: empty_range(), + value: ast::Constant::Str(s), + kind: None, }) } -pub fn as_py_list(elements: Vec>) -> Located> { - with_location({ - ast::ExprKind::List { - elts: elements, - ctx: ast::ExprContext::Load, - } +pub fn as_py_list(elements: Vec) -> Expr { + Expr::List(ast::ExprList { + range: empty_range(), + elts: elements, + ctx: ast::ExprContext::Load, }) } -pub fn as_stmt_expr(u: Located) -> Located { - with_location(StmtKind::Expr { value: Box::new(u) }) +pub fn as_stmt_expr(u: Expr) -> Stmt { + Stmt::Expr(ast::StmtExpr { + range: empty_range(), + value: Box::new(u), + }) } pub fn gen_py_function_call( name: Arc, - args: Vec>, - kw_args: Vec<(Arc, Located)>, -) -> Located { - let location = Location::new(1, 0); + args: Vec, + kw_args: Vec<(Arc, Expr)>, +) -> Expr { + let location = empty_range(); let mut kws = Vec::default(); for (k, v) in kw_args { - kws.push(with_location(ast::KeywordData { - arg: Some(k.as_ref().to_owned()), - value: Box::new(v), - })) + kws.push(ast::Keyword { + range: location, + arg: Some(ast::Identifier::new(k.to_string())), + value: v, + }) } - with_location({ - ast::ExprKind::Call { - func: Box::new(Expr::new( - location, - location, - ast::ExprKind::Name { - id: name.as_ref().to_owned(), - ctx: ast::ExprContext::Load, - }, - )), - args, - keywords: kws, - } + Expr::Call(ast::ExprCall { + range: location, + func: Box::new(Expr::Name( + ast::ExprName { + range: location, + id: ast::Identifier::new(name.to_string()), + ctx: ast::ExprContext::Load, + }, + )), + args, + keywords: kws, }) } diff --git a/crates/python_utilities/src/ast_printer.rs b/crates/python_utilities/src/ast_printer.rs index c6fd6128..7e75680a 100644 --- a/crates/python_utilities/src/ast_printer.rs +++ b/crates/python_utilities/src/ast_printer.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; -use ast::{Arguments, Located, StmtKind}; use rustpython_parser::ast; +use ast::{Arguments, Stmt}; use crate::PythonProgram; @@ -63,7 +63,7 @@ fn emit_args<'a>(args: &'a Arguments, str_buffer: &mut WritingBuffer<'a>) { str_buffer.push(Cow::Borrowed(", ")); } first_arg = false; - let positional_arg = &positional_arg.node; + let positional_arg = &positional_arg.def; if positional_arg.annotation.is_some() { panic!("Annotation printing not supported {:#?}", positional_arg); } @@ -73,34 +73,29 @@ fn emit_args<'a>(args: &'a Arguments, str_buffer: &mut WritingBuffer<'a>) { if args.kwarg.is_some() { panic!("KW arg printing not supported {:#?}", args); } - if !args.kw_defaults.is_empty() { - panic!("kw_defaults arg printing not supported {:#?}", args); - } - if !args.kwonlyargs.is_empty() { panic!("kwonlyargs arg printing not supported {:#?}", args); } - - if !args.defaults.is_empty() { - panic!("defaults arg printing not supported {:#?}", args); - } } -fn emit_body<'a>(body: &'a [Located], str_buffer: &mut WritingBuffer<'a>) { - for located_stmnt in body.iter() { - match &located_stmnt.node { - ast::StmtKind::Import { names: _ } => todo!(), - ast::StmtKind::FunctionDef { +fn emit_body<'a>(body: &'a [Stmt], str_buffer: &mut WritingBuffer<'a>) { + for stmt in body.iter() { + match &stmt { + Stmt::Import(ast::StmtImport { range: _ , names: _ }) => + todo!(), + Stmt::FunctionDef(ast::StmtFunctionDef { + range: _, name, args, body, decorator_list, returns: _, type_comment: _, - } => { + type_params: _, + }) => { if !decorator_list.is_empty() { panic!( "Have not implemented how to print function with decorators: {:?}", - located_stmnt.node + stmt ) } str_buffer.push(Cow::Borrowed("def ")); @@ -116,12 +111,13 @@ fn emit_body<'a>(body: &'a [Located], str_buffer: &mut WritingBuffer<' str_buffer.finish_line(); } - ast::StmtKind::ImportFrom { + Stmt::ImportFrom(ast::StmtImportFrom { + range: _, module, names, level, - } => { - if level.is_some() && level != &Some(0) { + }) => { + if level.is_some() && level != &Some(ast::Int::new(0)) { panic!( "Have not implemented how to print: {:?}, {:?}, {:?}", module, names, level @@ -141,38 +137,41 @@ fn emit_body<'a>(body: &'a [Located], str_buffer: &mut WritingBuffer<' str_buffer.push(Cow::Borrowed(",")); } first = false; - if let Some(as_name) = &nme.node.asname { - str_buffer.push(Cow::Borrowed(nme.node.name.as_str())); + if let Some(as_name) = &nme.asname { + str_buffer.push(Cow::Borrowed(nme.name.as_str())); str_buffer.push(Cow::Borrowed(" as ")); str_buffer.push(Cow::Borrowed(as_name.as_str())); } else { - str_buffer.push(Cow::Borrowed(nme.node.name.as_str())); + str_buffer.push(Cow::Borrowed(nme.name.as_str())); } } } str_buffer.finish_line(); } - ast::StmtKind::Pass => { + Stmt::Pass(ast::StmtPass { range: _ }) => { str_buffer.push(Cow::Borrowed("pass")); str_buffer.finish_line() } - ast::StmtKind::Expr { value } => { + Stmt::Expr(ast::StmtExpr { + range: _, + value + }) => { str_buffer.push(Cow::Owned(format!("{}", value))); str_buffer.finish_line() } _ => { panic!( "Have not implemented how to print: {:?}", - located_stmnt.node + stmt ) } } } } -fn program_to_string(program: &[Located]) -> String { +fn program_to_string(program: &[Stmt]) -> String { let mut write_buf = WritingBuffer::new(); emit_body(program, &mut write_buf); write_buf.finish() diff --git a/crates/python_utilities/src/lib.rs b/crates/python_utilities/src/lib.rs index 10242460..557c7e5c 100644 --- a/crates/python_utilities/src/lib.rs +++ b/crates/python_utilities/src/lib.rs @@ -1,16 +1,17 @@ -use rustpython_ast::{Located, StmtKind}; +use rustpython_parser::{Parse, ast}; +use ast::Stmt; pub mod ast_builder; pub mod ast_printer; #[derive(Debug, PartialEq)] pub struct PythonProgram { - pub body: Vec>, + pub body: Vec, } impl PythonProgram { pub fn parse(source: &str, source_path: &str) -> anyhow::Result { - let parsed = rustpython_parser::parser::parse_program(source, source_path)?; + let parsed = ast::Suite::parse(source, source_path)?; Ok(Self { body: parsed }) } } From 9bd5829397d63ce386c079e113d94004bfb7adfa Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 20 Mar 2024 17:13:31 -0400 Subject: [PATCH 2/3] Format --- crates/driver/src/print_build.rs | 2 +- crates/python_extractor/src/extract_py_imports.rs | 12 +++++++----- crates/python_utilities/src/ast_builder.rs | 14 ++++++-------- crates/python_utilities/src/ast_printer.rs | 15 ++++----------- crates/python_utilities/src/lib.rs | 2 +- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/crates/driver/src/print_build.rs b/crates/driver/src/print_build.rs index 481e0b27..3fa08fe7 100644 --- a/crates/driver/src/print_build.rs +++ b/crates/driver/src/print_build.rs @@ -11,6 +11,7 @@ use crate::{ to_directory, Opt, PrintBuildArgs, }; use anyhow::{anyhow, Context, Result}; +use ast::{Expr, Stmt}; use bzl_gen_build_python_utilities::{ast_builder, PythonProgram}; use bzl_gen_build_shared_types::{ build_config::{SourceConfig, TargetNameStrategy, WriteMode}, @@ -20,7 +21,6 @@ use bzl_gen_build_shared_types::{ use futures::{stream, StreamExt}; use ignore::WalkBuilder; use rustpython_parser::ast; -use ast::{Expr, Stmt}; use futures::Future; use tokio::{io::AsyncWriteExt, sync::Semaphore}; diff --git a/crates/python_extractor/src/extract_py_imports.rs b/crates/python_extractor/src/extract_py_imports.rs index e8c97de3..90155237 100644 --- a/crates/python_extractor/src/extract_py_imports.rs +++ b/crates/python_extractor/src/extract_py_imports.rs @@ -1,6 +1,6 @@ +use ast::Stmt; use bzl_gen_build_python_utilities::PythonProgram; use rustpython_parser::ast; -use ast::Stmt; pub fn extract(program: &PythonProgram) -> Vec { let mut buf = Vec::default(); @@ -34,7 +34,9 @@ fn extract_from_body(body: &Vec, buf: &mut Vec) { for element in body.iter() { match element { Stmt::FunctionDef(ast::StmtFunctionDef { body, .. }) => extract_from_body(&body, buf), - Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { body, .. }) => extract_from_body(&body, buf), + Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { body, .. }) => { + extract_from_body(&body, buf) + } Stmt::ClassDef(ast::StmtClassDef { body, .. }) => extract_from_body(&body, buf), Stmt::For(ast::StmtFor { body, orelse, .. }) => { extract_from_body(&body, buf); @@ -70,15 +72,15 @@ fn extract_from_body(body: &Vec, buf: &mut Vec) { match &handler.as_except_handler() { Some(ast::ExceptHandlerExceptHandler { body, .. }) => { extract_from_body(&body, buf); - }, - None => {}, + } + None => {} } } extract_from_body(&body, buf); extract_from_body(&orelse, buf); extract_from_body(&finalbody, buf); } - Stmt::Import(ast::StmtImport { names , .. }) => { + Stmt::Import(ast::StmtImport { names, .. }) => { for nme in names.iter() { buf.push(nme.name.to_string().clone()); } diff --git a/crates/python_utilities/src/ast_builder.rs b/crates/python_utilities/src/ast_builder.rs index 306d47c9..3c46be56 100644 --- a/crates/python_utilities/src/ast_builder.rs +++ b/crates/python_utilities/src/ast_builder.rs @@ -1,5 +1,5 @@ -use rustpython_parser::ast; use ast::{text_size::TextRange, Expr, Stmt, TextSize}; +use rustpython_parser::ast; use std::sync::Arc; fn empty_range() -> TextRange { @@ -46,13 +46,11 @@ pub fn gen_py_function_call( Expr::Call(ast::ExprCall { range: location, - func: Box::new(Expr::Name( - ast::ExprName { - range: location, - id: ast::Identifier::new(name.to_string()), - ctx: ast::ExprContext::Load, - }, - )), + func: Box::new(Expr::Name(ast::ExprName { + range: location, + id: ast::Identifier::new(name.to_string()), + ctx: ast::ExprContext::Load, + })), args, keywords: kws, }) diff --git a/crates/python_utilities/src/ast_printer.rs b/crates/python_utilities/src/ast_printer.rs index 7e75680a..3d0f9bd1 100644 --- a/crates/python_utilities/src/ast_printer.rs +++ b/crates/python_utilities/src/ast_printer.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; -use rustpython_parser::ast; use ast::{Arguments, Stmt}; +use rustpython_parser::ast; use crate::PythonProgram; @@ -80,8 +80,7 @@ fn emit_args<'a>(args: &'a Arguments, str_buffer: &mut WritingBuffer<'a>) { fn emit_body<'a>(body: &'a [Stmt], str_buffer: &mut WritingBuffer<'a>) { for stmt in body.iter() { match &stmt { - Stmt::Import(ast::StmtImport { range: _ , names: _ }) => - todo!(), + Stmt::Import(ast::StmtImport { range: _, names: _ }) => todo!(), Stmt::FunctionDef(ast::StmtFunctionDef { range: _, name, @@ -154,18 +153,12 @@ fn emit_body<'a>(body: &'a [Stmt], str_buffer: &mut WritingBuffer<'a>) { str_buffer.finish_line() } - Stmt::Expr(ast::StmtExpr { - range: _, - value - }) => { + Stmt::Expr(ast::StmtExpr { range: _, value }) => { str_buffer.push(Cow::Owned(format!("{}", value))); str_buffer.finish_line() } _ => { - panic!( - "Have not implemented how to print: {:?}", - stmt - ) + panic!("Have not implemented how to print: {:?}", stmt) } } } diff --git a/crates/python_utilities/src/lib.rs b/crates/python_utilities/src/lib.rs index 557c7e5c..9e61ec53 100644 --- a/crates/python_utilities/src/lib.rs +++ b/crates/python_utilities/src/lib.rs @@ -1,5 +1,5 @@ -use rustpython_parser::{Parse, ast}; use ast::Stmt; +use rustpython_parser::{ast, Parse}; pub mod ast_builder; pub mod ast_printer; From 6a6012d3bece893862891b052f230f6112ed35eb Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 20 Mar 2024 17:38:35 -0400 Subject: [PATCH 3/3] Switched forked rustpython-parser The published version doesn't compile on latest Rust. --- crates/Cargo.lock | 21 +++++++++------------ crates/driver/Cargo.toml | 4 ++-- crates/python_extractor/Cargo.toml | 4 ++-- crates/python_utilities/Cargo.toml | 4 ++-- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/crates/Cargo.lock b/crates/Cargo.lock index 6170ea7d..07a8ddf4 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -1382,8 +1382,7 @@ dependencies = [ [[package]] name = "rustpython-ast" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf9438da3660e6b88bd659fdc0cd13bcff4b85c584026a48b800c75bf0f8d00" +source = "git+https://github.com/bazeltools/rustpython-parser.git?rev=6f98c334d5ed709e6aa1a03ec1e20bd37859b867#6f98c334d5ed709e6aa1a03ec1e20bd37859b867" dependencies = [ "is-macro", "malachite-bigint", @@ -1395,8 +1394,7 @@ dependencies = [ [[package]] name = "rustpython-literal" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5d470a3e68cd776bb7590363d75c72d94b51e917847721847ab505c98b9397a" +source = "git+https://github.com/bazeltools/rustpython-parser.git?rev=6f98c334d5ed709e6aa1a03ec1e20bd37859b867#6f98c334d5ed709e6aa1a03ec1e20bd37859b867" dependencies = [ "hexf-parse", "is-macro", @@ -1408,8 +1406,7 @@ dependencies = [ [[package]] name = "rustpython-parser" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9db993974ff12f33c5be8a801741463691502f85ead5c503277937c4077bd92a" +source = "git+https://github.com/bazeltools/rustpython-parser.git?rev=6f98c334d5ed709e6aa1a03ec1e20bd37859b867#6f98c334d5ed709e6aa1a03ec1e20bd37859b867" dependencies = [ "anyhow", "is-macro", @@ -1432,8 +1429,7 @@ dependencies = [ [[package]] name = "rustpython-parser-core" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e9d560c6dd4dc774d4bbad48c770e074c178c4ed5f6fd0521fcdb639af21bdd" +source = "git+https://github.com/bazeltools/rustpython-parser.git?rev=6f98c334d5ed709e6aa1a03ec1e20bd37859b867#6f98c334d5ed709e6aa1a03ec1e20bd37859b867" dependencies = [ "is-macro", "memchr", @@ -1443,8 +1439,7 @@ dependencies = [ [[package]] name = "rustpython-parser-vendored" version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ae3062d7fe5fe38073f3a1c7145ed9a04e15f6e4a596d642c7db2d5cd2b51b" +source = "git+https://github.com/bazeltools/rustpython-parser.git?rev=6f98c334d5ed709e6aa1a03ec1e20bd37859b867#6f98c334d5ed709e6aa1a03ec1e20bd37859b867" dependencies = [ "memchr", "once_cell", @@ -1826,8 +1821,10 @@ checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode_names2" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446c96c6dd42604779487f0a981060717156648c1706aa1f464677f03c6cc059" +source = "git+https://github.com/youknowone/unicode_names2.git?rev=4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde#4ce16aa85cbcdd9cc830410f1a72ef9a235f2fde" +dependencies = [ + "phf", +] [[package]] name = "utf8parse" diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index e903bb9e..b9f7f9e6 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -18,8 +18,8 @@ thiserror = "1.0.58" lazy_static = "1.4.0" ignore = "0.4.22" globset = "0.4.14" -rustpython-parser = "0.3.0" -rustpython-ast = { version = "0.3.0", features = ["unparse"] } +rustpython-parser = { git = "https://github.com/bazeltools/rustpython-parser.git", rev = "6f98c334d5ed709e6aa1a03ec1e20bd37859b867" } +rustpython-ast = { git = "https://github.com/bazeltools/rustpython-parser.git", rev = "6f98c334d5ed709e6aa1a03ec1e20bd37859b867", features = ["unparse"] } pretty_env_logger = "0.5.0" log = "0.4.21" diff --git a/crates/python_extractor/Cargo.toml b/crates/python_extractor/Cargo.toml index 53559a37..11509e03 100644 --- a/crates/python_extractor/Cargo.toml +++ b/crates/python_extractor/Cargo.toml @@ -16,8 +16,8 @@ sha2 = { version = "0.10.8", features = ["asm"] } thiserror = "1.0.58" lazy_static = "1.4.0" ignore = "0.4.22" -rustpython-parser = "0.3.0" -rustpython-ast = { version = "0.3.0", features = ["unparse"] } +rustpython-parser = { git = "https://github.com/bazeltools/rustpython-parser.git", rev = "6f98c334d5ed709e6aa1a03ec1e20bd37859b867" } +rustpython-ast = { git = "https://github.com/bazeltools/rustpython-parser.git", rev = "6f98c334d5ed709e6aa1a03ec1e20bd37859b867", features = ["unparse"] } pretty_env_logger = "0.5.0" log = "0.4.21" encoding_rs = "0.8.33" diff --git a/crates/python_utilities/Cargo.toml b/crates/python_utilities/Cargo.toml index 1978656d..22a8352e 100644 --- a/crates/python_utilities/Cargo.toml +++ b/crates/python_utilities/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" [dependencies] anyhow = "1.0.81" -rustpython-parser = "0.3.0" -rustpython-ast = { version = "0.3.0", features = ["unparse"] } +rustpython-parser = { git = "https://github.com/bazeltools/rustpython-parser.git", rev = "6f98c334d5ed709e6aa1a03ec1e20bd37859b867" } +rustpython-ast = { git = "https://github.com/bazeltools/rustpython-parser.git", rev = "6f98c334d5ed709e6aa1a03ec1e20bd37859b867", features = ["unparse"] } \ No newline at end of file