PyKubeGrader 0.2.20__py3-none-any.whl → 0.2.22__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- {PyKubeGrader-0.2.20.dist-info → PyKubeGrader-0.2.22.dist-info}/METADATA +1 -1
- {PyKubeGrader-0.2.20.dist-info → PyKubeGrader-0.2.22.dist-info}/RECORD +9 -9
- pykubegrader/build/api_notebook_builder.py +6 -0
- pykubegrader/build/build_folder.py +70 -14
- pykubegrader/tokens/validate_token.py +13 -2
- {PyKubeGrader-0.2.20.dist-info → PyKubeGrader-0.2.22.dist-info}/LICENSE.txt +0 -0
- {PyKubeGrader-0.2.20.dist-info → PyKubeGrader-0.2.22.dist-info}/WHEEL +0 -0
- {PyKubeGrader-0.2.20.dist-info → PyKubeGrader-0.2.22.dist-info}/entry_points.txt +0 -0
- {PyKubeGrader-0.2.20.dist-info → PyKubeGrader-0.2.22.dist-info}/top_level.txt +0 -0
@@ -4,8 +4,8 @@ pykubegrader/telemetry.py,sha256=h8PPrXWGFgPWCcrChJo2woqd_XIPMFfYcxgLJ0CWpH8,536
|
|
4
4
|
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
|
-
pykubegrader/build/api_notebook_builder.py,sha256=
|
8
|
-
pykubegrader/build/build_folder.py,sha256=
|
7
|
+
pykubegrader/build/api_notebook_builder.py,sha256=IzzU_jh6SYSA2wtjtlhxa4t9WM8-JqWnWsV8e3UPwdo,20305
|
8
|
+
pykubegrader/build/build_folder.py,sha256=y5hrxkZgqVr0MRXL3AkihaJQmtm70F4umyVT8--uYTk,81820
|
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
|
@@ -14,7 +14,7 @@ pykubegrader/log_parser/parse.ipynb,sha256=H1CUuqiUSE-tiZV1IS7VG6HAEvoopGd6i_5QM
|
|
14
14
|
pykubegrader/log_parser/parse.py,sha256=YCs_OCnoxQKsL55MjTZWXBBBsehJL8PIB9ANnC-aE44,7379
|
15
15
|
pykubegrader/submit/submit_assignment.py,sha256=p-v31479342q0AO3lJrd8Fwk7iJQUz183OeGeiNcXOY,3405
|
16
16
|
pykubegrader/tokens/tokens.py,sha256=DorNwdrA5N5apB3LQjVGa2ABN5C1upkgglecaLHobr0,1260
|
17
|
-
pykubegrader/tokens/validate_token.py,sha256=
|
17
|
+
pykubegrader/tokens/validate_token.py,sha256=q5aJ0hUsFTDgrSfAszPS5RpxwTKODAguFqkZkKjkN3k,4058
|
18
18
|
pykubegrader/widgets/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
19
19
|
pykubegrader/widgets/multiple_choice.py,sha256=NjD3-uXSnibpUQ0mO3hRp_O-rynFyl0Dz6IXE4tnCRI,2078
|
20
20
|
pykubegrader/widgets/reading_question.py,sha256=y30_swHwzH8LrT8deWTnxctAAmR8BSxTlXAqMgUrAT4,3031
|
@@ -27,9 +27,9 @@ pykubegrader/widgets_base/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-
|
|
27
27
|
pykubegrader/widgets_base/multi_select.py,sha256=Cl0IN21wXLZuFu-zC65aS9tD4jMfzCRJ2DPjHao5_Ak,4044
|
28
28
|
pykubegrader/widgets_base/reading.py,sha256=_vjUPynqmJe_R4vf-7hVhGnQR726S9GL6qT8bflBXBM,5383
|
29
29
|
pykubegrader/widgets_base/select.py,sha256=Fw3uFNOIWo1a3CvlzSx23bvi6bSmA3TqutuRbhD4Dp8,2525
|
30
|
-
PyKubeGrader-0.2.
|
31
|
-
PyKubeGrader-0.2.
|
32
|
-
PyKubeGrader-0.2.
|
33
|
-
PyKubeGrader-0.2.
|
34
|
-
PyKubeGrader-0.2.
|
35
|
-
PyKubeGrader-0.2.
|
30
|
+
PyKubeGrader-0.2.22.dist-info/LICENSE.txt,sha256=YTp-Ewc8Kems8PJEE27KnBPFnZSxoWvSg7nnknzPyYw,1546
|
31
|
+
PyKubeGrader-0.2.22.dist-info/METADATA,sha256=dPgcV3VFD4CAMAFJ2kQR8dw3ZY9wu1qls8k5gstiKJw,2779
|
32
|
+
PyKubeGrader-0.2.22.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
33
|
+
PyKubeGrader-0.2.22.dist-info/entry_points.txt,sha256=UPMdTT46fQwTYJWtrUwIWIbXbwyOPfNQgBFRa0frWzw,138
|
34
|
+
PyKubeGrader-0.2.22.dist-info/top_level.txt,sha256=e550Klfze6higFxER1V62fnGOcIgiKRbsrl9CC4UdtQ,13
|
35
|
+
PyKubeGrader-0.2.22.dist-info/RECORD,,
|
@@ -14,6 +14,7 @@ class FastAPINotebookBuilder:
|
|
14
14
|
notebook_path: str
|
15
15
|
temp_notebook: Optional[str] = None
|
16
16
|
assignment_tag: Optional[str] = ""
|
17
|
+
require_key: Optional[bool] = False
|
17
18
|
|
18
19
|
def __post_init__(self):
|
19
20
|
self.root_path, self.filename = FastAPINotebookBuilder.get_filename_and_root(
|
@@ -119,6 +120,11 @@ class FastAPINotebookBuilder:
|
|
119
120
|
f"os.environ['TOTAL_POINTS_FREE_RESPONSE'] = str({self.total_points})\n"
|
120
121
|
)
|
121
122
|
|
123
|
+
if self.require_key:
|
124
|
+
first_cell_header.append(
|
125
|
+
"from pykubegrader.tokens.validate_token import validate_token\nvalidate_token()\n"
|
126
|
+
)
|
127
|
+
|
122
128
|
short_filename = self.filename.split(".")[0].replace("_temp", "")
|
123
129
|
first_cell_header.extend(
|
124
130
|
[
|
@@ -28,6 +28,19 @@ from .api_notebook_builder import FastAPINotebookBuilder
|
|
28
28
|
from typing import Optional
|
29
29
|
|
30
30
|
|
31
|
+
import os
|
32
|
+
|
33
|
+
os.environ["JUPYTERHUB_USER"] = "jca92"
|
34
|
+
os.environ["TOKEN"] = "token"
|
35
|
+
os.environ["DB_URL"] = "https://engr-131-api.eastus.cloudapp.azure.com/"
|
36
|
+
os.environ["keys_student"] = "capture"
|
37
|
+
os.environ["user_name_student"] = "student"
|
38
|
+
|
39
|
+
from pykubegrader.tokens.tokens import add_token
|
40
|
+
|
41
|
+
add_token("token", duration=20)
|
42
|
+
|
43
|
+
|
31
44
|
@dataclass
|
32
45
|
class NotebookProcessor:
|
33
46
|
"""
|
@@ -46,6 +59,7 @@ class NotebookProcessor:
|
|
46
59
|
solutions_folder: str = field(init=False)
|
47
60
|
verbose: bool = False
|
48
61
|
log: bool = True
|
62
|
+
require_key: bool = False
|
49
63
|
|
50
64
|
def __post_init__(self):
|
51
65
|
"""
|
@@ -559,11 +573,22 @@ class NotebookProcessor:
|
|
559
573
|
"you should see your score."
|
560
574
|
)
|
561
575
|
|
562
|
-
|
563
|
-
|
564
|
-
"from pykubegrader.submit.submit_assignment import
|
565
|
-
|
566
|
-
|
576
|
+
if self.require_key:
|
577
|
+
# Add an additional line for validate_token()
|
578
|
+
validate_token_line = "from pykubegrader.submit.submit_assignment import validate_token\nvalidate_token()\n"
|
579
|
+
|
580
|
+
# Define the Code cell
|
581
|
+
code_cell = nbformat.v4.new_code_cell(
|
582
|
+
f"{validate_token_line}\n\n" # Add the validate_token() line
|
583
|
+
"from pykubegrader.submit.submit_assignment import submit_assignment\n\n"
|
584
|
+
f'submit_assignment("week{self.week_num}-{self.assignment_type}", "{os.path.basename(notebook_path).replace(".ipynb", "")}")'
|
585
|
+
)
|
586
|
+
else:
|
587
|
+
# Define the Code cell without validate_token()
|
588
|
+
code_cell = nbformat.v4.new_code_cell(
|
589
|
+
"from pykubegrader.submit.submit_assignment import submit_assignment\n\n"
|
590
|
+
f'submit_assignment("week{self.week_num}-{self.assignment_type}", "{os.path.basename(notebook_path).replace(".ipynb", "")}")'
|
591
|
+
)
|
567
592
|
|
568
593
|
# Make the code cell non-editable and non-deletable
|
569
594
|
code_cell.metadata = {"editable": False, "deletable": False}
|
@@ -607,7 +632,9 @@ class NotebookProcessor:
|
|
607
632
|
shutil.copy("./keys/.server_public_key.bin", server_public_key)
|
608
633
|
|
609
634
|
out = FastAPINotebookBuilder(
|
610
|
-
notebook_path=temp_notebook_path,
|
635
|
+
notebook_path=temp_notebook_path,
|
636
|
+
assignment_tag=self.assignment_tag,
|
637
|
+
require_key=self.require_key,
|
611
638
|
)
|
612
639
|
|
613
640
|
debug_notebook = os.path.join(
|
@@ -632,7 +659,10 @@ class NotebookProcessor:
|
|
632
659
|
)
|
633
660
|
|
634
661
|
NotebookProcessor.add_initialization_code(
|
635
|
-
student_notebook,
|
662
|
+
student_notebook,
|
663
|
+
self.week,
|
664
|
+
self.assignment_type,
|
665
|
+
require_key=self.require_key,
|
636
666
|
)
|
637
667
|
|
638
668
|
NotebookProcessor.replace_temp_in_notebook(
|
@@ -659,7 +689,10 @@ class NotebookProcessor:
|
|
659
689
|
return student_notebook, out.total_points
|
660
690
|
else:
|
661
691
|
NotebookProcessor.add_initialization_code(
|
662
|
-
temp_notebook_path,
|
692
|
+
temp_notebook_path,
|
693
|
+
self.week,
|
694
|
+
self.assignment_type,
|
695
|
+
require_key=self.require_key,
|
663
696
|
)
|
664
697
|
NotebookProcessor.replace_temp_no_otter(
|
665
698
|
temp_notebook_path, temp_notebook_path
|
@@ -691,11 +724,19 @@ class NotebookProcessor:
|
|
691
724
|
nbformat.write(notebook, f)
|
692
725
|
|
693
726
|
@staticmethod
|
694
|
-
def add_initialization_code(
|
727
|
+
def add_initialization_code(
|
728
|
+
notebook_path, week, assignment_type, require_key=False
|
729
|
+
):
|
695
730
|
# finds the first code cell
|
696
731
|
index, cell = find_first_code_cell(notebook_path)
|
697
732
|
cell = cell["source"]
|
698
|
-
import_text = "
|
733
|
+
import_text = "# You must make sure to run all cells in sequence using shift + enter or you might encounter errors\n"
|
734
|
+
import_text += "from pykubegrader.initialize import initialize_assignment\n"
|
735
|
+
if require_key:
|
736
|
+
import_text += (
|
737
|
+
"from pykubegrader.token.validate_token import validate_token\n"
|
738
|
+
)
|
739
|
+
import_text += "validate_token('type the key provided by your TA here')\n"
|
699
740
|
import_text += f'\nresponses = initialize_assignment("{os.path.splitext(os.path.basename(notebook_path))[0]}", "{week}", "{assignment_type}" )\n'
|
700
741
|
cell = f"{import_text}\n" + cell
|
701
742
|
replace_cell_source(notebook_path, index, cell)
|
@@ -1740,7 +1781,9 @@ def generate_mcq_file(data_dict, output_file="mc_questions.py"):
|
|
1740
1781
|
)
|
1741
1782
|
f.write(" def __init__(self):\n")
|
1742
1783
|
f.write(" super().__init__(\n")
|
1743
|
-
f.write(
|
1784
|
+
f.write(
|
1785
|
+
f' title=f"Question{q_value['question number']}: {q_value['title']}",\n'
|
1786
|
+
)
|
1744
1787
|
f.write(" style=MCQ,\n")
|
1745
1788
|
f.write(
|
1746
1789
|
f" question_number={q_value['question number']},\n"
|
@@ -1811,7 +1854,9 @@ def generate_select_many_file(data_dict, output_file="select_many_questions.py")
|
|
1811
1854
|
)
|
1812
1855
|
f.write(" def __init__(self):\n")
|
1813
1856
|
f.write(" super().__init__(\n")
|
1814
|
-
f.write(
|
1857
|
+
f.write(
|
1858
|
+
f' title=f"Question{q_value['question number']}: {q_value['title']}",\n'
|
1859
|
+
)
|
1815
1860
|
f.write(" style=MultiSelect,\n")
|
1816
1861
|
f.write(
|
1817
1862
|
f" question_number={q_value['question number']},\n"
|
@@ -1888,7 +1933,9 @@ def generate_tf_file(data_dict, output_file="tf_questions.py"):
|
|
1888
1933
|
)
|
1889
1934
|
f.write(" def __init__(self):\n")
|
1890
1935
|
f.write(" super().__init__(\n")
|
1891
|
-
f.write(
|
1936
|
+
f.write(
|
1937
|
+
f' title=f"Question{q_value['question number']}: {q_value['title']}",\n'
|
1938
|
+
)
|
1892
1939
|
f.write(" style=TFStyle,\n")
|
1893
1940
|
f.write(
|
1894
1941
|
f" question_number={q_value['question number']},\n"
|
@@ -2060,9 +2107,18 @@ def main():
|
|
2060
2107
|
default="Reading-Week-X",
|
2061
2108
|
)
|
2062
2109
|
|
2110
|
+
parser.add_argument(
|
2111
|
+
"--require-key",
|
2112
|
+
type=bool,
|
2113
|
+
help="Require a key to be generated for the assignment",
|
2114
|
+
default=False,
|
2115
|
+
)
|
2116
|
+
|
2063
2117
|
args = parser.parse_args()
|
2064
2118
|
processor = NotebookProcessor(
|
2065
|
-
root_folder=args.root_folder,
|
2119
|
+
root_folder=args.root_folder,
|
2120
|
+
assignment_tag=args.assignment_tag,
|
2121
|
+
require_key=args.require_key,
|
2066
2122
|
)
|
2067
2123
|
processor.process_notebooks()
|
2068
2124
|
|
@@ -39,7 +39,7 @@ def get_credentials():
|
|
39
39
|
return {"username": username, "password": password}
|
40
40
|
|
41
41
|
|
42
|
-
async def async_validate_token(token: str) -> None:
|
42
|
+
async def async_validate_token(token: str = None) -> None:
|
43
43
|
"""
|
44
44
|
Asynchronously validate a token by making a GET request to the validation endpoint.
|
45
45
|
|
@@ -52,6 +52,16 @@ async def async_validate_token(token: str) -> None:
|
|
52
52
|
Returns:
|
53
53
|
None: If the token is valid, the function will pass silently.
|
54
54
|
"""
|
55
|
+
|
56
|
+
if token is not None:
|
57
|
+
os.environ["TOKEN"] = token
|
58
|
+
|
59
|
+
if token is None:
|
60
|
+
token = os.getenv("TOKEN", None)
|
61
|
+
|
62
|
+
if token is None:
|
63
|
+
raise TokenValidationError("No token provided")
|
64
|
+
|
55
65
|
# Fetch the endpoint URL
|
56
66
|
base_url = os.getenv("DB_URL")
|
57
67
|
if not base_url:
|
@@ -93,7 +103,7 @@ async def async_validate_token(token: str) -> None:
|
|
93
103
|
raise TokenValidationError(f"An unexpected error occurred: {e}")
|
94
104
|
|
95
105
|
|
96
|
-
def validate_token(token: str) -> None:
|
106
|
+
def validate_token(token: str = None) -> None:
|
97
107
|
"""
|
98
108
|
Synchronous wrapper for the `async_validate_token` function.
|
99
109
|
|
@@ -106,6 +116,7 @@ def validate_token(token: str) -> None:
|
|
106
116
|
Returns:
|
107
117
|
None: If the token is valid, the function will pass silently.
|
108
118
|
"""
|
119
|
+
|
109
120
|
# Get the current event loop or create one
|
110
121
|
try:
|
111
122
|
loop = asyncio.get_event_loop()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|