Skip to content

Commit

Permalink
feat(build): #3 ignore paths
Browse files Browse the repository at this point in the history
- Add `ignore` crate to the project
- Replace `walkdir` with `ignore` in `cognitive_complexity` module
- Sort the files by path in `cognitive_complexity` module
- Remove commented code in `cognitive_complexity` module
  • Loading branch information
rohaquinlop committed Feb 15, 2024
1 parent 4424e52 commit a7d94dc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
41 changes: 40 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ crate-type = ["cdylib"]

[dependencies]
env_logger = "0.11.1"
ignore = "0.4.22"
log = "0.4.20"
pyo3 = "0.19.0"
rayon = "1.8.1"
rustpython-parser = { git = "https://github.com/RustPython/Parser.git", rev = "9ce55aefdeb35e2f706ce0b02d5a2dfe6295fc57" }
walkdir = "2.4.0"
17 changes: 5 additions & 12 deletions src/cognitive_complexity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod utils;

use crate::classes::FileComplexity;
use ignore::Walk;
use pyo3::prelude::*;
use rayon::prelude::*;
use rustpython_parser::{
Expand All @@ -9,7 +10,6 @@ use rustpython_parser::{
};
use std::path;
use utils::{count_bool_ops, has_recursive_calls, is_decorator};
use walkdir::WalkDir;

// Main function
#[pyfunction]
Expand All @@ -26,6 +26,8 @@ pub fn main(path: &str, is_dir: bool, max_complexity: usize) -> PyResult<Vec<Fil
Err(e) => return Err(e),
}
}

ans.sort_by_key(|f| f.path.clone());
Ok(ans)
}

Expand All @@ -34,13 +36,11 @@ pub fn evaluate_dir(path: &str, max_complexity: usize) -> PyResult<Vec<FileCompl
let mut files_paths: Vec<String> = Vec::new();

// Get all the python files in the directory
for entry in WalkDir::new(path) {
for entry in Walk::new(path) {
let entry = entry.unwrap();
let file_path_str = entry.path().to_str().unwrap();

if entry.file_type().is_file()
&& entry.path().extension().and_then(|s| s.to_str()) == Some("py")
{
if entry.path().extension().and_then(|s| s.to_str()) == Some("py") {
files_paths.push(file_path_str.to_string());
}
}
Expand Down Expand Up @@ -78,13 +78,6 @@ pub fn file_cognitive_complexity(
complexity += statement_cognitive_complexity(node.clone(), 0)?;
}

// if max_complexity > 0 && complexity > max_complexity as u64 {
// return Err(PyErr::new::<pyo3::exceptions::PyException, _>(format!(
// "{}: Cognitive complexity of {} exceeds the maximum allowed complexity of {}.",
// file_name, complexity, max_complexity
// )));
// }

println!("{}", file_name);

Ok(FileComplexity {
Expand Down

0 comments on commit a7d94dc

Please sign in to comment.