Skip to content

Commit 1225fd0

Browse files
committed
lint: pydocstyle
1 parent d250f32 commit 1225fd0

16 files changed

Lines changed: 180 additions & 139 deletions

File tree

datacrunch/InferenceClient/inference_client.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class InferenceClientError(Exception):
1616

1717

1818
class AsyncStatus(str, Enum):
19+
"""Async status."""
20+
1921
Initialized = 'Initialized'
2022
Queue = 'Queue'
2123
Inference = 'Inference'
@@ -25,6 +27,8 @@ class AsyncStatus(str, Enum):
2527
@dataclass_json(undefined=Undefined.EXCLUDE)
2628
@dataclass
2729
class InferenceResponse:
30+
"""Inference response."""
31+
2832
headers: CaseInsensitiveDict[str]
2933
status_code: int
3034
status_text: str
@@ -66,6 +70,7 @@ def _is_stream_response(self, headers: CaseInsensitiveDict[str]) -> bool:
6670
)
6771

6872
def output(self, is_text: bool = False) -> Any:
73+
"""Get response output as a string or object."""
6974
try:
7075
if is_text:
7176
return self._original_response.text
@@ -99,11 +104,12 @@ def stream(self, chunk_size: int = 512, as_text: bool = True) -> Generator[Any,
99104

100105

101106
class InferenceClient:
107+
"""Inference client."""
108+
102109
def __init__(
103110
self, inference_key: str, endpoint_base_url: str, timeout_seconds: int = 60 * 5
104111
) -> None:
105-
"""
106-
Initialize the InferenceClient.
112+
"""Initialize the InferenceClient.
107113
108114
Args:
109115
inference_key: The authentication key for the API
@@ -139,17 +145,15 @@ def __exit__(self, exc_type, exc_val, exc_tb):
139145

140146
@property
141147
def global_headers(self) -> dict[str, str]:
142-
"""
143-
Get the current global headers that will be used for all requests.
148+
"""Get the current global headers that will be used for all requests.
144149
145150
Returns:
146151
Dictionary of current global headers
147152
"""
148153
return self._global_headers.copy()
149154

150155
def set_global_header(self, key: str, value: str) -> None:
151-
"""
152-
Set or update a global header that will be used for all requests.
156+
"""Set or update a global header that will be used for all requests.
153157
154158
Args:
155159
key: Header name
@@ -158,17 +162,15 @@ def set_global_header(self, key: str, value: str) -> None:
158162
self._global_headers[key] = value
159163

160164
def set_global_headers(self, headers: dict[str, str]) -> None:
161-
"""
162-
Set multiple global headers at once that will be used for all requests.
165+
"""Set multiple global headers at once that will be used for all requests.
163166
164167
Args:
165168
headers: Dictionary of headers to set globally
166169
"""
167170
self._global_headers.update(headers)
168171

169172
def remove_global_header(self, key: str) -> None:
170-
"""
171-
Remove a global header.
173+
"""Remove a global header.
172174
173175
Args:
174176
key: Header name to remove from global headers
@@ -183,8 +185,7 @@ def _build_url(self, path: str) -> str:
183185
def _build_request_headers(
184186
self, request_headers: dict[str, str] | None = None
185187
) -> dict[str, str]:
186-
"""
187-
Build the final headers by merging global headers with request-specific headers.
188+
"""Build the final headers by merging global headers with request-specific headers.
188189
189190
Args:
190191
request_headers: Optional headers specific to this request
@@ -198,8 +199,7 @@ def _build_request_headers(
198199
return headers
199200

200201
def _make_request(self, method: str, path: str, **kwargs) -> requests.Response:
201-
"""
202-
Make an HTTP request with error handling.
202+
"""Make an HTTP request with error handling.
203203
204204
Args:
205205
method: HTTP method to use
@@ -224,7 +224,9 @@ def _make_request(self, method: str, path: str, **kwargs) -> requests.Response:
224224
response.raise_for_status()
225225
return response
226226
except requests.exceptions.Timeout as e:
227-
raise InferenceClientError(f'Request to {path} timed out after {timeout} seconds') from e
227+
raise InferenceClientError(
228+
f'Request to {path} timed out after {timeout} seconds'
229+
) from e
228230
except requests.exceptions.RequestException as e:
229231
raise InferenceClientError(f'Request to {path} failed: {str(e)}') from e
230232

@@ -331,6 +333,7 @@ def get(
331333
headers: dict[str, str] | None = None,
332334
timeout_seconds: int | None = None,
333335
) -> requests.Response:
336+
"""Make GET request."""
334337
return self._make_request(
335338
'GET', path, params=params, headers=headers, timeout_seconds=timeout_seconds
336339
)
@@ -344,6 +347,7 @@ def post(
344347
headers: dict[str, str] | None = None,
345348
timeout_seconds: int | None = None,
346349
) -> requests.Response:
350+
"""Make POST request."""
347351
return self._make_request(
348352
'POST',
349353
path,
@@ -363,6 +367,7 @@ def put(
363367
headers: dict[str, str] | None = None,
364368
timeout_seconds: int | None = None,
365369
) -> requests.Response:
370+
"""Make PUT request."""
366371
return self._make_request(
367372
'PUT',
368373
path,
@@ -380,6 +385,7 @@ def delete(
380385
headers: dict[str, str] | None = None,
381386
timeout_seconds: int | None = None,
382387
) -> requests.Response:
388+
"""Make DELETE request."""
383389
return self._make_request(
384390
'DELETE',
385391
path,
@@ -397,6 +403,7 @@ def patch(
397403
headers: dict[str, str] | None = None,
398404
timeout_seconds: int | None = None,
399405
) -> requests.Response:
406+
"""Make PATCH request."""
400407
return self._make_request(
401408
'PATCH',
402409
path,
@@ -414,6 +421,7 @@ def head(
414421
headers: dict[str, str] | None = None,
415422
timeout_seconds: int | None = None,
416423
) -> requests.Response:
424+
"""Make HEAD request."""
417425
return self._make_request(
418426
'HEAD',
419427
path,
@@ -429,6 +437,7 @@ def options(
429437
headers: dict[str, str] | None = None,
430438
timeout_seconds: int | None = None,
431439
) -> requests.Response:
440+
"""Make OPTIONS request."""
432441
return self._make_request(
433442
'OPTIONS',
434443
path,
@@ -438,8 +447,7 @@ def options(
438447
)
439448

440449
def health(self, healthcheck_path: str = '/health') -> requests.Response:
441-
"""
442-
Check the health status of the API.
450+
"""Check the health status of the API.
443451
444452
Returns:
445453
requests.Response: The response from the health check
@@ -456,22 +464,23 @@ def health(self, healthcheck_path: str = '/health') -> requests.Response:
456464
@dataclass_json(undefined=Undefined.EXCLUDE)
457465
@dataclass
458466
class AsyncInferenceExecution:
467+
"""Async inference execution."""
468+
459469
_inference_client: 'InferenceClient'
460470
id: str
461471
_status: AsyncStatus
462472
INFERENCE_ID_HEADER = 'X-Inference-Id'
463473

464474
def status(self) -> AsyncStatus:
465-
"""Get the current stored status of the async inference execution. Only the status value type
475+
"""Get the current stored status of the async inference execution. Only the status value type.
466476
467477
Returns:
468478
AsyncStatus: The status object
469479
"""
470-
471480
return self._status
472481

473482
def status_json(self) -> dict[str, Any]:
474-
"""Get the current status of the async inference execution. Return the status json
483+
"""Get the current status of the async inference execution. Return the status json.
475484
476485
Returns:
477486
Dict[str, Any]: The status response containing the execution status and other metadata

datacrunch/authentication/authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212

1313
class AuthenticationService:
14-
"""A service for client authentication"""
14+
"""A service for client authentication."""
1515

1616
def __init__(self, client_id: str, client_secret: str, base_url: str) -> None:
1717
self._base_url = base_url
1818
self._client_id = client_id
1919
self._client_secret = client_secret
2020

2121
def authenticate(self) -> dict:
22-
"""Authenticate the client and store the access & refresh tokens
22+
"""Authenticate the client and store the access & refresh tokens.
2323
2424
returns an authentication data dictionary with the following schema:
2525
{

datacrunch/balance/balance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33

44
class Balance:
5-
"""A balance model class"""
5+
"""A balance model class."""
66

77
def __init__(self, amount: float, currency: str) -> None:
8-
"""Initialize a new Balance object
8+
"""Initialize a new Balance object.
99
1010
:param amount: Balance amount
1111
:type amount: float
@@ -17,7 +17,7 @@ def __init__(self, amount: float, currency: str) -> None:
1717

1818
@property
1919
def amount(self) -> float:
20-
"""Get the balance amount
20+
"""Get the balance amount.
2121
2222
:return: amount
2323
:rtype: float
@@ -26,7 +26,7 @@ def amount(self) -> float:
2626

2727
@property
2828
def currency(self) -> str:
29-
"""Get the currency code
29+
"""Get the currency code.
3030
3131
:return: currency code
3232
:rtype: str
@@ -35,13 +35,13 @@ def currency(self) -> str:
3535

3636

3737
class BalanceService:
38-
"""A service for interacting with the balance endpoint"""
38+
"""A service for interacting with the balance endpoint."""
3939

4040
def __init__(self, http_client) -> None:
4141
self._http_client = http_client
4242

4343
def get(self) -> Balance:
44-
"""Get the client's current balance
44+
"""Get the client's current balance.
4545
4646
:return: Balance object containing the amount and currency.
4747
:rtype: Balance

datacrunch/constants.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Actions:
2+
"""Instance actions."""
3+
24
START = 'start'
35
SHUTDOWN = 'shutdown'
46
DELETE = 'delete'
@@ -10,6 +12,8 @@ def __init__(self):
1012

1113

1214
class VolumeActions:
15+
"""Storage volume actions."""
16+
1317
ATTACH = 'attach'
1418
DETACH = 'detach'
1519
RENAME = 'rename'
@@ -22,6 +26,8 @@ def __init__(self):
2226

2327

2428
class InstanceStatus:
29+
"""Instance status."""
30+
2531
ORDERED = 'ordered'
2632
RUNNING = 'running'
2733
PROVISIONING = 'provisioning'
@@ -36,6 +42,8 @@ def __init__(self):
3642

3743

3844
class VolumeStatus:
45+
"""Storage volume status."""
46+
3947
ORDERED = 'ordered'
4048
CREATING = 'creating'
4149
ATTACHED = 'attached'
@@ -49,6 +57,8 @@ def __init__(self):
4957

5058

5159
class VolumeTypes:
60+
"""Storage volume types."""
61+
5262
NVMe = 'NVMe'
5363
HDD = 'HDD'
5464

@@ -57,6 +67,8 @@ def __init__(self):
5767

5868

5969
class Locations:
70+
"""Datacenter locations."""
71+
6072
FIN_01: str = 'FIN-01'
6173
FIN_02: str = 'FIN-02'
6274
FIN_03: str = 'FIN-03'
@@ -67,6 +79,8 @@ def __init__(self):
6779

6880

6981
class ErrorCodes:
82+
"""Error codes."""
83+
7084
INVALID_REQUEST = 'invalid_request'
7185
UNAUTHORIZED_REQUEST = 'unauthorized_request'
7286
INSUFFICIENT_FUNDS = 'insufficient_funds'
@@ -80,6 +94,8 @@ def __init__(self):
8094

8195

8296
class Constants:
97+
"""Constants."""
98+
8399
def __init__(self, base_url, version):
84100
self.instance_actions: Actions = Actions()
85101
"""Available actions to perform on an instance"""

datacrunch/containers/containers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def get_compute_resources(
993993
994994
Args:
995995
size: Optional size to filter resources by (e.g. 8 for 8x GPUs)
996-
available: Optional boolean to filter by availability status
996+
is_available: Optional boolean to filter by availability status
997997
998998
Returns:
999999
List[ComputeResource]: List of compute resources matching the filters.
@@ -1089,6 +1089,7 @@ def create_fileset_secret_from_file_paths(
10891089
self, secret_name: str, file_paths: list[str]
10901090
) -> None:
10911091
"""Creates a new fileset secret.
1092+
10921093
A fileset secret is a secret that contains several files,
10931094
and can be used to mount a directory with the files in a container.
10941095

datacrunch/datacrunch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
class DataCrunchClient:
18-
"""Client for interacting with DataCrunch's public API"""
18+
"""Client for interacting with DataCrunch's public API."""
1919

2020
def __init__(
2121
self,
@@ -24,7 +24,7 @@ def __init__(
2424
base_url: str = 'https://api.datacrunch.io/v1',
2525
inference_key: str = None,
2626
) -> None:
27-
"""The DataCrunch client
27+
"""The DataCrunch client.
2828
2929
:param client_id: client id
3030
:type client_id: str
@@ -35,7 +35,6 @@ def __init__(
3535
:param inference_key: inference key, optional
3636
:type inference_key: str, optional
3737
"""
38-
3938
# Validate that client_id and client_secret are not empty
4039
if not client_id or not client_secret:
4140
raise ValueError('client_id and client_secret must be provided')

datacrunch/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
class APIException(Exception):
22
"""This exception is raised if there was an error from datacrunch's API.
3+
34
Could be an invalid input, token etc.
45
56
Raised when an API HTTP call response has a status code >= 400
67
"""
78

89
def __init__(self, code: str, message: str) -> None:
9-
"""
10+
"""API Exception.
1011
1112
:param code: error code
1213
:type code: str

0 commit comments

Comments
 (0)