Skip to content

Commit 70595dd

Browse files
Fix/python files filtering (#318)
* fix: explicitly check if file is a jupyter notebook instead of using glob pattern * test: rewrote test to check the inclusion of python files * chore: rewrite an outdated comment
1 parent 18df4b8 commit 70595dd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

grader_service/convert/converters/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ def matches_allowed_patterns(file_path):
264264
"""
265265
Check if a file matches any of the allowed glob patterns.
266266
"""
267+
# Note: ignoring notebooks is needed to not overwrite converted notebooks
268+
# with the original ones as currently the copying process is done after the conversion
269+
if file_path.endswith(".ipynb"):
270+
return False
267271
return any(fnmatch.fnmatch(file_path, pattern) for pattern in files_patterns)
268272

269273
def is_ignored(file_path):

grader_service/tests/convert/converters/test_generate_assignment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@ def test_generate_assignment_no_copy_with_files(tmp_path):
4343

4444
def test_generate_assignment_copy_with_files(tmp_path):
4545
input_dir, output_dir = _create_input_output_dirs(tmp_path, ["simple.ipynb"])
46-
test_file = input_dir / "test.txt"
46+
test_file = input_dir / "test.py"
4747
test_file.touch()
4848
assert test_file.exists()
4949

5050
GenerateAssignment(
5151
input_dir=str(input_dir),
5252
output_dir=str(output_dir),
5353
file_pattern="*.ipynb",
54-
assignment_settings=AssignmentSettings(allowed_files=["*[!.ipynb]"]),
54+
assignment_settings=AssignmentSettings(allowed_files=["*"]),
5555
config=None,
5656
).start()
5757

5858
assert (output_dir / "simple.ipynb").exists()
5959
# Ensure the notebook was converted
6060
assert "BEGIN SOLUTION" not in (output_dir / "simple.ipynb").read_text()
6161
assert (output_dir / "gradebook.json").exists()
62-
assert (output_dir / "test.txt").exists()
62+
assert (output_dir / "test.py").exists()
6363

6464

6565
def test_generate_assignment_copy_with_dirs(tmp_path):

0 commit comments

Comments
 (0)