PyKubeGrader 0.2.10__py3-none-any.whl → 0.2.12__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyKubeGrader
3
- Version: 0.2.10
3
+ Version: 0.2.12
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: jagar2
@@ -5,14 +5,14 @@ pykubegrader/utils.py,sha256=T3GYnLnTL9VXjTZNPr00sUgMgobQYsNTGwynMyXdvHk,696
5
5
  pykubegrader/validate.py,sha256=2KLSB3wfFZbBh1NGgmrOV073paKAgrQz4AgA6LmCIj4,11076
6
6
  pykubegrader/build/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
7
  pykubegrader/build/api_notebook_builder.py,sha256=FEaTj1fEsPAes7KNrPuhClEvKzLuOL3wG7Hgr7FQc-o,20083
8
- pykubegrader/build/build_folder.py,sha256=hNHfhCn2rAHUK_i-KbtZYhUbd_bYsAoPRm2vVK9gYi8,76508
8
+ pykubegrader/build/build_folder.py,sha256=Ahec6o48wHYpsLViUWi5qIHTirZQg9PJk3N4ABiZD-w,78871
9
9
  pykubegrader/build/clean_folder.py,sha256=8N0KyL4eXRs0DCw-V_2jR9igtFs_mOFMQufdL6tD-38,1323
10
10
  pykubegrader/graders/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
11
11
  pykubegrader/graders/late_assignments.py,sha256=_2-rA5RqO0BWY9WAQA_mbCxxPKTOiJOl-byD2CYWaE0,1393
12
12
  pykubegrader/log_parser/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
13
13
  pykubegrader/log_parser/parse.ipynb,sha256=H1CUuqiUSE-tiZV1IS7VG6HAEvoopGd6i_5QM5CwoE0,12230
14
14
  pykubegrader/log_parser/parse.py,sha256=YCs_OCnoxQKsL55MjTZWXBBBsehJL8PIB9ANnC-aE44,7379
15
- pykubegrader/submit/submit_assignment.py,sha256=f8mQ96d0EpI5FNhdauGj21ybSZEzBEYsuG25a-Jel-c,3289
15
+ pykubegrader/submit/submit_assignment.py,sha256=p-v31479342q0AO3lJrd8Fwk7iJQUz183OeGeiNcXOY,3405
16
16
  pykubegrader/widgets/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
17
17
  pykubegrader/widgets/multiple_choice.py,sha256=NjD3-uXSnibpUQ0mO3hRp_O-rynFyl0Dz6IXE4tnCRI,2078
18
18
  pykubegrader/widgets/reading_question.py,sha256=y30_swHwzH8LrT8deWTnxctAAmR8BSxTlXAqMgUrAT4,3031
@@ -25,9 +25,9 @@ pykubegrader/widgets_base/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-
25
25
  pykubegrader/widgets_base/multi_select.py,sha256=Cl0IN21wXLZuFu-zC65aS9tD4jMfzCRJ2DPjHao5_Ak,4044
26
26
  pykubegrader/widgets_base/reading.py,sha256=_vjUPynqmJe_R4vf-7hVhGnQR726S9GL6qT8bflBXBM,5383
27
27
  pykubegrader/widgets_base/select.py,sha256=Fw3uFNOIWo1a3CvlzSx23bvi6bSmA3TqutuRbhD4Dp8,2525
28
- PyKubeGrader-0.2.10.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
29
- PyKubeGrader-0.2.10.dist-info/METADATA,sha256=VlXNrYslMa8YjmEQWQ67wCuII-K0uGZXKHeEDcAkSro,2779
30
- PyKubeGrader-0.2.10.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
31
- PyKubeGrader-0.2.10.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
32
- PyKubeGrader-0.2.10.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
33
- PyKubeGrader-0.2.10.dist-info/RECORD,,
28
+ PyKubeGrader-0.2.12.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
29
+ PyKubeGrader-0.2.12.dist-info/METADATA,sha256=DH3IMdYk9nFa_JwDfNdMSZRbr_vZy5jx7OvX8Rjy_FY,2779
30
+ PyKubeGrader-0.2.12.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
31
+ PyKubeGrader-0.2.12.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
32
+ PyKubeGrader-0.2.12.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
33
+ PyKubeGrader-0.2.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.7.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -215,6 +215,68 @@ class NotebookProcessor:
215
215
  "due_date": due_date,
216
216
  "max_score": int(self.assignment_total_points),
217
217
  }
218
+
219
+ def build_payload_notebook(self, yaml_content, notebook_title, total_points):
220
+ # Parse the YAML content
221
+ with open(yaml_content, "r") as file:
222
+ data = yaml.safe_load(file)
223
+
224
+ # Extract assignment details
225
+ assignment = data.get("assignment", {})
226
+
227
+ week_num = self.week_num
228
+ assignment_type = self.assignment_type
229
+ due_date_str = assignment.get("due_date")
230
+
231
+ # Convert due_date to a datetime object if available
232
+ due_date = None
233
+ if due_date_str:
234
+ try:
235
+ due_date = parser.parse(due_date_str) # Automatically handles timezones
236
+ except ValueError as e:
237
+ print(f"Error parsing due_date: {e}")
238
+
239
+ return {
240
+ "title": notebook_title,
241
+ "week_number": week_num,
242
+ "assignment_type": assignment_type,
243
+ "due_date": due_date,
244
+ "max_score": total_points,
245
+ }
246
+
247
+
248
+ def add_notebook(self, notebook_title, total_points):
249
+ """
250
+ Sends a POST request to add a notebook.
251
+ """
252
+ # Define the URL
253
+ url = "https://engr-131-api.eastus.cloudapp.azure.com/notebook"
254
+
255
+ # Build the payload
256
+ payload = self.build_payload_notebook(yaml_content=f"{self.root_folder}/assignment_config.yaml",
257
+ notebook_title=notebook_title,
258
+ total_points=total_points)
259
+
260
+ # Define HTTP Basic Authentication
261
+ auth = (user(), password())
262
+
263
+ # Define headers
264
+ headers = {"Content-Type": "application/json"}
265
+
266
+ # Serialize the payload with the custom JSON encoder
267
+ serialized_payload = json.dumps(payload, default=self.json_serial)
268
+
269
+ # Send the POST request
270
+ response = requests.post(
271
+ url, data=serialized_payload, headers=headers, auth=auth
272
+ )
273
+
274
+ # Print the response
275
+ print(f"Status Code: {response.status_code}")
276
+ try:
277
+ print(f"Response: {response.json()}")
278
+ except ValueError:
279
+ print(f"Response: {response.text}")
218
280
 
219
281
  def add_assignment(self):
220
282
  """
@@ -436,6 +498,9 @@ class NotebookProcessor:
436
498
  + self.tf_total_points
437
499
  + self.otter_total_points
438
500
  )
501
+
502
+ # creates the assignment record in the database
503
+ self.add_notebook(notebook_name, total_points)
439
504
 
440
505
  self.assignment_total_points += total_points
441
506
 
@@ -466,7 +531,7 @@ class NotebookProcessor:
466
531
  # Define the Code cell
467
532
  code_cell = nbformat.v4.new_code_cell(
468
533
  "from pykubegrader.submit.submit_assignment import submit_assignment\n\n"
469
- f'submit_assignment("week{self.week_num}-{self.assignment_type}")'
534
+ f'submit_assignment("week{self.week_num}-{self.assignment_type}", "{os.path.basename(notebook_path).replace(".ipynb", "")}")'
470
535
  )
471
536
 
472
537
  # Make the code cell non-editable and non-deletable
@@ -22,7 +22,7 @@ def get_credentials():
22
22
 
23
23
 
24
24
  async def call_score_assignment(
25
- assignment_title: str, file_path: str = ".output_reduced.log"
25
+ assignment_title: str, notebook_title: str, file_path: str = ".output_reduced.log"
26
26
  ) -> dict:
27
27
  """
28
28
  Submit an assignment to the scoring endpoint.
@@ -38,15 +38,17 @@ async def call_score_assignment(
38
38
  base_url = os.getenv("DB_URL")
39
39
  if not base_url:
40
40
  raise ValueError("Environment variable 'DB_URL' is not set.")
41
- url = f"{base_url}score-assignment?assignment_title={assignment_title}"
41
+ url = f"{base_url}score-assignment?assignment_title={assignment_title}&notebook_title={notebook_title}"
42
42
 
43
43
  # Get credentials
44
44
  credentials = get_credentials()
45
45
  username = credentials["username"]
46
- password = credentials["password"]
46
+ password = credentials["password"]
47
47
 
48
48
  # Encode credentials for Basic Authentication
49
- auth_header = f"Basic {base64.b64encode(f'{username}:{password}'.encode()).decode()}"
49
+ auth_header = (
50
+ f"Basic {base64.b64encode(f'{username}:{password}'.encode()).decode()}"
51
+ )
50
52
 
51
53
  # Send the POST request
52
54
  async with httpx.AsyncClient() as client:
@@ -71,7 +73,9 @@ async def call_score_assignment(
71
73
 
72
74
 
73
75
  def submit_assignment(
74
- assignment_title: str, file_path: str = ".output_reduced.log"
76
+ assignment_title: str,
77
+ notebook_title: str,
78
+ file_path: str = ".output_reduced.log",
75
79
  ) -> None:
76
80
  """
77
81
  Synchronous wrapper for the `call_score_assignment` function.
@@ -89,7 +93,7 @@ def submit_assignment(
89
93
 
90
94
  # Run the async function in the event loop
91
95
  response = loop.run_until_complete(
92
- call_score_assignment(assignment_title, file_path)
96
+ call_score_assignment(assignment_title, notebook_title, file_path)
93
97
  )
94
98
  print("Server Response:", response.get("message", "No message in response"))
95
99