Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): #23 add progress bars #24

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ crate-type = ["cdylib"]
csv = "1.3.0"
env_logger = "0.11.1"
ignore = "0.4.22"
indicatif = "0.17.8"
log = "0.4.20"
pyo3 = "0.19.0"
rayon = "1.8.1"
Expand Down
45 changes: 41 additions & 4 deletions src/cognitive_complexity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ pub mod utils;

use crate::classes::{FileComplexity, FunctionComplexity};
use ignore::Walk;
use indicatif::ProgressBar;
use indicatif::ProgressStyle;
use pyo3::prelude::*;
use rayon::prelude::*;
use rustpython_parser::{
Expand All @@ -11,6 +13,8 @@ use rustpython_parser::{
use std::env;
use std::path;
use std::process;
use std::sync::{Arc, Mutex};
use std::thread;
use tempfile::tempdir;
use utils::{count_bool_ops, get_repo_name, is_decorator};

Expand All @@ -31,10 +35,30 @@ pub fn main(

env::set_current_dir(&dir)?;

let _output = process::Command::new("git")
.args(&["clone", path])
.output()
.expect("failed to execute process");
let cloning_done = Arc::new(Mutex::new(false));
let cloning_done_clone = Arc::clone(&cloning_done);
let path_clone = path.to_owned(); // Clone the path variable

thread::spawn(move || {
let _output = process::Command::new("git")
.args(&["clone", &path_clone]) // Use the cloned path variable
.output()
.expect("failed to execute process");

let mut done = cloning_done_clone.lock().unwrap();
*done = true;
});

let pb = ProgressBar::new_spinner();
pb.set_style(ProgressStyle::default_spinner());
pb.set_message("Cloning repository...");

while !*cloning_done.lock().unwrap() {
pb.tick();
thread::sleep(std::time::Duration::from_millis(100));
}

pb.finish_with_message("Repository cloned!");

let repo_path = dir.path().join(&repo_name).to_str().unwrap().to_string();

Expand Down Expand Up @@ -84,16 +108,29 @@ fn evaluate_dir(
}
}

let pb = ProgressBar::new(files_paths.len() as u64);
pb.set_style(
indicatif::ProgressStyle::default_bar()
.template(
"{spiner:.green} [{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
)
.unwrap()
.progress_chars("##-"),
);

let files_complexity_result: Result<Vec<FileComplexity>, PyErr> = files_paths
.par_iter()
.map(|file_path| {
pb.inc(1);
match cognitive_complexity(file_path, parent_dir, max_complexity, file_level) {
Ok(file_complexity) => Ok(file_complexity),
Err(e) => Err(e),
}
})
.collect();

pb.finish_with_message("Done!");

match files_complexity_result {
Ok(files_complexity) => Ok(files_complexity),
Err(e) => Err(e),
Expand Down
Loading