Skip to content

Commit 0f63e3e

Browse files
committed
Update Client docs. Simplify docs structure.
1 parent eb4fbff commit 0f63e3e

File tree

7 files changed

+160
-32
lines changed

7 files changed

+160
-32
lines changed

docs/source/api/clients.rst

+43-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
Clients Module
22
==============
33

4-
.. automodule:: judge0.clients
5-
:members:
6-
:member-order: groupwise
4+
5+
.. autoclass:: judge0.clients.Client
6+
:exclude-members: API_KEY_ENV
7+
8+
.. autoclass:: judge0.clients.ATD
9+
:show-inheritance:
10+
11+
.. autoclass:: judge0.clients.ATDJudge0CE
12+
:show-inheritance:
13+
:exclude-members: DEFAULT_ENDPOINT, DEFAULT_HOST, HOME_URL, DEFAULT_ABOUT_ENDPOINT,
14+
DEFAULT_CONFIG_INFO_ENDPOINT, DEFAULT_LANGUAGE_ENDPOINT, DEFAULT_LANGUAGES_ENDPOINT,
15+
DEFAULT_STATUSES_ENDPOINT, DEFAULT_CREATE_SUBMISSION_ENDPOINT, DEFAULT_GET_SUBMISSION_ENDPOINT,
16+
DEFAULT_CREATE_SUBMISSIONS_ENDPOINT, DEFAULT_GET_SUBMISSIONS_ENDPOINT, get_about,
17+
get_config_info, get_language, get_languages, get_statuses, create_submission, get_submission,
18+
create_submissions, get_submissions
19+
20+
.. autoclass:: judge0.clients.ATDJudge0ExtraCE
21+
:show-inheritance:
22+
:exclude-members: DEFAULT_ENDPOINT, DEFAULT_HOST, HOME_URL, DEFAULT_ABOUT_ENDPOINT,
23+
DEFAULT_CONFIG_INFO_ENDPOINT, DEFAULT_LANGUAGE_ENDPOINT, DEFAULT_LANGUAGES_ENDPOINT,
24+
DEFAULT_STATUSES_ENDPOINT, DEFAULT_CREATE_SUBMISSION_ENDPOINT, DEFAULT_GET_SUBMISSION_ENDPOINT,
25+
DEFAULT_CREATE_SUBMISSIONS_ENDPOINT, DEFAULT_GET_SUBMISSIONS_ENDPOINT, get_about,
26+
get_config_info, get_language, get_languages, get_statuses, create_submission, get_submission,
27+
create_submissions, get_submissions
28+
29+
30+
.. autoclass:: judge0.clients.Rapid
31+
:show-inheritance:
32+
33+
.. autoclass:: judge0.clients.RapidJudge0CE
34+
:show-inheritance:
35+
36+
.. autoclass:: judge0.clients.RapidJudge0ExtraCE
37+
:show-inheritance:
38+
39+
.. autoclass:: judge0.clients.Sulu
40+
:show-inheritance:
41+
42+
.. autoclass:: judge0.clients.SuluJudge0CE
43+
:show-inheritance:
44+
45+
.. autoclass:: judge0.clients.SuluJudge0ExtraCE
46+
:show-inheritance:

docs/source/api/index.rst

-7
This file was deleted.

docs/source/api/types.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Types Module
33

44
.. automodule:: judge0.base_types
55
:members:
6-
:undoc-members:
6+

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
extensions = [
2222
"sphinx.ext.autodoc",
2323
"sphinx.ext.napoleon",
24-
"sphinx.ext.autosummary",
24+
# "sphinx.ext.autosummary",
2525
"sphinx_autodoc_typehints",
2626
"sphinx_multiversion",
2727
]
@@ -47,7 +47,7 @@
4747

4848
autodoc_default_options = {
4949
"members": True,
50-
"undoc-members": True,
50+
"undoc-members": False,
5151
"private-members": False,
5252
"special-members": False,
5353
"inherited-members": False,

docs/source/contributors_guide/index.rst

-5
This file was deleted.

docs/source/index.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ You can run minimal Hello World example in three easy steps:
2525
3. Run the script.
2626

2727
Want to learn more
28-
------------------
29-
28+
==================
3029

3130
To learn what is happening behind the scenes and how to best use Judge0 Python
3231
SDK to facilitate the development of your own product see In Depth guide and
3332
Examples.
3433

3534
Getting Involved
36-
----------------
35+
================
3736

3837
TODO
3938

@@ -43,12 +42,16 @@ TODO
4342
:titlesonly:
4443
:hidden:
4544

46-
api/index
45+
api/api
46+
api/submission
47+
api/clients
48+
api/types
4749

4850
.. toctree::
4951
:caption: Getting Involved
5052
:glob:
5153
:titlesonly:
5254
:hidden:
5355

54-
contributors_guide/index
56+
contributors_guide/contributing
57+
contributors_guide/release_notes

src/judge0/clients.py

+106-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@
1010

1111

1212
class Client:
13+
"""Base class for all clients.
14+
15+
Parameters
16+
----------
17+
endpoint : str
18+
Client's default endpoint.
19+
auth_headers : dict
20+
Request authentication headers.
21+
22+
Attributes
23+
----------
24+
API_KEY_ENV : str
25+
Environment variable where judge0-python should look for API key for
26+
the client. Set to default values for ATD, RapidAPI, and Sulu clients.
27+
"""
28+
29+
# Environment variable where judge0-python should look for API key for
30+
# the client. Set to default values for ATD, RapidAPI, and Sulu clients.
1331
API_KEY_ENV: ClassVar[str] = None
1432

1533
def __init__(
@@ -24,7 +42,6 @@ def __init__(
2442
self.retry_strategy = retry_strategy
2543
self.session = requests.Session()
2644

27-
# TODO: Should be handled differently.
2845
try:
2946
self.languages = self.get_languages()
3047
self.config = self.get_config_info()
@@ -39,6 +56,13 @@ def __del__(self):
3956

4057
@handle_too_many_requests_error_for_preview_client
4158
def get_about(self) -> dict:
59+
"""Get general information about judge0.
60+
61+
Returns
62+
-------
63+
dict
64+
General information about judge0.
65+
"""
4266
response = self.session.get(
4367
f"{self.endpoint}/about",
4468
headers=self.auth_headers,
@@ -48,6 +72,13 @@ def get_about(self) -> dict:
4872

4973
@handle_too_many_requests_error_for_preview_client
5074
def get_config_info(self) -> Config:
75+
"""Get information about client's configuration.
76+
77+
Returns
78+
-------
79+
Config
80+
Client's configuration.
81+
"""
5182
response = self.session.get(
5283
f"{self.endpoint}/config_info",
5384
headers=self.auth_headers,
@@ -57,20 +88,46 @@ def get_config_info(self) -> Config:
5788

5889
@handle_too_many_requests_error_for_preview_client
5990
def get_language(self, language_id: int) -> Language:
91+
"""Get language corresponding to the id.
92+
93+
Parameters
94+
----------
95+
language_id : int
96+
Language id.
97+
98+
Returns
99+
-------
100+
Language
101+
Language corresponding to the passed id.
102+
"""
60103
request_url = f"{self.endpoint}/languages/{language_id}"
61104
response = self.session.get(request_url, headers=self.auth_headers)
62105
response.raise_for_status()
63106
return Language(**response.json())
64107

65108
@handle_too_many_requests_error_for_preview_client
66109
def get_languages(self) -> list[Language]:
110+
"""Get a list of supported languages.
111+
112+
Returns
113+
-------
114+
list of language
115+
A list of supported languages.
116+
"""
67117
request_url = f"{self.endpoint}/languages"
68118
response = self.session.get(request_url, headers=self.auth_headers)
69119
response.raise_for_status()
70120
return [Language(**lang_dict) for lang_dict in response.json()]
71121

72122
@handle_too_many_requests_error_for_preview_client
73123
def get_statuses(self) -> list[dict]:
124+
"""Get a list of possible submission statuses.
125+
126+
Returns
127+
-------
128+
list of dict
129+
A list of possible submission statues.
130+
"""
74131
response = self.session.get(
75132
f"{self.endpoint}/statuses",
76133
headers=self.auth_headers,
@@ -80,20 +137,43 @@ def get_statuses(self) -> list[dict]:
80137

81138
@property
82139
def version(self):
140+
"""Property corresponding to the current client's version."""
83141
if not hasattr(self, "_version"):
84142
_version = self.get_about()["version"]
85143
setattr(self, "_version", _version)
86144
return self._version
87145

88146
def get_language_id(self, language: Union[LanguageAlias, int]) -> int:
89-
"""Get language id corresponding to the language alias for the client."""
147+
"""Get language id corresponding to the language alias for the client.
148+
149+
Parameters
150+
----------
151+
language : LanguageAlias or int
152+
Language alias or language id.
153+
154+
Returns
155+
-------
156+
Language id corresponding to the language alias.
157+
"""
90158
if isinstance(language, LanguageAlias):
91159
supported_language_ids = LANGUAGE_TO_LANGUAGE_ID[self.version]
92160
language = supported_language_ids.get(language, -1)
93161
return language
94162

95163
def is_language_supported(self, language: Union[LanguageAlias, int]) -> bool:
96-
"""Check if language is supported by the client."""
164+
"""Check if language is supported by the client.
165+
166+
Parameters
167+
----------
168+
language : LanguageAlias or int
169+
Language alias or language id.
170+
171+
Returns
172+
-------
173+
bool
174+
Return True if language is supported by the client, otherwise returns
175+
False.
176+
"""
97177
language_id = self.get_language_id(language)
98178
return any(language_id == lang.id for lang in self.languages)
99179

@@ -208,9 +288,6 @@ def create_submissions(self, submissions: Submissions) -> Submissions:
208288
f"{submission.language}!"
209289
)
210290

211-
# TODO: Maybe raise an exception if the number of submissions is bigger
212-
# than the batch size a client supports?
213-
214291
submissions_body = [submission.as_body(self) for submission in submissions]
215292

216293
response = self.session.post(
@@ -516,7 +593,15 @@ def __init__(self, api_key, **kwargs):
516593

517594

518595
class Sulu(Client):
519-
"""Base class for all Sulu clients."""
596+
"""Base class for all Sulu clients.
597+
598+
Parameters
599+
----------
600+
endpoint : str
601+
Default request endpoint.
602+
api_key : str, optional
603+
Sulu API key.
604+
"""
520605

521606
API_KEY_ENV: ClassVar[str] = "JUDGE0_SULU_API_KEY"
522607

@@ -530,7 +615,13 @@ def __init__(self, endpoint, api_key=None, **kwargs):
530615

531616

532617
class SuluJudge0CE(Sulu):
533-
"""Sulu client for CE flavor."""
618+
"""Sulu client for CE flavor.
619+
620+
Parameters
621+
----------
622+
api_key : str, optional
623+
Sulu API key.
624+
"""
534625

535626
DEFAULT_ENDPOINT: ClassVar[str] = "https://judge0-ce.p.sulu.sh"
536627
HOME_URL: ClassVar[str] = "https://sparkhub.sulu.sh/apis/judge0/judge0-ce/readme"
@@ -544,7 +635,13 @@ def __init__(self, api_key=None, **kwargs):
544635

545636

546637
class SuluJudge0ExtraCE(Sulu):
547-
"""Sulu client for Extra CE flavor."""
638+
"""Sulu client for Extra CE flavor.
639+
640+
Parameters
641+
----------
642+
api_key : str
643+
Sulu API key.
644+
"""
548645

549646
DEFAULT_ENDPOINT: ClassVar[str] = "https://judge0-extra-ce.p.sulu.sh"
550647
HOME_URL: ClassVar[str] = (

0 commit comments

Comments
 (0)