Skip to content

Commit 1e4e679

Browse files
committed
fixed python student file policy
1 parent e282b74 commit 1e4e679

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

plugins/python3/src/policy.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ impl StudentFilePolicy for Python3StudentFilePolicy {
2222
}
2323

2424
fn is_student_source_file(&self, path: &Path) -> bool {
25-
// .py files in exercise root, and all non-pyc or __pycache__ files in src
26-
match path.parent() {
27-
Some(parent) => {
28-
parent == OsStr::new("src")
29-
&& path.extension() != Some(OsStr::new("pyc"))
30-
&& !path
31-
.components()
32-
.any(|c| c.as_os_str() == OsStr::new("__pycache__"))
33-
}
34-
None => path.extension() == Some(OsStr::new("py")),
35-
}
25+
// all non-pyc or __pycache__ files in src are student source files
26+
let in_src = path.starts_with("src");
27+
let is_cache_file = path.extension() == Some(OsStr::new("pyc"))
28+
|| path
29+
.components()
30+
.any(|c| c.as_os_str() == OsStr::new("__pycache__"));
31+
// .py files in exercise root are student source files
32+
let is_py_in_root = path.extension() == Some(OsStr::new("py")) && path.parent().is_none();
33+
34+
in_src && !is_cache_file || is_py_in_root
3635
}
3736
}
3837

tmc-langs-framework/src/io/tmc_zip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn zip<P: StudentFilePolicy>(policy: P, root_directory: &Path) -> Result<Vec
2121
.filter_entry(|e| !contains_tmcnosubmit(e))
2222
.filter_map(|e| e.ok())
2323
{
24-
log::trace!("processing {:?}", entry.path());
24+
log::trace!("processing {}", entry.path().display());
2525
if policy.is_student_file(entry.path(), &root_directory, &tmc_project_yml)? {
2626
let path = root_directory
2727
.parent()

tmc-langs-framework/src/policy.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub trait StudentFilePolicy {
4141
let root_canon = project_root_path
4242
.canonicalize()
4343
.map_err(|e| TmcError::Canonicalize(project_root_path.to_path_buf(), e))?;
44-
log::debug!("{} {}", path_canon.display(), root_canon.display());
4544

4645
// the project root path should be considered a student file
4746
if path_canon == root_canon {

0 commit comments

Comments
 (0)