Skip to content

Commit

Permalink
Merge pull request #24 from rohaquinlop/issue-23
Browse files Browse the repository at this point in the history
feat(build): #23 add progress bars
  • Loading branch information
rohaquinlop authored Mar 6, 2024
2 parents 6a7e16d + 2cc9666 commit fdb6401
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
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

0 comments on commit fdb6401

Please sign in to comment.