Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c98e077

Browse files
committedNov 25, 2024·
Add Config dataclass for storing client's info from get_config_info route. Use client.config.max_submission_batch_size in get_submissions and create_submissions.
1 parent 1922033 commit c98e077

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed
 

‎src/judge0/api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ def create_submissions(
6565
if isinstance(submissions, Submission):
6666
return client.create_submission(submissions)
6767

68-
# TODO: Use result from get_config.
6968
result_submissions = []
7069
for submission_batch in batched(
71-
submissions, client.EFFECTIVE_SUBMISSION_BATCH_SIZE
70+
submissions, client.config.max_submission_batch_size
7271
):
7372
if len(submission_batch) > 1:
7473
result_submissions.extend(client.create_submissions(submission_batch))
@@ -89,10 +88,9 @@ def get_submissions(
8988
if isinstance(submissions, Submission):
9089
return client.get_submission(submissions, fields=fields)
9190

92-
# TODO: Use result from get_config.
9391
result_submissions = []
9492
for submission_batch in batched(
95-
submissions, client.EFFECTIVE_SUBMISSION_BATCH_SIZE
93+
submissions, client.config.max_submission_batch_size
9694
):
9795
if len(submission_batch) > 1:
9896
result_submissions.extend(

‎src/judge0/base_types.py

+43
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,46 @@ class Status(IntEnum):
8989

9090
def __str__(self):
9191
return self.name.lower().replace("_", " ").title()
92+
93+
94+
@dataclass(frozen=True)
95+
class Config:
96+
allow_enable_network: bool
97+
allow_enable_per_process_and_thread_memory_limit: bool
98+
allow_enable_per_process_and_thread_time_limit: bool
99+
allowed_languages_for_compile_options: list[str]
100+
callbacks_max_tries: int
101+
callbacks_timeout: float
102+
cpu_extra_time: float
103+
cpu_time_limit: float
104+
enable_additional_files: bool
105+
enable_batched_submissions: bool
106+
enable_callbacks: bool
107+
enable_command_line_arguments: bool
108+
enable_compiler_options: bool
109+
enable_network: bool
110+
enable_per_process_and_thread_memory_limit: bool
111+
enable_per_process_and_thread_time_limit: bool
112+
enable_submission_delete: bool
113+
enable_wait_result: bool
114+
maintenance_mode: bool
115+
max_cpu_extra_time: float
116+
max_cpu_time_limit: float
117+
max_extract_size: int
118+
max_file_size: int
119+
max_max_file_size: int
120+
max_max_processes_and_or_threads: int
121+
max_memory_limit: int
122+
max_number_of_runs: int
123+
max_processes_and_or_threads: int
124+
max_queue_size: int
125+
max_stack_limit: int
126+
max_submission_batch_size: int
127+
max_wall_time_limit: float
128+
memory_limit: int
129+
number_of_runs: int
130+
redirect_stderr_to_stdout: bool
131+
stack_limit: int
132+
submission_cache_duration: float
133+
use_docs_as_homepage: bool
134+
wall_time_limit: float

‎src/judge0/clients.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import requests
44

5-
from .base_types import Language, LanguageAlias
5+
from .base_types import Config, Language, LanguageAlias
66
from .data import LANGUAGE_TO_LANGUAGE_ID
77
from .submission import Submission, Submissions
88

@@ -20,10 +20,8 @@ def __init__(self, endpoint, auth_headers) -> None:
2020
self.auth_headers = auth_headers
2121

2222
try:
23-
self.languages = [
24-
Language(id=lang["id"], name=lang["name"])
25-
for lang in self.get_languages()
26-
]
23+
self.languages = [Language(**lang) for lang in self.get_languages()]
24+
self.config = Config(**self.get_config_info())
2725
except Exception as e:
2826
raise RuntimeError(
2927
f"Authentication failed. Visit {self.HOME_URL} to get or review your authentication credentials."

0 commit comments

Comments
 (0)
Please sign in to comment.