From a89fd3416cb1eb9b0d34fc514d79cbf85b0e856a Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 16 Jun 2023 18:30:13 +0000 Subject: [PATCH] `metrics.py` --- .gitignore | 1 + .vscode/settings.json | 3 ++- metrics.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 metrics.py diff --git a/.gitignore b/.gitignore index d97d817..380e46f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /Cargo.lock **/*.rs.bk metrics.ansi +metrics.txt diff --git a/.vscode/settings.json b/.vscode/settings.json index ab2a30d..2fc1d4b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,6 @@ 99, 100 ] - } + }, + "python.analysis.typeCheckingMode": "basic" } \ No newline at end of file diff --git a/metrics.py b/metrics.py new file mode 100644 index 0000000..4c18bd7 --- /dev/null +++ b/metrics.py @@ -0,0 +1,37 @@ +import json +from subprocess import check_output + +all_entries = [] + + +def save_entry(entry: dict, prefix=""): + name = entry["name"] = prefix + entry["name"] + spaces = entry.pop("spaces") + all_entries.append(entry) + for space in spaces: + save_entry(space, f"{name}::") + + +def main(): + lines = check_output( + ["rust-code-analysis-cli", "-m", "-p", "src", "-O", "json"], text=True + ).splitlines() + for line in lines: + entry = json.loads(line) + assert entry["kind"] == "unit" + assert entry["start_line"] == 1 + assert entry["end_line"] >= entry["start_line"] + save_entry(entry) + all_entries.sort( + key=lambda entry: ( + entry["metrics"]["halstead"]["bugs"] or 0, + entry["metrics"]["halstead"]["volume"], + ), + reverse=True, + ) + for entry in all_entries: + # print(*entry["metrics"]) + print(entry["name"], entry["metrics"]["halstead"]) + + +main()