Skip to content

Commit f435c03

Browse files
authored
IWF-711 Review pyproject.toml version constraints and identify which packages should be updated (#101)
* Declare httpx as a dependency to the SDK * run poetry update * Revert "run poetry update" This reverts commit 7459987. * run poetry lock * Declare httpx as a dependency to the SDK * run poetry lock * Update README command to generate the OpenAPI files * Fix timeout param * Lint fixes * Fixing issues found during code review * Remove fallback, as we couldn't reproduce a case for this * Run lint * Adding except clause to parse_unexpected_error
1 parent afe70e5 commit f435c03

File tree

99 files changed

+2745
-2652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2745
-2652
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ git submodule update --remote --merge
9999
This project uses [openapi-python-client](https://github.com/openapi-generators/openapi-python-client) to generate an API client from the IDL. To update the generated client:
100100
101101
```bash
102-
mkdir iwf/iwf_api/iwf_api
103-
cd iwf && poetry run openapi-python-client update --path ../iwf-idl/iwf-sdk.yaml --config .openapi-python-client-config.yaml
104-
cd .. && cp -R iwf/iwf_api/iwf_api/* iwf/iwf_api && rm -R iwf/iwf_api/iwf_api && poetry update
102+
poetry run openapi-python-client generate --path iwf-idl/iwf-sdk.yaml --config iwf/.openapi-python-client-config.yaml
103+
cp -R iwf_api/iwf_api/* iwf/iwf_api && rm -R iwf_api/ && poetry update
105104
```
106105
107106
The last command will:

iwf/errors.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json as jsonlib
2-
3-
from httpx._utils import guess_json_utf
2+
from httpx import Response
43

54
from iwf.iwf_api.models import (
65
ErrorResponse,
@@ -112,9 +111,8 @@ def process_workflow_abnormal_exit_error(
112111

113112

114113
def parse_unexpected_error(err) -> ErrorResponse:
115-
encoding = guess_json_utf(err.content)
116-
if encoding is not None:
117-
err_dict = jsonlib.loads(err.content.decode(encoding))
118-
else:
119-
err_dict = jsonlib.loads(err.content)
120-
return ErrorResponse.from_dict(err_dict)
114+
try:
115+
response = Response(err.status_code, content=err.content)
116+
return ErrorResponse.from_dict(response.json())
117+
except Exception:
118+
return ErrorResponse.from_dict(jsonlib.loads(err.content))

iwf/iwf_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" A client library for accessing Workflow APIs """
1+
"""A client library for accessing Workflow APIs"""
22

33
from .client import AuthenticatedClient, Client
44

iwf/iwf_api/api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
""" Contains methods for accessing the API """
1+
"""Contains methods for accessing the API"""

iwf/iwf_api/api/default/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains endpoint functions for accessing the API"""

iwf/iwf_api/api/default/get_info_healthcheck.py

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional
2+
from typing import Any, Optional, Union
33

44
import httpx
55

66
from ... import errors
7-
from ...client import Client
7+
from ...client import AuthenticatedClient, Client
88
from ...models.health_info import HealthInfo
99
from ...types import Response
1010

1111

12-
def _get_kwargs(
13-
*,
14-
client: Client,
15-
) -> Dict[str, Any]:
16-
url = "{}/info/healthcheck".format(client.base_url)
17-
18-
headers: Dict[str, str] = client.get_headers()
19-
cookies: Dict[str, Any] = client.get_cookies()
20-
21-
return {
12+
def _get_kwargs() -> dict[str, Any]:
13+
_kwargs: dict[str, Any] = {
2214
"method": "get",
23-
"url": url,
24-
"headers": headers,
25-
"cookies": cookies,
26-
"timeout": client.get_timeout(),
27-
"follow_redirects": client.follow_redirects,
15+
"url": "/info/healthcheck",
2816
}
2917

18+
return _kwargs
3019

31-
def _parse_response(
32-
*, client: Client, response: httpx.Response
33-
) -> Optional[HealthInfo]:
34-
if response.status_code == HTTPStatus.OK:
20+
21+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[HealthInfo]:
22+
if response.status_code == 200:
3523
response_200 = HealthInfo.from_dict(response.json())
3624

3725
return response_200
@@ -41,9 +29,7 @@ def _parse_response(
4129
return None
4230

4331

44-
def _build_response(
45-
*, client: Client, response: httpx.Response
46-
) -> Response[HealthInfo]:
32+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[HealthInfo]:
4733
return Response(
4834
status_code=HTTPStatus(response.status_code),
4935
content=response.content,
@@ -54,7 +40,7 @@ def _build_response(
5440

5541
def sync_detailed(
5642
*,
57-
client: Client,
43+
client: Union[AuthenticatedClient, Client],
5844
) -> Response[HealthInfo]:
5945
"""return health info of the server
6046
@@ -66,12 +52,9 @@ def sync_detailed(
6652
Response[HealthInfo]
6753
"""
6854

69-
kwargs = _get_kwargs(
70-
client=client,
71-
)
55+
kwargs = _get_kwargs()
7256

73-
response = httpx.request(
74-
verify=client.verify_ssl,
57+
response = client.get_httpx_client().request(
7558
**kwargs,
7659
)
7760

@@ -80,7 +63,7 @@ def sync_detailed(
8063

8164
def sync(
8265
*,
83-
client: Client,
66+
client: Union[AuthenticatedClient, Client],
8467
) -> Optional[HealthInfo]:
8568
"""return health info of the server
8669
@@ -99,7 +82,7 @@ def sync(
9982

10083
async def asyncio_detailed(
10184
*,
102-
client: Client,
85+
client: Union[AuthenticatedClient, Client],
10386
) -> Response[HealthInfo]:
10487
"""return health info of the server
10588
@@ -111,19 +94,16 @@ async def asyncio_detailed(
11194
Response[HealthInfo]
11295
"""
11396

114-
kwargs = _get_kwargs(
115-
client=client,
116-
)
97+
kwargs = _get_kwargs()
11798

118-
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
119-
response = await _client.request(**kwargs)
99+
response = await client.get_async_httpx_client().request(**kwargs)
120100

121101
return _build_response(client=client, response=response)
122102

123103

124104
async def asyncio(
125105
*,
126-
client: Client,
106+
client: Union[AuthenticatedClient, Client],
127107
) -> Optional[HealthInfo]:
128108
"""return health info of the server
129109
Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, Optional, Union, cast
2+
from typing import Any, Optional, Union, cast
33

44
import httpx
55

66
from ... import errors
7-
from ...client import Client
7+
from ...client import AuthenticatedClient, Client
88
from ...models.error_response import ErrorResponse
99
from ...models.workflow_config_update_request import WorkflowConfigUpdateRequest
1010
from ...types import Response
1111

1212

1313
def _get_kwargs(
1414
*,
15-
client: Client,
16-
json_body: WorkflowConfigUpdateRequest,
17-
) -> Dict[str, Any]:
18-
url = "{}/api/v1/workflow/config/update".format(client.base_url)
15+
body: WorkflowConfigUpdateRequest,
16+
) -> dict[str, Any]:
17+
headers: dict[str, Any] = {}
1918

20-
headers: Dict[str, str] = client.get_headers()
21-
cookies: Dict[str, Any] = client.get_cookies()
22-
23-
json_json_body = json_body.to_dict()
24-
25-
return {
19+
_kwargs: dict[str, Any] = {
2620
"method": "post",
27-
"url": url,
28-
"headers": headers,
29-
"cookies": cookies,
30-
"timeout": client.get_timeout(),
31-
"follow_redirects": client.follow_redirects,
32-
"json": json_json_body,
21+
"url": "/api/v1/workflow/config/update",
3322
}
3423

24+
_body = body.to_dict()
25+
26+
_kwargs["json"] = _body
27+
headers["Content-Type"] = "application/json"
28+
29+
_kwargs["headers"] = headers
30+
return _kwargs
31+
3532

3633
def _parse_response(
37-
*, client: Client, response: httpx.Response
34+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
3835
) -> Optional[Union[Any, ErrorResponse]]:
39-
if response.status_code == HTTPStatus.OK:
36+
if response.status_code == 200:
4037
response_200 = cast(Any, None)
4138
return response_200
42-
if response.status_code == HTTPStatus.BAD_REQUEST:
39+
if response.status_code == 400:
4340
response_400 = ErrorResponse.from_dict(response.json())
4441

4542
return response_400
@@ -50,7 +47,7 @@ def _parse_response(
5047

5148

5249
def _build_response(
53-
*, client: Client, response: httpx.Response
50+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
5451
) -> Response[Union[Any, ErrorResponse]]:
5552
return Response(
5653
status_code=HTTPStatus(response.status_code),
@@ -62,13 +59,13 @@ def _build_response(
6259

6360
def sync_detailed(
6461
*,
65-
client: Client,
66-
json_body: WorkflowConfigUpdateRequest,
62+
client: Union[AuthenticatedClient, Client],
63+
body: WorkflowConfigUpdateRequest,
6764
) -> Response[Union[Any, ErrorResponse]]:
6865
"""update the config of a workflow
6966
7067
Args:
71-
json_body (WorkflowConfigUpdateRequest):
68+
body (WorkflowConfigUpdateRequest):
7269
7370
Raises:
7471
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -79,12 +76,10 @@ def sync_detailed(
7976
"""
8077

8178
kwargs = _get_kwargs(
82-
client=client,
83-
json_body=json_body,
79+
body=body,
8480
)
8581

86-
response = httpx.request(
87-
verify=client.verify_ssl,
82+
response = client.get_httpx_client().request(
8883
**kwargs,
8984
)
9085

@@ -93,13 +88,13 @@ def sync_detailed(
9388

9489
def sync(
9590
*,
96-
client: Client,
97-
json_body: WorkflowConfigUpdateRequest,
91+
client: Union[AuthenticatedClient, Client],
92+
body: WorkflowConfigUpdateRequest,
9893
) -> Optional[Union[Any, ErrorResponse]]:
9994
"""update the config of a workflow
10095
10196
Args:
102-
json_body (WorkflowConfigUpdateRequest):
97+
body (WorkflowConfigUpdateRequest):
10398
10499
Raises:
105100
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -111,19 +106,19 @@ def sync(
111106

112107
return sync_detailed(
113108
client=client,
114-
json_body=json_body,
109+
body=body,
115110
).parsed
116111

117112

118113
async def asyncio_detailed(
119114
*,
120-
client: Client,
121-
json_body: WorkflowConfigUpdateRequest,
115+
client: Union[AuthenticatedClient, Client],
116+
body: WorkflowConfigUpdateRequest,
122117
) -> Response[Union[Any, ErrorResponse]]:
123118
"""update the config of a workflow
124119
125120
Args:
126-
json_body (WorkflowConfigUpdateRequest):
121+
body (WorkflowConfigUpdateRequest):
127122
128123
Raises:
129124
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -134,25 +129,23 @@ async def asyncio_detailed(
134129
"""
135130

136131
kwargs = _get_kwargs(
137-
client=client,
138-
json_body=json_body,
132+
body=body,
139133
)
140134

141-
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
142-
response = await _client.request(**kwargs)
135+
response = await client.get_async_httpx_client().request(**kwargs)
143136

144137
return _build_response(client=client, response=response)
145138

146139

147140
async def asyncio(
148141
*,
149-
client: Client,
150-
json_body: WorkflowConfigUpdateRequest,
142+
client: Union[AuthenticatedClient, Client],
143+
body: WorkflowConfigUpdateRequest,
151144
) -> Optional[Union[Any, ErrorResponse]]:
152145
"""update the config of a workflow
153146
154147
Args:
155-
json_body (WorkflowConfigUpdateRequest):
148+
body (WorkflowConfigUpdateRequest):
156149
157150
Raises:
158151
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
@@ -165,6 +158,6 @@ async def asyncio(
165158
return (
166159
await asyncio_detailed(
167160
client=client,
168-
json_body=json_body,
161+
body=body,
169162
)
170163
).parsed

0 commit comments

Comments
 (0)