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): #3 ignore paths #6

Merged
merged 1 commit into from
Feb 15, 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
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
Loading