Skip to content

Commit 0b40954

Browse files
committed
Fix all black and ruff issues
1 parent 968f1cd commit 0b40954

File tree

12 files changed

+61
-70
lines changed

12 files changed

+61
-70
lines changed

bases/rsptx/admin_server_api/routers/instructor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,9 +1255,7 @@ async def post_create_course_page(
12551255

12561256
# if invoice is true then we need to create an invoice for the course
12571257
if invoice == "true":
1258-
res = await create_invoice_request(
1259-
user.username, projectname, 0.0, user.email
1260-
)
1258+
await create_invoice_request(user.username, projectname, 0.0, user.email)
12611259
# Copy attributes from base course
12621260
bc = await fetch_course(coursetype)
12631261
attrs = await fetch_all_course_attributes(bc.id)

bases/rsptx/assignment_server_api/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from .routers import student
2323
from .routers import instructor
2424
from .routers import peer
25-
from rsptx.configuration import settings
2625
from rsptx.exceptions.core import add_exception_handlers
2726
from rsptx.logging import rslogger
2827
from rsptx.templates import template_folder

bases/rsptx/book_server_api/routers/coach.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async def parsons_scaffolding(request: Request, course: Optional[str]):
208208
rslogger.warning("CodeTailor: api_token obtained successfully")
209209
# Start to process the request from activecode.js
210210
req_bytes = await request.body()
211-
req = req_bytes.decode("utf-8")
211+
_ = req_bytes.decode("utf-8")
212212
data = await request.json()
213213

214214
language = data.get("language") # Capture the question language from the front end

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# import necessary packages
2-
from .buggy_code_checker import *
3-
from .get_personalized_solution import *
4-
from .evaluate_fixed_code import *
5-
from .generate_parsons_blocks import *
6-
from .personalize_parsons import *
7-
from .token_compare import *
8-
from .get_parsons_code_distractors import *
2+
from .buggy_code_checker import student_code_checker
3+
from .evaluate_fixed_code import (
4+
clean_student_code,
5+
code_distractor_unittest_evaluation,
6+
unittest_evaluation,
7+
)
8+
from .generate_parsons_blocks import generate_Parsons_block
9+
from .get_parsons_code_distractors import generate_code_with_distrator
10+
from .get_personalized_solution import get_example_solution, get_fixed_code
11+
from .personalize_parsons import compare_code, personalize_Parsons_block
12+
from .token_compare import code_similarity_score
913

1014

1115
def get_parsons_help(api_token, language, dict_buggy_code, personalize_level):
@@ -149,7 +153,7 @@ def request_fixed_code_from_openai(
149153
if not unittest_result:
150154
return example_solution.lstrip(), "example_solution"
151155

152-
if unittest_result == True:
156+
if unittest_result:
153157
similarity_personalized = code_similarity_score(
154158
cleaned_buggy_code, cleaned_fixed_code, language
155159
)
@@ -248,7 +252,7 @@ def generate_personalized_fixed_code(
248252
default_test_code,
249253
unittest_case=unittest_code,
250254
)
251-
if unittest_result != True:
255+
if not unittest_result:
252256
# If the code is not correct, we will TRY to get an example solution first
253257
example_solution = generate_example_solution(
254258
api_token,
@@ -358,7 +362,7 @@ def generate_multi_personalized_Parsons_blocks(
358362
unittest_code,
359363
)
360364
# If the code with distractors passes the unittest, we will remove the distractor from the distractors list
361-
if unittest_flag == True:
365+
if unittest_flag:
362366
distractors.pop(distractor_correct_line)
363367

364368
if Parsons_type == "Correct":

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
from types import ModuleType
55
import threading
66
import signal
7-
import subprocess
8-
import tempfile
9-
import os
10-
import shutil
11-
from unittest import result
127
import requests as rq
138
import hashlib
149
import base64
1510
import json
16-
from ..rsproxy import get_jobe_server, settings
11+
from ..rsproxy import settings
1712

1813

1914
class NullOutput:
@@ -504,16 +499,16 @@ def code_distractor_unittest_evaluation(
504499
return results.wasSuccessful(), code_with_distrator
505500
else:
506501
return "No starting code", code_with_distrator
507-
except:
502+
except Exception:
508503
try:
509504
code_with_distrator = fix_indentation(code_with_distrator)
510505
results = load_and_run_tests(unittest_case, code_with_distrator)
511506
if contain_default_starting_code(starting_code, code_with_distrator):
512507
return results.wasSuccessful(), code_with_distrator
513508
else:
514509
return "No starting code", code_with_distrator
515-
except Exception:
516-
return False, code_with_distrator
510+
except Exception as e:
511+
return f"We got errors, {e}", code_with_distrator
517512

518513

519514
def clean_student_code(student_code, default_test_code):
@@ -530,7 +525,7 @@ def clean_student_code(student_code, default_test_code):
530525
cleaned_student_code = remove_default_testline(student_code, default_test_code)
531526
cleaned_student_code = remove_empty_lines(cleaned_student_code)
532527
cleaned_student_code = remove_python_comments(cleaned_student_code)
533-
except:
528+
except Exception:
534529
cleaned_student_code = student_code
535530

536531
return cleaned_student_code

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ def generate_partial_Parsons(
215215
line_indentation = fixed_line_code[
216216
: len(fixed_line_code) - len(fixed_line_code.lstrip())
217217
]
218-
if type(distractor_tuple_dict[fixed_line_key]) == tuple:
218+
if type(distractor_tuple_dict[fixed_line_key]) is tuple:
219219
distractor_tuple_dict[fixed_line_key] = (
220220
fixed_line_key[0] + 0.5,
221221
fixed_line_key[0],
222222
line_indentation
223223
+ distractor_tuple_dict[fixed_line_key][2].strip()
224224
+ " #paired",
225225
)
226-
elif type(distractor_tuple_dict[fixed_line_key]) == str:
226+
elif type(distractor_tuple_dict[fixed_line_key]) is str:
227227
distractor_tuple_dict[fixed_line_key] = (
228228
fixed_line_key[0] + 0.5,
229229
fixed_line_key[0],
@@ -257,10 +257,10 @@ def keep_last_hash_tag_lines(input_string, hash_tag):
257257
output_lines = []
258258
found_last_settled = False
259259
for line in reversed(lines):
260-
if (hash_tag in line) & (not found_last_settled):
260+
if (hash_tag in line) and not found_last_settled:
261261
output_lines.append(line)
262262
found_last_settled = True
263-
elif (hash_tag in line) & (found_last_settled == True):
263+
elif (hash_tag in line) and found_last_settled:
264264
line = line.replace(hash_tag, "")
265265
output_lines.append(line)
266266
else:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from openai import OpenAI
22
import re
33

4-
from .evaluate_fixed_code import *
4+
from .evaluate_fixed_code import clean_student_code, unittest_evaluation
55

66
# Below is the system message as part of the prompt to generate the fixed code
77
system_message = """
@@ -263,7 +263,7 @@ def get_example_solution(api_token, language, problem_description, unittest_code
263263
unittest_result, cleaned_LLM_example_code = unittest_evaluation(
264264
language, LLM_example_code, "", "", unittest_case=unittest_code
265265
)
266-
if unittest_result == True:
266+
if unittest_result:
267267
# LLM_example_code is correct
268268
return cleaned_LLM_example_code
269269
else:

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import difflib
22
from collections import namedtuple
3-
from .generate_parsons_blocks import *
4-
from .token_compare import *
3+
from .token_compare import code_similarity_score
54
import random
65
import re
76

@@ -163,8 +162,8 @@ def find_distractor(fixed_line, removed_lines, language):
163162
)
164163
if (
165164
(similarity > highest_similarity)
166-
& (similarity != 1)
167-
& (normalized_line_comparision == False)
165+
and (similarity != 1)
166+
and (not normalized_line_comparision)
168167
):
169168
highest_similarity = similarity
170169
distractor_line = student_line
@@ -291,12 +290,12 @@ def personalize_Parsons_block(
291290
normalize_and_compare = normalize_and_compare_lines(
292291
pair[0][2], pair[1][2], pair[2]
293292
)
294-
if normalize_and_compare == False:
293+
if not normalize_and_compare:
295294
# if the student code is wrong (not just a different way to write the same code), generate a distractor using student buggy code
296295
distractor_similarity, distractor = find_distractor(
297296
pair[1][2], removed_lines, language
298297
)
299-
if distractor != False:
298+
if distractor:
300299
distractors[pair[1]] = (distractor_similarity, distractor)
301300
else:
302301
continue

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def code_similarity_score(code1, code2, language):
8282
try:
8383
tokens1, type1 = tokenize_code(code1, language)
8484
tokens2 = following_tokenize_code(code2, type1, language)
85-
except:
85+
except Exception:
8686
tokens2, type2 = tokenize_code(code2, language)
8787
tokens1 = following_tokenize_code(code1, type2, language)
8888

0 commit comments

Comments
 (0)