diff --git a/Cargo.lock b/Cargo.lock index 8b7d9a7..57db644 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" + [[package]] name = "bitflags" version = "1.3.2" @@ -89,6 +95,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + [[package]] name = "cc" version = "1.0.83" @@ -119,6 +131,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + [[package]] name = "crunchy" version = "0.2.2" @@ -155,13 +176,14 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "els" -version = "0.1.32-nightly.2" +version = "0.1.33-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d64ff7aa566fa24ecc955cb17649f65eaa0401926a43785589864ebad8da4cd9" +checksum = "8d90ce06b81836342feef59d9f1730340b39e32a9f488827c12919e3a9784cb2" dependencies = [ "erg_common", "erg_compiler", "lsp-types", + "molc", "serde", "serde_json", ] @@ -172,7 +194,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af36f591236d9d822425cb6896595658fa558fcebf5ee8accac1d4b92c47166e" dependencies = [ - "base64", + "base64 0.13.1", "proc-macro2", "quote", "syn 1.0.109", @@ -180,9 +202,9 @@ dependencies = [ [[package]] name = "erg_common" -version = "0.6.20-nightly.2" +version = "0.6.21-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5938643fcee96603ff9d1df6df3a5b088079d7e2122607fd9d374f60440cf02" +checksum = "8c9e3dc0e21777787ea3fdc174f29fd6cdc8d7a6d671fcf7ed583c5f2c614956" dependencies = [ "backtrace-on-stack-overflow", "parking_lot", @@ -191,9 +213,9 @@ dependencies = [ [[package]] name = "erg_compiler" -version = "0.6.20-nightly.2" +version = "0.6.21-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c88aaafbbe1eb293316e1e78af55acae6e840580f9b5a74aeed387a27c8c8988" +checksum = "dfff095a4ce56412940dcf8d43e6897f85242365a9529c0d7e0cb10029668090" dependencies = [ "erg_common", "erg_parser", @@ -201,14 +223,24 @@ dependencies = [ [[package]] name = "erg_parser" -version = "0.6.20-nightly.2" +version = "0.6.21-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a129213e4217d11ac5420afdb8e63bcca553d1cc4900e977f7619c4e1c801a6" +checksum = "8a76f132bafed4fd84fb90a1c8f3ecde6a238f462ab2e8ca18e9d19ac27fd07c" dependencies = [ "erg_common", "unicode-xid", ] +[[package]] +name = "flate2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -292,6 +324,15 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "keccak" version = "0.1.4" @@ -425,6 +466,17 @@ dependencies = [ "adler", ] +[[package]] +name = "molc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19b669aab31ca7552fc43cb9ab08e325113aa090f7bf97a2112b3d6241ba898" +dependencies = [ + "lsp-types", + "serde", + "serde_json", +] + [[package]] name = "nix" version = "0.23.2" @@ -597,6 +649,7 @@ dependencies = [ "py2erg", "rustpython-ast", "rustpython-parser", + "ureq", ] [[package]] @@ -673,6 +726,21 @@ dependencies = [ "bitflags", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -694,6 +762,38 @@ dependencies = [ "semver", ] +[[package]] +name = "rustls" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" +dependencies = [ + "log", + "ring", + "rustls-webpki 0.101.4", + "sct", +] + +[[package]] +name = "rustls-webpki" +version = "0.100.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e98ff011474fa39949b7e5c0428f9b4937eda7da7848bbb947786b7be0b27dab" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d93931baf2d282fff8d3a532bbfd7653f734643161b87e3e01e59a04439bf0d" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustpython-ast" version = "0.3.0" @@ -763,6 +863,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "semver" version = "1.0.18" @@ -835,6 +945,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "static_assertions" version = "1.1.0" @@ -988,6 +1104,28 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "446c96c6dd42604779487f0a981060717156648c1706aa1f464677f03c6cc059" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "ureq" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9" +dependencies = [ + "base64 0.21.3", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-webpki 0.100.2", + "url", + "webpki-roots", +] + [[package]] name = "url" version = "2.4.1" @@ -1012,6 +1150,101 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.31", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.31", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" +dependencies = [ + "rustls-webpki 0.100.2", +] + +[[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-targets" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 1be8f9b..049b82a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ edition = "2021" repository = "https://github.com/mtshiba/pylyzer" [workspace.dependencies] -erg_common = { version = "0.6.20-nightly.2", features = ["py_compat", "els"] } -erg_compiler = { version = "0.6.20-nightly.2", features = ["py_compat", "els"] } -els = { version = "0.1.32-nightly.2", features = ["py_compat"] } +erg_common = { version = "0.6.21-nightly.1", features = ["py_compat", "els"] } +erg_compiler = { version = "0.6.21-nightly.1", features = ["py_compat", "els"] } +els = { version = "0.1.33-nightly.1", features = ["py_compat"] } rustpython-parser = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } rustpython-ast = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } # rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } @@ -50,6 +50,7 @@ els = { workspace = true } rustpython-parser = { workspace = true } rustpython-ast = { workspace = true } py2erg = { version = "0.0.43", path = "./crates/py2erg" } +ureq = "2" [lib] path = "src/lib.rs" diff --git a/README.md b/README.md index 201b629..36099ef 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ ## Installation +### pip + +```bash +pip install pylyzer +``` + ### cargo (rust package manager) ```bash @@ -25,18 +31,6 @@ cargo install --path . Make sure that `cargo/rustc` is up-to-date, as pylyzer may be written with the latest language features. -### pip - -```bash -pip install pylyzer -``` - -__If installed this way, you also need to [install Erg](https://github.com/mtshiba/ergup).__ - -```bash -curl -L https://github.com/mtshiba/ergup/raw/main/ergup.py | python3 -``` - ### [GitHub Releases](https://github.com/mtshiba/pylyzer/releases/latest) ## What is the advantage over pylint, pyright, pytype, etc.? diff --git a/src/download.rs b/src/download.rs new file mode 100644 index 0000000..7cb65f5 --- /dev/null +++ b/src/download.rs @@ -0,0 +1,16 @@ +use std::error::Error; + +use erg_common::env::erg_path; +use erg_common::python_util::exec_py_code; + +#[allow(unused)] +pub(crate) fn download_dependencies() -> Result<(), Box> { + if erg_path().exists() { + return Ok(()); + } + println!("Erg standard library not found. Installing..."); + let install_script_url = "https://github.com/mtshiba/ergup/raw/main/ergup.py"; + let code = ureq::get(install_script_url).call()?.into_string()?; + exec_py_code(&code, &[])?; + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index f83b4e6..22e397d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ mod analyze; mod config; +mod download; mod handle_err; pub use analyze::PythonAnalyzer; diff --git a/src/main.rs b/src/main.rs index cf4bffa..a67862c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,19 @@ mod analyze; mod config; +mod download; mod handle_err; use analyze::{PythonAnalyzer, SimplePythonParser}; +use download::download_dependencies; use els::Server; use erg_common::config::ErgMode; use erg_common::spawn::exec_new_thread; fn run() { + download_dependencies().unwrap(); let cfg = config::parse_args(); if cfg.mode == ErgMode::LanguageServer { - let mut lang_server = Server::::new(cfg); + let mut lang_server = Server::::new(cfg, None); lang_server.run().unwrap_or_else(|_| { std::process::exit(1); });