@@ -20,12 +20,19 @@ impl StudentFilePolicy for Python3StudentFilePolicy {
2020 }
2121
2222 fn is_non_extra_student_file ( & self , path : & Path ) -> bool {
23- // all non-pyc or __pycache__ files in src are student source files
24- let in_src = path. starts_with ( "src" ) ;
23+ // no files in tmc, test and venv subdirectories are considered student files
2524 let is_cache_file = path. extension ( ) == Some ( OsStr :: new ( "pyc" ) )
2625 || path
2726 . components ( )
2827 . any ( |c| c. as_os_str ( ) == OsStr :: new ( "__pycache__" ) ) ;
28+ let is_in_exercise_subdir = path. starts_with ( "test" ) || path. starts_with ( "tmc" ) ;
29+ let is_in_venv = path. starts_with ( ".venv" ) || path. starts_with ( "venv" ) ;
30+ if is_cache_file || is_in_exercise_subdir || is_in_venv {
31+ return false ;
32+ }
33+
34+ // all non-pyc or __pycache__ files in src are student source files
35+ let in_src = path. starts_with ( "src" ) ;
2936 // .py files in exercise root are student source files
3037 let is_in_project_root = match path. parent ( ) {
3138 Some ( s) => s. as_os_str ( ) . is_empty ( ) ,
@@ -34,13 +41,12 @@ impl StudentFilePolicy for Python3StudentFilePolicy {
3441 let is_py_file = path. extension ( ) == Some ( OsStr :: new ( "py" ) ) ;
3542 let is_ipynb = path. extension ( ) == Some ( OsStr :: new ( "ipynb" ) ) ;
3643
37- // all files in non-tmc and non-test subdirectories are considered student files
38- let is_in_exercise_subdir = path. starts_with ( "test" ) || path. starts_with ( "tmc" ) ;
39-
40- in_src && !is_cache_file
44+ // all in all, excluding cache files and the exception subdirs,
45+ // we take non-cache files in src, py files in root, everything not in the root and not in src, and all ipynb files
46+ in_src
4147 || is_in_project_root && is_py_file
42- || !is_in_exercise_subdir && !is_in_project_root && !is_cache_file
43- || is_ipynb && !is_cache_file
48+ || !is_in_exercise_subdir && !is_in_project_root
49+ || is_ipynb
4450 }
4551}
4652
@@ -96,4 +102,11 @@ mod test {
96102 assert ! ( !policy. is_student_file( Path :: new( "test" ) ) ) ;
97103 assert ! ( !policy. is_student_file( Path :: new( "root_file" ) ) ) ;
98104 }
105+
106+ #[ test]
107+ fn venv_dir_is_not_student_file ( ) {
108+ let policy = Python3StudentFilePolicy :: new ( Path :: new ( "." ) ) . unwrap ( ) ;
109+ assert ! ( !policy. is_student_file( Path :: new( "venv/asd.py" ) ) ) ;
110+ assert ! ( !policy. is_student_file( Path :: new( ".venv/asd.py" ) ) ) ;
111+ }
99112}
0 commit comments