@@ -20,33 +20,20 @@ impl StudentFilePolicy for Python3StudentFilePolicy {
2020 }
2121
2222 fn is_non_extra_student_file ( & self , path : & Path ) -> bool {
23- // no files in tmc, test and venv subdirectories are considered student files
24- let is_cache_file = path. extension ( ) == Some ( OsStr :: new ( "pyc" ) )
25- || path
26- . components ( )
27- . 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 {
23+ // never include pyc files
24+ let is_pyc = path. extension ( ) == Some ( OsStr :: new ( "pyc" ) ) ;
25+ if is_pyc {
3126 return false ;
3227 }
3328
34- // all non-pyc or __pycache__ files in src are student source files
3529 let in_src = path. starts_with ( "src" ) ;
36- // .py files in exercise root are student source files
37- let is_in_project_root = match path. parent ( ) {
30+ let in_exercise_root = match path. parent ( ) {
3831 Some ( s) => s. as_os_str ( ) . is_empty ( ) ,
3932 None => true ,
4033 } ;
41- let is_py_file = path. extension ( ) == Some ( OsStr :: new ( "py" ) ) ;
34+ let is_py = path. extension ( ) == Some ( OsStr :: new ( "py" ) ) ;
4235 let is_ipynb = path. extension ( ) == Some ( OsStr :: new ( "ipynb" ) ) ;
43-
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
47- || is_in_project_root && is_py_file
48- || !is_in_exercise_subdir && !is_in_project_root
49- || is_ipynb
36+ ( in_src || in_exercise_root) && ( is_py || is_ipynb)
5037 }
5138}
5239
@@ -83,10 +70,10 @@ mod test {
8370 }
8471
8572 #[ test]
86- fn subdirs_are_student_files ( ) {
73+ fn subdirs_are_not_student_files ( ) {
8774 let policy = Python3StudentFilePolicy :: new ( Path :: new ( "." ) ) . unwrap ( ) ;
88- assert ! ( policy. is_student_file( Path :: new( "subdir/something" ) ) ) ;
89- assert ! ( policy. is_student_file( Path :: new( "another/mid/else" ) ) ) ;
75+ assert ! ( ! policy. is_student_file( Path :: new( "subdir/something" ) ) ) ;
76+ assert ! ( ! policy. is_student_file( Path :: new( "another/mid/else" ) ) ) ;
9077 }
9178
9279 #[ test]
0 commit comments