Skip to content

Commit a58855c

Browse files
committed
upgrade libs, move mug to own module
1 parent a4b96c1 commit a58855c

36 files changed

Lines changed: 1034 additions & 686 deletions

poetry.lock

Lines changed: 677 additions & 300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,30 @@ classifiers = [
3232

3333
[tool.poetry.dependencies]
3434
python = "^3.8"
35-
httpx = ">=0.15.4,<0.24.0"
35+
httpx = ">=0.20.0,<0.25.0"
3636
attrs = ">=21.3.0"
3737
python-dateutil = "^2.8.0"
38-
typer = {extras = ["all"], version = "^0.7.0"}
38+
typer = {extras = ["all"], version = "^0.9.0"}
3939
tomlkit = "^0.11.6"
4040
importlib-metadata = {version = "^1.0", python = "<3.8"}
41-
typing-extensions = {version = "^4.6.1", python = "3.9"}
41+
typing-extensions = {version = "^4.7.1", python = "3.9"}
42+
celery = {version = ">=4.0.0,<6.0.0", optional = true}
43+
44+
[tool.poetry.extras]
45+
celery = ["celery"]
4246

4347
[tool.poetry.group.dev.dependencies]
44-
openapi-python-client = "^0.13.1"
48+
openapi-python-client = "^0.15.1"
4549
pytest = "^7.2.1"
4650
isort = "^5.12.0"
4751
black = "^23.1.0"
4852
pre-commit = "^3.0.2"
4953
pytest-httpx = "^0.21.3"
5054
invoke = "^2.0.0"
55+
pytest-celery = "^0.0.0"
5156

5257
[tool.poetry.scripts]
53-
taskbadger = "taskbadger.cli:app"
58+
taskbadger = "taskbadger.cli_main:app"
5459

5560
[build-system]
5661
requires = ["poetry-core>=1.0.0"]

taskbadger/errors.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

taskbadger/exceptions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ def __str__(self):
88

99
class TaskbadgerException(Exception):
1010
pass
11+
12+
13+
class Unauthorized(TaskbadgerException):
14+
pass
15+
16+
17+
class UnexpectedStatus(TaskbadgerException):
18+
def __init__(self, status_code: int, content: bytes):
19+
self.status_code = status_code
20+
self.content = content
21+
22+
super().__init__(f"Unexpected status code: {status_code}")
23+
24+
25+
class ServerError(UnexpectedStatus):
26+
pass

taskbadger/internal/api/action_endpoints/action_cancel.py

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

44
import httpx
55

@@ -13,27 +13,21 @@ def _get_kwargs(
1313
project_slug: str,
1414
task_id: str,
1515
id: str,
16-
*,
17-
client: AuthenticatedClient,
1816
) -> Dict[str, Any]:
19-
url = "{}/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/{id}/".format(
20-
client.base_url, organization_slug=organization_slug, project_slug=project_slug, task_id=task_id, id=id
21-
)
22-
23-
headers: Dict[str, str] = client.get_headers()
24-
cookies: Dict[str, Any] = client.get_cookies()
17+
pass
2518

2619
return {
2720
"method": "delete",
28-
"url": url,
29-
"headers": headers,
30-
"cookies": cookies,
31-
"timeout": client.get_timeout(),
32-
"follow_redirects": client.follow_redirects,
21+
"url": "/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/{id}/".format(
22+
organization_slug=organization_slug,
23+
project_slug=project_slug,
24+
task_id=task_id,
25+
id=id,
26+
),
3327
}
3428

3529

36-
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
30+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
3731
if response.status_code == HTTPStatus.NO_CONTENT:
3832
return None
3933
if client.raise_on_unexpected_status:
@@ -42,7 +36,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any
4236
return None
4337

4438

45-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
39+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]:
4640
return Response(
4741
status_code=HTTPStatus(response.status_code),
4842
content=response.content,
@@ -82,11 +76,9 @@ def sync_detailed(
8276
project_slug=project_slug,
8377
task_id=task_id,
8478
id=id,
85-
client=client,
8679
)
8780

88-
response = httpx.request(
89-
verify=client.verify_ssl,
81+
response = client.get_httpx_client().request(
9082
**kwargs,
9183
)
9284

@@ -124,10 +116,8 @@ async def asyncio_detailed(
124116
project_slug=project_slug,
125117
task_id=task_id,
126118
id=id,
127-
client=client,
128119
)
129120

130-
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
131-
response = await _client.request(**kwargs)
121+
response = await client.get_async_httpx_client().request(**kwargs)
132122

133123
return _build_response(client=client, response=response)

taskbadger/internal/api/action_endpoints/action_create.py

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

44
import httpx
55

@@ -15,30 +15,24 @@ def _get_kwargs(
1515
project_slug: str,
1616
task_id: str,
1717
*,
18-
client: AuthenticatedClient,
1918
json_body: ActionRequest,
2019
) -> Dict[str, Any]:
21-
url = "{}/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/".format(
22-
client.base_url, organization_slug=organization_slug, project_slug=project_slug, task_id=task_id
23-
)
24-
25-
headers: Dict[str, str] = client.get_headers()
26-
cookies: Dict[str, Any] = client.get_cookies()
20+
pass
2721

2822
json_json_body = json_body.to_dict()
2923

3024
return {
3125
"method": "post",
32-
"url": url,
33-
"headers": headers,
34-
"cookies": cookies,
35-
"timeout": client.get_timeout(),
36-
"follow_redirects": client.follow_redirects,
26+
"url": "/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/".format(
27+
organization_slug=organization_slug,
28+
project_slug=project_slug,
29+
task_id=task_id,
30+
),
3731
"json": json_json_body,
3832
}
3933

4034

41-
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Action]:
35+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Action]:
4236
if response.status_code == HTTPStatus.CREATED:
4337
response_201 = Action.from_dict(response.json())
4438

@@ -49,7 +43,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Act
4943
return None
5044

5145

52-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Action]:
46+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Action]:
5347
return Response(
5448
status_code=HTTPStatus(response.status_code),
5549
content=response.content,
@@ -88,12 +82,10 @@ def sync_detailed(
8882
organization_slug=organization_slug,
8983
project_slug=project_slug,
9084
task_id=task_id,
91-
client=client,
9285
json_body=json_body,
9386
)
9487

95-
response = httpx.request(
96-
verify=client.verify_ssl,
88+
response = client.get_httpx_client().request(
9789
**kwargs,
9890
)
9991

@@ -165,12 +157,10 @@ async def asyncio_detailed(
165157
organization_slug=organization_slug,
166158
project_slug=project_slug,
167159
task_id=task_id,
168-
client=client,
169160
json_body=json_body,
170161
)
171162

172-
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
173-
response = await _client.request(**kwargs)
163+
response = await client.get_async_httpx_client().request(**kwargs)
174164

175165
return _build_response(client=client, response=response)
176166

taskbadger/internal/api/action_endpoints/action_get.py

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

44
import httpx
55

@@ -14,27 +14,21 @@ def _get_kwargs(
1414
project_slug: str,
1515
task_id: str,
1616
id: str,
17-
*,
18-
client: AuthenticatedClient,
1917
) -> Dict[str, Any]:
20-
url = "{}/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/{id}/".format(
21-
client.base_url, organization_slug=organization_slug, project_slug=project_slug, task_id=task_id, id=id
22-
)
23-
24-
headers: Dict[str, str] = client.get_headers()
25-
cookies: Dict[str, Any] = client.get_cookies()
18+
pass
2619

2720
return {
2821
"method": "get",
29-
"url": url,
30-
"headers": headers,
31-
"cookies": cookies,
32-
"timeout": client.get_timeout(),
33-
"follow_redirects": client.follow_redirects,
22+
"url": "/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/{id}/".format(
23+
organization_slug=organization_slug,
24+
project_slug=project_slug,
25+
task_id=task_id,
26+
id=id,
27+
),
3428
}
3529

3630

37-
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Action]:
31+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Action]:
3832
if response.status_code == HTTPStatus.OK:
3933
response_200 = Action.from_dict(response.json())
4034

@@ -45,7 +39,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Act
4539
return None
4640

4741

48-
def _build_response(*, client: Client, response: httpx.Response) -> Response[Action]:
42+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Action]:
4943
return Response(
5044
status_code=HTTPStatus(response.status_code),
5145
content=response.content,
@@ -85,11 +79,9 @@ def sync_detailed(
8579
project_slug=project_slug,
8680
task_id=task_id,
8781
id=id,
88-
client=client,
8982
)
9083

91-
response = httpx.request(
92-
verify=client.verify_ssl,
84+
response = client.get_httpx_client().request(
9385
**kwargs,
9486
)
9587

@@ -162,11 +154,9 @@ async def asyncio_detailed(
162154
project_slug=project_slug,
163155
task_id=task_id,
164156
id=id,
165-
client=client,
166157
)
167158

168-
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
169-
response = await _client.request(**kwargs)
159+
response = await client.get_async_httpx_client().request(**kwargs)
170160

171161
return _build_response(client=client, response=response)
172162

taskbadger/internal/api/action_endpoints/action_list.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from http import HTTPStatus
2-
from typing import Any, Dict, List, Optional
2+
from typing import Any, Dict, List, Optional, Union
33

44
import httpx
55

@@ -13,27 +13,22 @@ def _get_kwargs(
1313
organization_slug: str,
1414
project_slug: str,
1515
task_id: str,
16-
*,
17-
client: AuthenticatedClient,
1816
) -> Dict[str, Any]:
19-
url = "{}/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/".format(
20-
client.base_url, organization_slug=organization_slug, project_slug=project_slug, task_id=task_id
21-
)
22-
23-
headers: Dict[str, str] = client.get_headers()
24-
cookies: Dict[str, Any] = client.get_cookies()
17+
pass
2518

2619
return {
2720
"method": "get",
28-
"url": url,
29-
"headers": headers,
30-
"cookies": cookies,
31-
"timeout": client.get_timeout(),
32-
"follow_redirects": client.follow_redirects,
21+
"url": "/api/{organization_slug}/{project_slug}/tasks/{task_id}/actions/".format(
22+
organization_slug=organization_slug,
23+
project_slug=project_slug,
24+
task_id=task_id,
25+
),
3326
}
3427

3528

36-
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List["Action"]]:
29+
def _parse_response(
30+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
31+
) -> Optional[List["Action"]]:
3732
if response.status_code == HTTPStatus.OK:
3833
response_200 = []
3934
_response_200 = response.json()
@@ -49,7 +44,9 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis
4944
return None
5045

5146

52-
def _build_response(*, client: Client, response: httpx.Response) -> Response[List["Action"]]:
47+
def _build_response(
48+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
49+
) -> Response[List["Action"]]:
5350
return Response(
5451
status_code=HTTPStatus(response.status_code),
5552
content=response.content,
@@ -86,11 +83,9 @@ def sync_detailed(
8683
organization_slug=organization_slug,
8784
project_slug=project_slug,
8885
task_id=task_id,
89-
client=client,
9086
)
9187

92-
response = httpx.request(
93-
verify=client.verify_ssl,
88+
response = client.get_httpx_client().request(
9489
**kwargs,
9590
)
9691

@@ -157,11 +152,9 @@ async def asyncio_detailed(
157152
organization_slug=organization_slug,
158153
project_slug=project_slug,
159154
task_id=task_id,
160-
client=client,
161155
)
162156

163-
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
164-
response = await _client.request(**kwargs)
157+
response = await client.get_async_httpx_client().request(**kwargs)
165158

166159
return _build_response(client=client, response=response)
167160

0 commit comments

Comments
 (0)