Skip to content

Commit c2f0a7f

Browse files
committed
fix: Fix submission file filtering when '*' whitelist pattern is specified in the assignment
1 parent c4d3bba commit c2f0a7f

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

grader_service/autograding/git_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def _commit_files(self, filenames: List[str], output_path: str) -> None:
109109
self.log.info("No files to commit.")
110110
return
111111

112+
# Make sure we do not commit the gradebook.json
113+
filenames = [f for f in filenames if f != "gradebook.json"]
114+
112115
self._run_git([self.git_executable, "add", "--", *filenames], output_path)
113116
self._run_git(
114117
[self.git_executable, "commit", "-m", self.submission.commit_hash], output_path

grader_service/convert/converters/base.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,9 @@ def init_destination(self) -> bool:
236236
return False
237237
return True
238238

239-
def copy_unmatched_files(self, gb: Gradebook):
240-
"""
241-
Copy the files from source to the output directory that match the allowed file patterns,
242-
excluding files and directories that match any of the ignore patterns.
243-
:return: None
244-
"""
245-
dst = self._output_directory
246-
src = self._input_directory
247-
239+
def get_include_patterns(self, gb: Gradebook) -> List[str]:
240+
"""Get glob patterns specifying which submission files to copy."""
248241
allowed_files = self._assignment_settings.allowed_files
249-
ignore_patterns = self.ignore # List of patterns to ignore
250-
251242
if allowed_files is None:
252243
self.log.info(
253244
"No additional file patterns specified; only copying files included "
@@ -257,6 +248,19 @@ def copy_unmatched_files(self, gb: Gradebook):
257248
else:
258249
self.log.info(f"Found additional file patterns: {allowed_files}")
259250
files_patterns = allowed_files + gb.get_extra_files()
251+
return files_patterns
252+
253+
def copy_unmatched_files(self, gb: Gradebook):
254+
"""
255+
Copy the files from source to the output directory that match the allowed file patterns,
256+
excluding files and directories that match any of the ignore patterns.
257+
:return: None
258+
"""
259+
dst = self._output_directory
260+
src = self._input_directory
261+
262+
ignore_patterns = self.ignore # List of patterns to ignore
263+
files_patterns = self.get_include_patterns(gb)
260264

261265
copied_files = []
262266

@@ -285,9 +289,6 @@ def is_ignored(file_path):
285289
] # Modify dirs in-place to ignore unwanted dirs
286290

287291
for file in files:
288-
if file == "gradebook.json":
289-
continue
290-
291292
abs_file_path = os.path.join(root, file)
292293
rel_file_path = os.path.relpath(abs_file_path, src)
293294

grader_service/convert/converters/generate_feedback.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from grader_service.convert import utils
1111
from grader_service.convert.converters.base import BaseConverter
1212
from grader_service.convert.converters.baseapp import ConverterApp
13-
from grader_service.convert.gradebook.gradebook import MissingEntry
13+
from grader_service.convert.gradebook.gradebook import Gradebook
1414
from grader_service.convert.preprocessors import GetGrades
1515

1616

@@ -55,17 +55,21 @@ def __init__(
5555
self.update_config(c)
5656
self.force = True # always overwrite generated assignments
5757

58-
def convert_single_notebook(self, notebook_filename: str) -> None:
59-
"""Generate feedback for a single notebook.
58+
def init_notebooks(self) -> None:
59+
# We only generate feedback for the notebooks for which there is a gradebook entry,
60+
# and ignore e.g. additional notebooks created by the student, because feedback
61+
# generation would fail for them anyway.
62+
json_path = os.path.join(self._output_directory, "gradebook.json")
63+
with Gradebook(json_path) as gb:
64+
self.notebooks = [f"{nb_id}.ipynb" for nb_id in gb.model.notebook_id_set]
6065

61-
We ignore any notebooks for which there are no gradebook entries
62-
(e.g. additional notebooks created by the student), because feedback
63-
generation would fail for them anyway.
66+
def get_include_patterns(self, gb: Gradebook) -> list[str]:
67+
"""Get glob patterns specifying for which submission files to generate feedback.
68+
69+
In case of feedback generation, it can only be done for the notebooks
70+
which were included in the original assignment.
6471
"""
65-
try:
66-
super().convert_single_notebook(notebook_filename)
67-
except MissingEntry:
68-
self.log.info("Skipping notebook %s", notebook_filename)
72+
return self.notebooks
6973

7074

7175
class GenerateFeedbackApp(ConverterApp):

0 commit comments

Comments
 (0)