mirror of https://github.com/mtshiba/pylyzer
Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
b7e78b310c | |
|
|
83bd0ffc61 | |
|
|
f0a44bf272 |
|
|
@ -6,5 +6,8 @@
|
||||||
"[typescript]": {
|
"[typescript]": {
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.defaultFormatter": "biomejs.biome"
|
"editor.defaultFormatter": "biomejs.biome"
|
||||||
}
|
},
|
||||||
|
"cSpell.words": [
|
||||||
|
"indexmap"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -152,9 +152,9 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "els"
|
name = "els"
|
||||||
version = "0.1.65-nightly.2"
|
version = "0.1.65-nightly.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1dd708f21ce87a184ff5c9010afe61169b021a986fa1f0480ce93f7069308b34"
|
checksum = "5cbf48dcb22f23c344ebcf751ba479ea2d770782826659d5ac0e341f6b971432"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
|
@ -167,10 +167,16 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_common"
|
name = "equivalent"
|
||||||
version = "0.6.53-nightly.2"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc22c2d3966dfd49dc4e3d142a4c066acfbc2debbf807bd80239640263f82906"
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "erg_common"
|
||||||
|
version = "0.6.53-nightly.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e712be33223eb2376056e5864c32290b592058c5ebdfaf27562e5196cb6ae74a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace-on-stack-overflow",
|
"backtrace-on-stack-overflow",
|
||||||
"erg_proc_macros",
|
"erg_proc_macros",
|
||||||
|
|
@ -181,9 +187,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_compiler"
|
name = "erg_compiler"
|
||||||
version = "0.6.53-nightly.2"
|
version = "0.6.53-nightly.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "33a71fd95255b255147476dba4b043babe82350d1b32c3bd2b716b5c801ac455"
|
checksum = "84555ce7074c7c068f64393630add858d5b4d9ccd9c304f5c8274ddae291c58c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_parser",
|
"erg_parser",
|
||||||
|
|
@ -191,9 +197,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_parser"
|
name = "erg_parser"
|
||||||
version = "0.6.53-nightly.2"
|
version = "0.6.53-nightly.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "283375be7368b88ab745eeb2530c4a276325d36d41f664935c6521cd2afe4043"
|
checksum = "e28e444531ca109213845ff38f96e1717f26018ed7cc857e5c8fd4ff29bf3800"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_proc_macros",
|
"erg_proc_macros",
|
||||||
|
|
@ -202,9 +208,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erg_proc_macros"
|
name = "erg_proc_macros"
|
||||||
version = "0.6.53-nightly.2"
|
version = "0.6.53-nightly.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "222a96d889f1f49149a1d20e634096a82fc575dfe49661d8e713ebcfb152ef71"
|
checksum = "dbe0c49c58f7bd9003582c725ce0050bcac6c3754f408e24793c0a29102de9ce"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -260,6 +266,12 @@ dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.15.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
|
@ -405,6 +417,16 @@ dependencies = [
|
||||||
"icu_properties",
|
"icu_properties",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "indexmap"
|
||||||
|
version = "2.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
|
||||||
|
dependencies = [
|
||||||
|
"equivalent",
|
||||||
|
"hashbrown 0.15.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is-macro"
|
name = "is-macro"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
|
|
@ -502,7 +524,7 @@ version = "0.4.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5ea0ed76adf7defc1a92240b5c36d5368cfe9251640dcce5bd2d0b7c1fd87aeb"
|
checksum = "5ea0ed76adf7defc1a92240b5c36d5368cfe9251640dcce5bd2d0b7c1fd87aeb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown",
|
"hashbrown 0.14.5",
|
||||||
"itertools",
|
"itertools",
|
||||||
"libm",
|
"libm",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
|
@ -717,7 +739,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "py2erg"
|
name = "py2erg"
|
||||||
version = "0.0.81"
|
version = "0.0.82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
|
@ -727,18 +749,19 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pylyzer"
|
name = "pylyzer"
|
||||||
version = "0.0.81"
|
version = "0.0.82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"els",
|
"els",
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
"glob",
|
"glob",
|
||||||
|
"indexmap",
|
||||||
"pylyzer_core",
|
"pylyzer_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pylyzer_core"
|
name = "pylyzer_core"
|
||||||
version = "0.0.81"
|
version = "0.0.82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
|
@ -749,7 +772,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pylyzer_wasm"
|
name = "pylyzer_wasm"
|
||||||
version = "0.0.81"
|
version = "0.0.82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erg_common",
|
"erg_common",
|
||||||
"erg_compiler",
|
"erg_compiler",
|
||||||
|
|
|
||||||
11
Cargo.toml
11
Cargo.toml
|
|
@ -17,16 +17,16 @@ members = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.0.81"
|
version = "0.0.82"
|
||||||
authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"]
|
authors = ["Shunsuke Shibayama <sbym1346@gmail.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/mtshiba/pylyzer"
|
repository = "https://github.com/mtshiba/pylyzer"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
erg_common = { version = "0.6.53-nightly.2", features = ["py_compat", "els"] }
|
erg_common = { version = "0.6.53-nightly.5", features = ["py_compat", "els"] }
|
||||||
erg_compiler = { version = "0.6.53-nightly.2", features = ["py_compat", "els"] }
|
erg_compiler = { version = "0.6.53-nightly.5", features = ["py_compat", "els"] }
|
||||||
els = { version = "0.1.65-nightly.2", features = ["py_compat"] }
|
els = { version = "0.1.65-nightly.5", features = ["py_compat"] }
|
||||||
# rustpython-parser = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] }
|
# 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-ast = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] }
|
||||||
rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.4.0", features = ["all-nodes-with-ranges", "location"] }
|
rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.4.0", features = ["all-nodes-with-ranges", "location"] }
|
||||||
|
|
@ -50,10 +50,11 @@ simplified_chinese = ["erg_common/simplified_chinese", "els/simplified_chinese"]
|
||||||
traditional_chinese = ["erg_common/traditional_chinese", "els/traditional_chinese"]
|
traditional_chinese = ["erg_common/traditional_chinese", "els/traditional_chinese"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pylyzer_core = { version = "0.0.81", path = "./crates/pylyzer_core" }
|
pylyzer_core = { version = "0.0.82", path = "./crates/pylyzer_core" }
|
||||||
erg_common = { workspace = true }
|
erg_common = { workspace = true }
|
||||||
els = { workspace = true }
|
els = { workspace = true }
|
||||||
glob = "0.3.2"
|
glob = "0.3.2"
|
||||||
|
indexmap = "2.7.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
erg_compiler = { workspace = true }
|
erg_compiler = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
# pylyzer ⚡
|
# pylyzer ⚡
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> pylyzer is now under the maintenance phase, which means that only bug fixes will be made and no new features will be added.
|
||||||
|
The author is currently cooperating with the development of [astral-sh/ty](https://github.com/astral-sh/ty). Please try that instead!
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
<a href="https://marketplace.visualstudio.com/items?itemName=pylyzer.pylyzer" target="_blank" rel="noreferrer noopener nofollow"><img src="https://img.shields.io/visual-studio-marketplace/v/pylyzer.pylyzer?style=flat&label=VS%20Marketplace&logo=visual-studio-code" alt="vsm-version"></a>
|
<a href="https://marketplace.visualstudio.com/items?itemName=pylyzer.pylyzer" target="_blank" rel="noreferrer noopener nofollow"><img src="https://img.shields.io/visual-studio-marketplace/v/pylyzer.pylyzer?style=flat&label=VS%20Marketplace&logo=visual-studio-code" alt="vsm-version"></a>
|
||||||
|
|
@ -41,7 +45,7 @@ Make sure that `cargo`/`rustc` is up-to-date, as pylyzer may be written with the
|
||||||
pylyzer file.py
|
pylyzer file.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## Check multiple files
|
### Check multiple files
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# glob patterns are supported
|
# glob patterns are supported
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ erg_common = { workspace = true }
|
||||||
erg_compiler = { workspace = true }
|
erg_compiler = { workspace = true }
|
||||||
rustpython-parser = { workspace = true }
|
rustpython-parser = { workspace = true }
|
||||||
rustpython-ast = { workspace = true }
|
rustpython-ast = { workspace = true }
|
||||||
py2erg = { version = "0.0.81", path = "../py2erg" }
|
py2erg = { version = "0.0.82", path = "../py2erg" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use erg_common::config::{ErgConfig, ErgMode};
|
||||||
use erg_common::io::Input;
|
use erg_common::io::Input;
|
||||||
use erg_common::pathutil::project_entry_file_of;
|
use erg_common::pathutil::project_entry_file_of;
|
||||||
use erg_common::switch_lang;
|
use erg_common::switch_lang;
|
||||||
|
use indexmap::IndexSet;
|
||||||
|
|
||||||
use crate::copy::clear_cache;
|
use crate::copy::clear_cache;
|
||||||
|
|
||||||
|
|
@ -49,7 +50,7 @@ OPTIONS
|
||||||
--clear-cache キャッシュをクリア
|
--clear-cache キャッシュをクリア
|
||||||
--code/-c cmd 文字列をプログラムに渡す
|
--code/-c cmd 文字列をプログラムに渡す
|
||||||
--dump-decl 型宣言ファイルを出力
|
--dump-decl 型宣言ファイルを出力
|
||||||
--disable 指定した機能を無効化",
|
--disable feat 指定した機能を無効化",
|
||||||
|
|
||||||
"simplified_chinese" =>
|
"simplified_chinese" =>
|
||||||
"\
|
"\
|
||||||
|
|
@ -67,7 +68,7 @@ OPTIONS
|
||||||
--clear-cache 清除缓存
|
--clear-cache 清除缓存
|
||||||
--code/-c cmd 作为字符串传入程序
|
--code/-c cmd 作为字符串传入程序
|
||||||
--dump-decl 输出类型声明文件
|
--dump-decl 输出类型声明文件
|
||||||
--disable 禁用指定功能",
|
--disable feat 禁用指定功能",
|
||||||
|
|
||||||
"traditional_chinese" =>
|
"traditional_chinese" =>
|
||||||
"\
|
"\
|
||||||
|
|
@ -85,7 +86,7 @@ OPTIONS
|
||||||
--clear-cache 清除快取
|
--clear-cache 清除快取
|
||||||
--code/-c cmd 作為字串傳入程式
|
--code/-c cmd 作為字串傳入程式
|
||||||
--dump-decl 輸出類型宣告檔案
|
--dump-decl 輸出類型宣告檔案
|
||||||
--disable 禁用指定功能",
|
--disable feat 禁用指定功能",
|
||||||
|
|
||||||
"english" =>
|
"english" =>
|
||||||
"\
|
"\
|
||||||
|
|
@ -103,7 +104,7 @@ OPTIONS
|
||||||
--clear-cache clear cache
|
--clear-cache clear cache
|
||||||
--code/-c cmd program passed in as string
|
--code/-c cmd program passed in as string
|
||||||
--dump-decl output type declaration file
|
--dump-decl output type declaration file
|
||||||
--disable disable specified features",
|
--disable feat disable specified features",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,21 +214,53 @@ For more information try `pylyzer --help`"
|
||||||
cfg
|
cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn files_to_be_checked() -> Vec<PathBuf> {
|
pub(crate) fn files_to_be_checked() -> IndexSet<Result<PathBuf, String>> {
|
||||||
let file_or_patterns = env::args()
|
let mut file_or_patterns = vec![];
|
||||||
.skip(1)
|
let mut args = env::args().skip(1);
|
||||||
.rev()
|
while let Some(arg) = &args.next() {
|
||||||
.take_while(|arg| !arg.starts_with("-"));
|
match arg.as_str() {
|
||||||
let mut files = vec![];
|
"--" => {
|
||||||
|
// Discard runtime args
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
"--code" | "-c" | "--disable" | "--verbose" => {
|
||||||
|
// Skip options
|
||||||
|
let _ = &args.next();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
file_or_pattern if file_or_pattern.starts_with("-") => {
|
||||||
|
// Skip flags
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_or_pattern => file_or_patterns.push(file_or_pattern.to_owned()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut files = IndexSet::new();
|
||||||
for file_or_pattern in file_or_patterns {
|
for file_or_pattern in file_or_patterns {
|
||||||
if PathBuf::from(&file_or_pattern).is_file() {
|
if PathBuf::from(&file_or_pattern).is_file() {
|
||||||
files.push(PathBuf::from(&file_or_pattern));
|
files.insert(Ok(PathBuf::from(&file_or_pattern)));
|
||||||
} else {
|
} else {
|
||||||
for entry in glob::glob(&file_or_pattern).expect("Failed to read glob pattern") {
|
let entries = glob::glob(&file_or_pattern);
|
||||||
match entry {
|
match entries {
|
||||||
Err(e) => eprintln!("err: {e}"),
|
Err(_) => {
|
||||||
Ok(path) if path.is_file() => files.push(path),
|
files.insert(Err(file_or_pattern));
|
||||||
_ => {}
|
continue;
|
||||||
|
}
|
||||||
|
Ok(entries) => {
|
||||||
|
let mut entries = entries.into_iter().peekable();
|
||||||
|
if entries.peek().is_none() {
|
||||||
|
files.insert(Err(file_or_pattern));
|
||||||
|
}
|
||||||
|
for entry in entries {
|
||||||
|
match entry {
|
||||||
|
Err(e) => eprintln!("err: {e}"),
|
||||||
|
Ok(path) if path.is_file() => {
|
||||||
|
files.insert(Ok(path));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
src/main.rs
22
src/main.rs
|
|
@ -4,6 +4,8 @@ mod copy;
|
||||||
use els::Server;
|
use els::Server;
|
||||||
use erg_common::config::ErgMode;
|
use erg_common::config::ErgMode;
|
||||||
use erg_common::spawn::exec_new_thread;
|
use erg_common::spawn::exec_new_thread;
|
||||||
|
use erg_common::style::colors::RED;
|
||||||
|
use erg_common::style::RESET;
|
||||||
use pylyzer_core::{PythonAnalyzer, SimplePythonParser};
|
use pylyzer_core::{PythonAnalyzer, SimplePythonParser};
|
||||||
|
|
||||||
use crate::config::files_to_be_checked;
|
use crate::config::files_to_be_checked;
|
||||||
|
|
@ -23,11 +25,21 @@ fn run() {
|
||||||
code = analyzer.run();
|
code = analyzer.run();
|
||||||
} else {
|
} else {
|
||||||
for path in files {
|
for path in files {
|
||||||
let cfg = cfg.inherit(path);
|
match path {
|
||||||
let mut analyzer = PythonAnalyzer::new(cfg);
|
Err(invalid_file_or_pattern) => {
|
||||||
let c = analyzer.run();
|
if code == 0 {
|
||||||
if c != 0 {
|
code = 1;
|
||||||
code = 1;
|
}
|
||||||
|
println!("{RED}Invalid file or pattern{RESET}: {invalid_file_or_pattern}");
|
||||||
|
}
|
||||||
|
Ok(path) => {
|
||||||
|
let cfg = cfg.inherit(path);
|
||||||
|
let mut analyzer = PythonAnalyzer::new(cfg);
|
||||||
|
let c = analyzer.run();
|
||||||
|
if c != 0 {
|
||||||
|
code = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue