Skip to content

Commit 968f1cd

Browse files
committed
Fix all black errors
1 parent a739d75 commit 968f1cd

File tree

13 files changed

+128
-60
lines changed

13 files changed

+128
-60
lines changed

bases/rsptx/admin_server_api/routers/instructor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ async def post_create_course_page(
12561256
# if invoice is true then we need to create an invoice for the course
12571257
if invoice == "true":
12581258
res = await create_invoice_request(
1259-
user.username, projectname, 0.0, user.email
1259+
user.username, projectname, 0.0, user.email
12601260
)
12611261
# Copy attributes from base course
12621262
bc = await fetch_course(coursetype)

bases/rsptx/assignment_server_api/routers/assignment_summary.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ def create_assignment_summary(assignment_id, course, dburl):
141141
]
142142
try:
143143
merged.iloc[0, 3:] = merged.iloc[0, 3:].apply(
144-
lambda x: "{:.2f}".format(float(x.split("(")[0]))
145-
if type(x) is str and "(" in x
146-
else "{:.2f}".format(float(x))
144+
lambda x: (
145+
"{:.2f}".format(float(x.split("(")[0]))
146+
if type(x) is str and "(" in x
147+
else "{:.2f}".format(float(x))
148+
)
147149
)
148150
except Exception as e:
149151
print(

bases/rsptx/assignment_server_api/routers/student.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,19 @@ def sort_key(assignment):
110110
deadline = assignment.duedate
111111
if timezoneoffset:
112112
deadline = deadline + datetime.timedelta(hours=float(timezoneoffset))
113-
return (deadline < canonical_utcnow(), abs((deadline - canonical_utcnow()).total_seconds()))
113+
return (
114+
deadline < canonical_utcnow(),
115+
abs((deadline - canonical_utcnow()).total_seconds()),
116+
)
114117
else:
115-
return (assignment.duedate < canonical_utcnow(), abs((assignment.duedate - canonical_utcnow()).total_seconds()))
118+
return (
119+
assignment.duedate < canonical_utcnow(),
120+
abs((assignment.duedate - canonical_utcnow()).total_seconds()),
121+
)
116122

117123
# Sort assignments: upcoming assignments first (closest to current date), past due assignments last
118124
now = canonical_utcnow()
119-
assignments.sort(
120-
key=sort_key
121-
)
125+
assignments.sort(key=sort_key)
122126
stats_list = await fetch_all_assignment_stats(course.course_name, user.id)
123127
stats = {}
124128
for s in stats_list:

bases/rsptx/book_server_api/routers/course.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ def sort_key(assignment):
116116
)
117117

118118
now = canonical_utcnow()
119-
assignments.sort(
120-
key=sort_key
121-
)
119+
assignments.sort(key=sort_key)
122120

123121
stats_list = await fetch_all_assignment_stats(course_name, user.id)
124122
stats = {}

bases/rsptx/book_server_api/routers/personalized_parsons/end_to_end.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def request_fixed_code_from_openai(
138138
old_fixed_code=old_fixed_code,
139139
)
140140
unittest_result, cleaned_fixed_code = unittest_evaluation(
141-
language,
142-
fixed_code,
143-
default_start_code,
144-
default_test_code,
141+
language,
142+
fixed_code,
143+
default_start_code,
144+
default_test_code,
145145
unittest_code,
146146
)
147147

bases/rsptx/book_server_api/routers/personalized_parsons/evaluate_fixed_code.py

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ class TimeoutError(Exception):
3131
def handler(signum, frame):
3232
raise TimeoutError("Test execution exceeded time limit")
3333

34+
3435
def _runestone_file_id(filename: str, content: str) -> str:
3536
# Exactly: "runestone" + MD5(fileName + fileContent)
3637
md5 = hashlib.md5((filename + content).encode("utf-8")).hexdigest()
3738
return "runestone" + md5
3839

40+
3941
def _b64_text_utf8(s: str) -> str:
4042
return base64.b64encode(s.encode("utf-8")).decode("ascii")
4143

44+
4245
def _jobe_session():
4346
s = rq.Session()
4447
s.headers["Content-type"] = "application/json; charset=utf-8"
@@ -48,7 +51,9 @@ def _jobe_session():
4851
return s
4952

5053

51-
def _ensure_file_on_jobe(sess: rq.Session, base_host: str, file_id: str, content: str) -> None:
54+
def _ensure_file_on_jobe(
55+
sess: rq.Session, base_host: str, file_id: str, content: str
56+
) -> None:
5257
"""
5358
Mirrors JS logic:
5459
- HEAD /jobeCheckFile/<id>
@@ -64,7 +69,9 @@ def _ensure_file_on_jobe(sess: rq.Session, base_host: str, file_id: str, content
6469
return # already there
6570

6671
if r.status_code not in (404, 208):
67-
raise RuntimeError(f"Unexpected HEAD status from JOBE checkFile: {r.status_code} {r.text[:300]}")
72+
raise RuntimeError(
73+
f"Unexpected HEAD status from JOBE checkFile: {r.status_code} {r.text[:300]}"
74+
)
6875

6976
put_url = base_host + PUSH_PROXY + file_id
7077
payload = {"file_contents": _b64_text_utf8(content)}
@@ -75,12 +82,16 @@ def _ensure_file_on_jobe(sess: rq.Session, base_host: str, file_id: str, content
7582
timeout=10,
7683
)
7784
if pr.status_code != 204:
78-
raise RuntimeError(f"Failed to push file to JOBE: {pr.status_code} {pr.text[:300]}")
85+
raise RuntimeError(
86+
f"Failed to push file to JOBE: {pr.status_code} {pr.text[:300]}"
87+
)
88+
7989

8090
# Match what the JS client uses
8191
PUSH_PROXY = "/ns/rsproxy/jobePushFile/"
8292
CHECK_PROXY = "/ns/rsproxy/jobeCheckFile/"
8393

94+
8495
def inject_pass_fail_prints(test_code):
8596
"""
8697
Inserts System.out.println("PASS") before System.exit(0)
@@ -96,19 +107,20 @@ def inject_pass_fail_prints(test_code):
96107
test_code = re.sub(
97108
r"(TestHelper\.runAllTests\(\);\s*)(System\.exit\(0\);)",
98109
r'\1System.out.println("PASS");\n \2',
99-
test_code
110+
test_code,
100111
)
101112

102113
# Insert FAIL prints before System.exit(1) inside catch(Exception e)
103114
if 'System.out.println("FAIL")' not in test_code:
104115
test_code = re.sub(
105116
r"(catch\s*\(\s*Exception\s+e\s*\)\s*\{\s*)(System\.exit\(1\);)",
106117
r'\1System.out.println("FAIL");\n System.out.println(e.getMessage());\n \2',
107-
test_code
118+
test_code,
108119
)
109120

110121
return test_code
111122

123+
112124
# modified from rsproxy.py and livecode.js logic
113125
def load_and_run_java_tests(java_code, test_code):
114126
"""
@@ -126,7 +138,7 @@ def extract_class_name(code):
126138
return match.group(1)
127139
else:
128140
raise ValueError("Could not find a public class declaration.")
129-
141+
130142
test_code = inject_pass_fail_prints(test_code)
131143
print("modified_test_code\n", test_code)
132144
student_class = extract_class_name(java_code)
@@ -135,12 +147,20 @@ def extract_class_name(code):
135147
student_filename = f"{student_class}.java"
136148
test_filename = f"{test_class}.java"
137149

138-
# Runestone-style file ids: "runestone" + md5(filename + content)
139-
student_id = "runestone" + hashlib.md5((student_filename + java_code).encode("utf-8")).hexdigest()
140-
test_id = "runestone" + hashlib.md5((test_filename + test_code).encode("utf-8")).hexdigest()
150+
# Runestone-style file ids: "runestone" + md5(filename + content)
151+
student_id = (
152+
"runestone"
153+
+ hashlib.md5((student_filename + java_code).encode("utf-8")).hexdigest()
154+
)
155+
test_id = (
156+
"runestone"
157+
+ hashlib.md5((test_filename + test_code).encode("utf-8")).hexdigest()
158+
)
141159

142160
runs_url = settings.jobe_server + "/jobe/index.php/restapi/runs/"
143-
student_file_url = settings.jobe_server + "/jobe/index.php/restapi/files/" + student_id
161+
student_file_url = (
162+
settings.jobe_server + "/jobe/index.php/restapi/files/" + student_id
163+
)
144164
test_file_url = settings.jobe_server + "/jobe/index.php/restapi/files/" + test_id
145165

146166
sess = rq.Session()
@@ -157,15 +177,25 @@ def extract_class_name(code):
157177
r = sess.head(student_file_url, timeout=10)
158178
if r.status_code != 204:
159179
# if not found (typically 404), push it
160-
put = sess.put(student_file_url, json={"file_contents": student_b64}, timeout=10)
180+
put = sess.put(
181+
student_file_url, json={"file_contents": student_b64}, timeout=10
182+
)
161183
if put.status_code != 204:
162-
return False, {"error": "Failed to push student file", "status": put.status_code, "body": put.text[:500]}
184+
return False, {
185+
"error": "Failed to push student file",
186+
"status": put.status_code,
187+
"body": put.text[:500],
188+
}
163189

164190
r = sess.head(test_file_url, timeout=10)
165191
if r.status_code != 204:
166192
put = sess.put(test_file_url, json={"file_contents": test_b64}, timeout=10)
167193
if put.status_code != 204:
168-
return False, {"error": "Failed to push test file", "status": put.status_code, "body": put.text[:500]}
194+
return False, {
195+
"error": "Failed to push test file",
196+
"status": put.status_code,
197+
"body": put.text[:500],
198+
}
169199

170200
# JOBE runs this, and it calls test class main()
171201
runner_code = f"""public class TestRunner {{
@@ -190,7 +220,11 @@ def extract_class_name(code):
190220
try:
191221
result = resp.json()
192222
except Exception:
193-
return False, {"error": "Non-JSON JOBE response", "status": resp.status_code, "body": resp.text[:800]}
223+
return False, {
224+
"error": "Non-JSON JOBE response",
225+
"status": resp.status_code,
226+
"body": resp.text[:800],
227+
}
194228

195229
out = (result.get("stdout") or "").strip()
196230
passed = (result.get("outcome") == 15) and out.startswith("PASS")
@@ -199,6 +233,7 @@ def extract_class_name(code):
199233
except Exception:
200234
return False
201235

236+
202237
def load_and_run_tests(unittest_case, code_to_test, time_limit=6):
203238
"""
204239
Load and run Python test cases against the provided code.

bases/rsptx/rsmanage/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ async def addcourse(
312312
basecourse = click.prompt("Base Course: ")
313313
bookrec = await fetch_library_book(basecourse)
314314
if not bookrec:
315-
click.echo(f"{basecourse} Not Found: Please add the book first using `addbookauthor")
315+
click.echo(
316+
f"{basecourse} Not Found: Please add the book first using `addbookauthor"
317+
)
316318
exit(1)
317319
if bookrec and bookrec.build_system is None:
318320
click.echo(
@@ -955,7 +957,9 @@ def grade(config, course, pset, enforce):
955957
)
956958
@click.option("--sample_size", help="Number of courses to sample", default=0)
957959
@click.option("--course_list", help="List of courses to sample", default=None)
958-
@click.option("--preserve_user_ids", is_flag=True, help="Preserve user ids in the datashop export")
960+
@click.option(
961+
"--preserve_user_ids", is_flag=True, help="Preserve user ids in the datashop export"
962+
)
959963
@pass_config
960964
async def datashop(config, basecourse, sample_size, course_list, preserve_user_ids):
961965
"""Export the course data to the datashop format"""

components/rsptx/build_tools/add_github_links.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from pathlib import Path
55

66

7-
def build_github_url(owner: str, repo: str, branch: str, root: Path, file_path: Path, line: int | None) -> str:
7+
def build_github_url(
8+
owner: str, repo: str, branch: str, root: Path, file_path: Path, line: int | None
9+
) -> str:
810
# "root" should be the repository root; we build a URL
911
# relative to that so it matches the layout on GitHub.
1012
rel = file_path.relative_to(root).as_posix()
@@ -41,7 +43,9 @@ def find_exercise_open_line(lines: list[str], close_index: int) -> int | None:
4143
return None
4244

4345

44-
def process_file(path: Path, root: Path, owner: str, repo: str, branch: str, dry_run: bool) -> int:
46+
def process_file(
47+
path: Path, root: Path, owner: str, repo: str, branch: str, dry_run: bool
48+
) -> int:
4549
text = path.read_text(encoding="utf-8")
4650
lines = text.splitlines(keepends=True)
4751

@@ -93,7 +97,11 @@ def process_file(path: Path, root: Path, owner: str, repo: str, branch: str, dry
9397

9498
# Build fast lookup tables for rewriting.
9599
close_to_ex = {e["close_idx"]: e for e in exercises}
96-
url_to_ex = {e["existing_url_index"]: e for e in exercises if e["existing_url_index"] is not None}
100+
url_to_ex = {
101+
e["existing_url_index"]: e
102+
for e in exercises
103+
if e["existing_url_index"] is not None
104+
}
97105

98106
# Third pass: rebuild the file contents with corrected URLs and without
99107
# counting our local-only <url> lines toward GitHub line numbers.
@@ -119,8 +127,12 @@ def process_file(path: Path, root: Path, owner: str, repo: str, branch: str, dry
119127
newline = "\r\n"
120128

121129
exercise_line_number = ex["exercise_line_number"]
122-
github_url = build_github_url(owner, repo, branch, root, path, exercise_line_number)
123-
url_line = f'{indent}<url href="{github_url}">Source on GitHub</url>{newline}'
130+
github_url = build_github_url(
131+
owner, repo, branch, root, path, exercise_line_number
132+
)
133+
url_line = (
134+
f'{indent}<url href="{github_url}">Source on GitHub</url>{newline}'
135+
)
124136

125137
new_lines.append(url_line)
126138

@@ -167,7 +179,7 @@ def main():
167179
"--file",
168180
type=str,
169181
help="Single XML file to process (relative to --root or absolute). "
170-
"If omitted, all XML files under --root are processed.",
182+
"If omitted, all XML files under --root are processed.",
171183
)
172184
parser.add_argument(
173185
"--dry-run",
@@ -188,10 +200,14 @@ def main():
188200
if target.suffix != ".xml":
189201
print(f"Warning: file does not have .xml suffix: {target}")
190202

191-
inserts = process_file(target, root, args.owner, args.repo, args.branch, args.dry_run)
203+
inserts = process_file(
204+
target, root, args.owner, args.repo, args.branch, args.dry_run
205+
)
192206
prefix = "[DRY-RUN] " if args.dry_run else ""
193207
print(f"{prefix}Updated {target}: added {inserts} <url> tag(s)")
194-
print(f"Done. Files changed: {1 if inserts else 0}, <url> tags added: {inserts}")
208+
print(
209+
f"Done. Files changed: {1 if inserts else 0}, <url> tags added: {inserts}"
210+
)
195211
return
196212

197213
# No --file: process all XML files under root
@@ -208,10 +224,12 @@ def main():
208224
if inserts:
209225
total_files += 1
210226
total_inserts += inserts
211-
print(f"{'[DRY-RUN] ' if args.dry_run else ''}Updated {fpath}: added {inserts} <url> tag(s)")
227+
print(
228+
f"{'[DRY-RUN] ' if args.dry_run else ''}Updated {fpath}: added {inserts} <url> tag(s)"
229+
)
212230

213231
print(f"Done. Files changed: {total_files}, <url> tags added: {total_inserts}")
214232

215233

216234
if __name__ == "__main__":
217-
main()
235+
main()

components/rsptx/build_tools/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,8 @@ def dev(ctx, config):
894894
ctx.invoke(image)
895895
ctx.invoke(restart)
896896

897-
# This command should be used when you pull new code from github and want to rebuild and make
897+
898+
# This command should be used when you pull new code from github and want to rebuild and make
898899
# sure you are using the latest database schema. Many people forget to run migrations
899900
# after pulling new code.
900901
@cli.command()

0 commit comments

Comments
 (0)