assignment-codeval 0.0.26__py3-none-any.whl → 0.0.28__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,7 +62,7 @@ def _has_codeval_comment_after_submission(submission_node, codeval_prefix):
62
62
  comments = submission_node.get("commentsConnection", {}).get("nodes", [])
63
63
  for comment in comments:
64
64
  text = comment.get("comment", "")
65
- if not text.startswith(codeval_prefix):
65
+ if not text.startswith(codeval_prefix.rstrip()):
66
66
  continue
67
67
  created_at = comment.get("createdAt")
68
68
  if created_at and created_at > submitted_at:
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import re
3
+ import zipfile
3
4
 
4
5
  import markdown
5
6
 
@@ -41,19 +42,28 @@ def ansi_to_html(text):
41
42
  return ''.join(result)
42
43
 
43
44
 
44
- def _read_file_content(filename, spec_dir):
45
- """Read the content of a file referenced by an OF or IF tag."""
46
- if not spec_dir:
47
- return None
48
- filepath = os.path.join(spec_dir, filename)
49
- try:
50
- with open(filepath, 'r') as f:
51
- return f.read()
52
- except (FileNotFoundError, OSError):
53
- return None
45
+ def _read_file_content(filename, spec_dir, zip_archives=None):
46
+ """Read the content of a file referenced by an IF/OF/EF tag.
54
47
 
48
+ Searches local spec_dir first, then zip archives. Returns content as string.
49
+ """
50
+ if spec_dir:
51
+ filepath = os.path.join(spec_dir, filename)
52
+ try:
53
+ with open(filepath, 'r') as f:
54
+ return f.read()
55
+ except (FileNotFoundError, OSError):
56
+ pass
57
+ if zip_archives:
58
+ for zf in zip_archives:
59
+ try:
60
+ return zf.read(filename).decode('utf-8')
61
+ except KeyError:
62
+ continue
63
+ return None
55
64
 
56
- def sampleTestCases(listOfTC, numOfTC, spec_dir=None):
65
+
66
+ def sampleTestCases(listOfTC, numOfTC, spec_dir=None, zip_archives=None):
57
67
  counter = 0
58
68
  samples = "<pre><code>"
59
69
  for line in listOfTC:
@@ -64,7 +74,7 @@ def sampleTestCases(listOfTC, numOfTC, spec_dir=None):
64
74
  samples = samples + "\n" + "Command to RUN: " + line[2:]
65
75
  elif line.startswith('IF '):
66
76
  filename = line[3:].strip()
67
- content = _read_file_content(filename, spec_dir)
77
+ content = _read_file_content(filename, spec_dir, zip_archives)
68
78
  if content is not None:
69
79
  samples = samples + "<span style=\"color:green\">" + ansi_to_html(content) + "</span>"
70
80
  else:
@@ -75,7 +85,7 @@ def sampleTestCases(listOfTC, numOfTC, spec_dir=None):
75
85
  samples = samples + "<span style=\"color:green\">" + line[2:] + "</span>"
76
86
  elif line.startswith('OF '):
77
87
  filename = line[3:].strip()
78
- content = _read_file_content(filename, spec_dir)
88
+ content = _read_file_content(filename, spec_dir, zip_archives)
79
89
  if content is not None:
80
90
  samples = samples + "<span style=\"color:blue\">" + ansi_to_html(content) + "</span>"
81
91
  else:
@@ -86,6 +96,13 @@ def sampleTestCases(listOfTC, numOfTC, spec_dir=None):
86
96
  samples = samples + "<span style=\"color:blue\">" + line[2:] + "</span>"
87
97
  elif line.startswith('X '):
88
98
  samples = samples + "Expected Exit Code: " + line[2:]
99
+ elif line.startswith('EF '):
100
+ filename = line[3:].strip()
101
+ content = _read_file_content(filename, spec_dir, zip_archives)
102
+ if content is not None:
103
+ samples = samples + "<span style=\"color:Tomato\">" + ansi_to_html(content) + "</span>"
104
+ else:
105
+ samples = samples + "<span style=\"color:Tomato\">Expected error from file: " + filename + "\n</span>"
89
106
  elif line.startswith('EB '):
90
107
  samples = samples + "<span style=\"color:Tomato\">" + line[3:] + "</span>"
91
108
  elif line.startswith('E '):
@@ -104,24 +121,41 @@ def mdToHtml(file_name, files_resolver=None):
104
121
  compile_command = ""
105
122
  past_crt_hw = False
106
123
  numOfSampleTC = 1
124
+ zip_paths = []
107
125
  for line in f:
108
126
  if 'CRT_HW START' in line:
109
127
  assignment_name = line[13:].strip()
110
128
  elif 'CRT_HW END' in line:
111
129
  assignment = text
112
130
  past_crt_hw = True
113
- elif line.startswith(('T ', 'I ', 'IB ', 'IF ', 'O ', 'OB ', 'OF ', 'X ', 'E ', 'EB ')):
131
+ elif line.startswith(('T ', 'I ', 'IB ', 'IF ', 'O ', 'OB ', 'OF ',
132
+ 'EF ', 'X ', 'E ', 'EB ')):
114
133
  examples.append(line)
115
134
  elif line.startswith('HT '):
116
135
  break
117
136
  else:
118
137
  if past_crt_hw and line.startswith('C '):
119
138
  compile_command = line[2:].strip()
139
+ if past_crt_hw and line.startswith('Z '):
140
+ zip_paths.append(line[2:].strip())
120
141
  if 'EXMPLS ' in line:
121
142
  numOfSampleTC = int(line[7:])
122
143
  text = text + line
123
144
  spec_dir = os.path.dirname(os.path.abspath(file_name))
124
- samples = sampleTestCases(examples, numOfSampleTC, spec_dir)
145
+
146
+ # Open zip archives for IF/OF/EF file resolution
147
+ zip_archives = []
148
+ try:
149
+ for zp in zip_paths:
150
+ full_path = os.path.join(spec_dir, zp)
151
+ if os.path.exists(full_path):
152
+ zip_archives.append(zipfile.ZipFile(full_path, 'r'))
153
+ samples = sampleTestCases(examples, numOfSampleTC, spec_dir,
154
+ zip_archives)
155
+ finally:
156
+ for zf in zip_archives:
157
+ zf.close()
158
+
125
159
  assignment = re.sub('EXMPLS [0-9]+', samples, assignment)
126
160
  if compile_command:
127
161
  assignment = assignment.replace('COMPILE', compile_command)
@@ -25,6 +25,28 @@ def get_codeval_folder(course):
25
25
  exit(2)
26
26
 
27
27
 
28
+ def get_assignment_subfolder(course, codeval_folder, assignment_name):
29
+ """Get or create a subfolder under CodEval named after the assignment."""
30
+ subfolder_path = f"{codeval_folder.full_name}/{assignment_name}"
31
+ canvas_folders = course.get_folders()
32
+ for folder in canvas_folders:
33
+ if folder.full_name == subfolder_path:
34
+ return folder
35
+ # Create the subfolder if it doesn't exist
36
+ debug(f'Creating subfolder: {subfolder_path}')
37
+ return course.create_folder(assignment_name, parent_folder_id=codeval_folder.id)
38
+
39
+
40
+ def extract_assignment_name(specname):
41
+ """Extract the assignment name from the CRT_HW START line of a codeval spec file."""
42
+ with open(specname, 'r') as f:
43
+ for line in f:
44
+ if 'CRT_HW START' in line:
45
+ return line[13:].strip()
46
+ error(f"could not find CRT_HW START in {specname}")
47
+ exit(2)
48
+
49
+
28
50
  def extract_file_macros(specname):
29
51
  """Extract all FILE[filename] macros from the markdown portion of a codeval spec file."""
30
52
  file_macros = []
@@ -119,7 +141,13 @@ def create_assignment(dryrun, verbose, course_name, group_name, specname, extra)
119
141
  if has_github:
120
142
  debug(f'Found GITHUB entry for course, will use online_text_entry submission type')
121
143
 
122
- canvas_folder = get_codeval_folder(course)
144
+ codeval_folder = get_codeval_folder(course)
145
+ assign_name_early = extract_assignment_name(specname)
146
+ if get_config().dry_run:
147
+ canvas_folder = codeval_folder
148
+ debug(f'Would use subfolder: CodEval/{assign_name_early}')
149
+ else:
150
+ canvas_folder = get_assignment_subfolder(course, codeval_folder, assign_name_early)
123
151
  if extra:
124
152
  upload_assignment_files(canvas_folder, extra)
125
153
  # find zipfiles in spec
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: assignment-codeval
3
- Version: 0.0.26
3
+ Version: 0.0.28
4
4
  Summary: CodEval for evaluating programming assignments
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -1,11 +1,11 @@
1
1
  assignment_codeval/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  assignment_codeval/ai_benchmark.py,sha256=ZGWWrBeUcaArkuQqS9wY42gxP8g7J2nivJMedYq9RFs,18045
3
3
  assignment_codeval/canvas_utils.py,sha256=MNtGXc93tHlqudEZsb_6r-5QzV9tSqf3AVxIVGEmk-U,5989
4
- assignment_codeval/check_grading.py,sha256=VFbkAG_PrBi6iFeyqHs7mLKPi0Xjccg6WtLwY9xrRIk,5880
4
+ assignment_codeval/check_grading.py,sha256=rnNdp8T_XWckDfF1zUi3r70BMe9CPNTD-RfjfarI-CM,5889
5
5
  assignment_codeval/cli.py,sha256=Vl27zNI7kI0QEZoXTIE2aTrraEJWj9vgJiyVWou3vgU,1357
6
6
  assignment_codeval/commons.py,sha256=rr09qHacHoLmmU8S9sBss4_utb0DH8-IyL9Dsj0ycE0,1412
7
- assignment_codeval/convertMD2Html.py,sha256=4yu41U4Up1oGI5vDZGelmuogwFmEZrRS55M4ZHbRfaE,6243
8
- assignment_codeval/create_assignment.py,sha256=oZ-0LadVb6R-rXVg0Lz5itziaalIvFoxd71cIxgMfow,10815
7
+ assignment_codeval/convertMD2Html.py,sha256=cCfTWwxH-0SKZ7Br-Qn54OabPuEAhHpx3q4Aeqp_NAo,7682
8
+ assignment_codeval/create_assignment.py,sha256=duGI8wZRpeEnmYPAAth_QXcFHWd185zkjkSJsaeH-GY,11999
9
9
  assignment_codeval/evaluate.py,sha256=er21lA-eohP1BfHPYPWRw9m0a_IOeljMNtcidOYacJY,36253
10
10
  assignment_codeval/export_tests.py,sha256=IDAlGAp3zk-K5AFwLr85v4w9_WcYr6HXVF0joi4eYTg,5467
11
11
  assignment_codeval/file_utils.py,sha256=RDgAgmyIOLKvRlxbAr-zILz2A24zSr-r3--p-dxl4G8,2132
@@ -14,8 +14,8 @@ assignment_codeval/install_assignment.py,sha256=HsXzTex4G-U3t4tb-HyQ2AobBDBPcKeR
14
14
  assignment_codeval/recent_comments.py,sha256=e8UQL2_9dsPlf-NYFrGSaM6h6XYnTf_MW2jWhtEsb38,9097
15
15
  assignment_codeval/submissions.py,sha256=YbwKynZwWsmcyytwRi3Kuxq3WN-V-vvshO9JrNJoxAs,28333
16
16
  assignment_codeval/test_template.html,sha256=lgWsin5sYE_Pwjp3xqa7_UT-yZ4dWrVqAvNlSBBiNMI,2584
17
- assignment_codeval-0.0.26.dist-info/METADATA,sha256=CvKtHeb1kR3x4Sz0ojGIKui1v_Q1ejiColTIShfMOfg,15589
18
- assignment_codeval-0.0.26.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
19
- assignment_codeval-0.0.26.dist-info/entry_points.txt,sha256=Pk0eAhsXBpCsgkv6HYLSHTRf5x_zUf-Lg8KK9KsK2B8,66
20
- assignment_codeval-0.0.26.dist-info/top_level.txt,sha256=a_P8W2IWjAELxKlTV2t4rLwWVoTxElxUMvWgWjR_1n4,19
21
- assignment_codeval-0.0.26.dist-info/RECORD,,
17
+ assignment_codeval-0.0.28.dist-info/METADATA,sha256=eqDDrmcpY-ibWCD5fI7fgEG44-IfPp-PxpQoTHnYKeg,15589
18
+ assignment_codeval-0.0.28.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
19
+ assignment_codeval-0.0.28.dist-info/entry_points.txt,sha256=Pk0eAhsXBpCsgkv6HYLSHTRf5x_zUf-Lg8KK9KsK2B8,66
20
+ assignment_codeval-0.0.28.dist-info/top_level.txt,sha256=a_P8W2IWjAELxKlTV2t4rLwWVoTxElxUMvWgWjR_1n4,19
21
+ assignment_codeval-0.0.28.dist-info/RECORD,,