Skip to content

Commit e3270b0

Browse files
committed
Update docs for api module.
1 parent 1b5898f commit e3270b0

File tree

4 files changed

+77
-25
lines changed

4 files changed

+77
-25
lines changed

docs/source/api/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
api
55
submission
6-
clients
6+
clients
7+
types

docs/source/api/types.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Types Module
2+
============
3+
4+
.. automodule:: judge0.base_types
5+
:members:
6+
:undoc-members:

docs/source/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ Getting Involved
3838
TODO
3939

4040
.. toctree::
41-
:caption: Getting Involved
41+
:caption: API
4242
:glob:
4343
:titlesonly:
4444
:hidden:
4545

46-
contributors_guide/index
46+
api/index
4747

4848
.. toctree::
49-
:caption: API
49+
:caption: Getting Involved
5050
:glob:
5151
:titlesonly:
5252
:hidden:
5353

54-
api/index
54+
contributors_guide/index

src/judge0/api.py

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99

1010

1111
def get_client(flavor: Flavor = Flavor.CE) -> Client:
12+
"""Resolve client from API keys from environment or default to preview client.
13+
14+
Parameters
15+
----------
16+
flavor : Flavor
17+
Flavor of Judge0 Client.
18+
19+
Returns
20+
-------
21+
Client
22+
An object of base type Client and the specified flavor.
23+
"""
1224
from . import _get_implicit_client
1325

1426
if isinstance(flavor, Flavor):
@@ -26,23 +38,40 @@ def _resolve_client(
2638
) -> Client:
2739
"""Resolve a client from flavor or submission(s) arguments.
2840
41+
Parameters
42+
----------
43+
client : Client or Flavor, optional
44+
A Client object or flavor of client. Returns the client if not None.
45+
submissions: Submission or Submissions, optional
46+
Submission(s) used to determine the suitable client.
47+
48+
Returns
49+
-------
50+
Client
51+
An object of base type Client.
52+
2953
Raises
3054
------
3155
ClientResolutionError
32-
Raised if client resolution fails.
56+
If there is no implemented client that supports all the languages specified
57+
in the submissions.
3358
"""
3459
# User explicitly passed a client.
3560
if isinstance(client, Client):
3661
return client
3762

63+
# NOTE: At the moment, we do not support the option to check if explicit
64+
# flavor of a client supports the submissions, i.e. submissions argument is
65+
# ignored if flavor argument is provided.
66+
3867
if isinstance(client, Flavor):
3968
return get_client(client)
4069

4170
if client is None and isinstance(submissions, Iterable) and len(submissions) == 0:
4271
raise ValueError("Client cannot be determined from empty submissions.")
4372

4473
# client is None and we have to determine a flavor of the client from the
45-
# submissions and the languages.
74+
# the submission's languages.
4675
if isinstance(submissions, Submission):
4776
submissions = [submissions]
4877

@@ -65,18 +94,17 @@ def _resolve_client(
6594

6695
def create_submissions(
6796
*,
68-
client: Optional[Client] = None,
97+
client: Optional[Union[Client, Flavor]] = None,
6998
submissions: Optional[Union[Submission, Submissions]] = None,
7099
) -> Union[Submission, Submissions]:
71-
"""Create submissions to a client.
100+
"""Universal function for creating submissions to the client.
72101
73102
Parameters
74103
----------
75-
client : Client, optional
76-
A Client where submissions should be created. If None, will try to
77-
be automatically resolved.
78-
submissions: Submission, Submissions
79-
A submission or submissions to create.
104+
client : Client or Flavor, optional
105+
A client or client flavor where submissions should be created.
106+
submissions: Submission or Submissions, optional
107+
Submission(s) to create.
80108
81109
Raises
82110
------
@@ -102,19 +130,20 @@ def create_submissions(
102130

103131
def get_submissions(
104132
*,
105-
client: Optional[Client] = None,
133+
client: Optional[Union[Client, Flavor]] = None,
106134
submissions: Optional[Union[Submission, Submissions]] = None,
107135
fields: Optional[Union[str, Iterable[str]]] = None,
108136
) -> Union[Submission, Submissions]:
109-
"""Create submissions to a client.
137+
"""Get submission (status) from a client.
110138
111139
Parameters
112140
----------
113-
client : Client, optional
114-
A Client where submissions should be created. If None, will try to
115-
be automatically resolved.
116-
submissions: Submission, Submissions
117-
A submission or submissions to create.
141+
client : Client or Flavor, optional
142+
A client or client flavor where submissions should be checked.
143+
submissions : Submission or Submissions, optional
144+
Submission(s) to update.
145+
fields : str or sequence of str, optional
146+
Submission attributes that need to be updated. Defaults to all attributes.
118147
119148
Raises
120149
------
@@ -144,10 +173,26 @@ def get_submissions(
144173

145174
def wait(
146175
*,
147-
client: Optional[Client] = None,
176+
client: Optional[Union[Client, Flavor]] = None,
148177
submissions: Optional[Union[Submission, Submissions]] = None,
149178
retry_strategy: Optional[RetryStrategy] = None,
150179
) -> Union[Submission, Submissions]:
180+
"""Wait for all the submissions to finish.
181+
182+
Parameters
183+
----------
184+
client : Client or Flavor, optional
185+
A client or client flavor where submissions should be checked.
186+
submissions : Submission or Submissions
187+
Submission(s) to wait for.
188+
retry_strategy : RetryStrategy, optional
189+
A retry strategy.
190+
191+
Raises
192+
------
193+
ClientResolutionError
194+
Raised if client resolution fails.
195+
"""
151196
client = _resolve_client(client, submissions)
152197

153198
if retry_strategy is None:
@@ -189,9 +234,9 @@ def create_submissions_from_test_cases(
189234
submissions: Union[Submission, Submissions],
190235
test_cases: Optional[Union[TestCaseType, TestCases]] = None,
191236
) -> Union[Submission, list[Submission]]:
192-
"""Create submissions from the (submission, test_case) pairs.
237+
"""Create submissions from the submission and test case pairs.
193238
194-
This function always returns a deep copy so make sure you are using the
239+
Function always returns a deep copy so make sure you are using the
195240
returned submission(s).
196241
197242
Parameters
@@ -335,7 +380,7 @@ def sync_execute(
335380
A client where submissions should be created. If None, will try to be
336381
resolved.
337382
submissions : Submission or Submissions, optional
338-
Submission or submissions for execution.
383+
Submission(s) for execution.
339384
source_code: str, optional
340385
A source code of a program.
341386
test_cases: TestCaseType or TestCases, optional

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy