PyKubeGrader 0.2.6__py3-none-any.whl → 0.2.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyKubeGrader
3
- Version: 0.2.6
3
+ Version: 0.2.8
4
4
  Summary: Add a short description here!
5
5
  Home-page: https://github.com/pyscaffold/pyscaffold/
6
6
  Author: jagar2
@@ -28,6 +28,8 @@ Requires-Dist: types-python-dateutil
28
28
  Requires-Dist: types-pyyaml
29
29
  Requires-Dist: types-requests
30
30
  Requires-Dist: types-setuptools
31
+ Requires-Dist: httpx
32
+ Requires-Dist: nest_asyncio
31
33
  Provides-Extra: testing
32
34
  Requires-Dist: setuptools; extra == "testing"
33
35
  Requires-Dist: pytest; extra == "testing"
@@ -12,6 +12,7 @@ pykubegrader/graders/late_assignments.py,sha256=_2-rA5RqO0BWY9WAQA_mbCxxPKTOiJOl
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=UHRwogSz7TpMUZSAyEbQIQut2WcC08ma2JEIEWaSUdM,2702
15
16
  pykubegrader/widgets/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
16
17
  pykubegrader/widgets/multiple_choice.py,sha256=NjD3-uXSnibpUQ0mO3hRp_O-rynFyl0Dz6IXE4tnCRI,2078
17
18
  pykubegrader/widgets/reading_question.py,sha256=y30_swHwzH8LrT8deWTnxctAAmR8BSxTlXAqMgUrAT4,3031
@@ -24,9 +25,9 @@ pykubegrader/widgets_base/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-
24
25
  pykubegrader/widgets_base/multi_select.py,sha256=Cl0IN21wXLZuFu-zC65aS9tD4jMfzCRJ2DPjHao5_Ak,4044
25
26
  pykubegrader/widgets_base/reading.py,sha256=_vjUPynqmJe_R4vf-7hVhGnQR726S9GL6qT8bflBXBM,5383
26
27
  pykubegrader/widgets_base/select.py,sha256=Fw3uFNOIWo1a3CvlzSx23bvi6bSmA3TqutuRbhD4Dp8,2525
27
- PyKubeGrader-0.2.6.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
28
- PyKubeGrader-0.2.6.dist-info/METADATA,sha256=_XXXPzB7wxkhmlAFJDZwa5s2BCzFQ3-kzU4tncrn2IA,2729
29
- PyKubeGrader-0.2.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
30
- PyKubeGrader-0.2.6.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
31
- PyKubeGrader-0.2.6.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
32
- PyKubeGrader-0.2.6.dist-info/RECORD,,
28
+ PyKubeGrader-0.2.8.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
29
+ PyKubeGrader-0.2.8.dist-info/METADATA,sha256=KDlsQ-0emWgalUlulH1-hifPtv1M7kzHulEJlcLDmtM,2778
30
+ PyKubeGrader-0.2.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
31
+ PyKubeGrader-0.2.8.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
32
+ PyKubeGrader-0.2.8.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
33
+ PyKubeGrader-0.2.8.dist-info/RECORD,,
@@ -0,0 +1,84 @@
1
+ import os
2
+ import httpx
3
+ import asyncio
4
+
5
+ import nest_asyncio
6
+
7
+ nest_asyncio.apply()
8
+
9
+
10
+ def get_credentials():
11
+ """
12
+ Fetch the username and password from environment variables.
13
+ """
14
+ username = os.getenv("user_name_student")
15
+ password = os.getenv("keys_student")
16
+ if not username or not password:
17
+ raise ValueError(
18
+ "Environment variables 'user_name_student' or 'keys_student' are not set."
19
+ )
20
+ return {"username": username, "password": password}
21
+
22
+
23
+ async def call_score_assignment(
24
+ assignment_title: str, file_path: str = ".output_reduced.log"
25
+ ) -> dict:
26
+ """
27
+ Submit an assignment to the scoring endpoint.
28
+
29
+ Args:
30
+ assignment_title (str): Title of the assignment.
31
+ file_path (str): Path to the log file to upload.
32
+
33
+ Returns:
34
+ dict: JSON response from the server.
35
+ """
36
+ # Fetch the endpoint URL from environment variables
37
+ base_url = os.getenv("DB_URL")
38
+ if not base_url:
39
+ raise ValueError("Environment variable 'DB_URL' is not set.")
40
+ url = f"{base_url}score-assignment"
41
+
42
+ # Get credentials
43
+ credentials = get_credentials()
44
+
45
+ # Send the POST request
46
+ async with httpx.AsyncClient() as client:
47
+ try:
48
+ with open(file_path, "rb") as file:
49
+ response = await client.post(
50
+ url,
51
+ data={"cred": credentials, "assignment_title": assignment_title},
52
+ files={"log_file": file},
53
+ )
54
+
55
+ # Handle the response
56
+ response.raise_for_status() # Raise an exception for HTTP errors
57
+ response_data = response.json()
58
+ return response_data
59
+ except FileNotFoundError:
60
+ raise FileNotFoundError(f"The file {file_path} does not exist.")
61
+ except httpx.RequestError as e:
62
+ raise RuntimeError(f"An error occurred while requesting {url}: {e}")
63
+ except Exception as e:
64
+ raise RuntimeError(f"An unexpected error occurred: {e}")
65
+
66
+
67
+ # Importable function
68
+ def submit_assignment(
69
+ assignment_title: str, file_path: str = ".output_reduced.log"
70
+ ) -> None:
71
+ """
72
+ Synchronous wrapper for the `call_score_assignment` function.
73
+
74
+ Args:
75
+ assignment_title (str): Title of the assignment.
76
+ file_path (str): Path to the log file to upload.
77
+ """
78
+ response = asyncio.run(call_score_assignment(assignment_title, file_path))
79
+ print("Server Response:", response.get("message", "No message in response"))
80
+
81
+
82
+ # Example usage (remove this section if only the function needs to be importable):
83
+ if __name__ == "__main__":
84
+ submit_assignment("Week 1 Assignment", "path/to/your/log_file.txt")