Skip to content

Commit 7fc7685

Browse files
fm3normanrz
andauthored
Rename Open Tasks to Pending Tasks (#930)
* Rename Open Tasks to Pending Tasks * format * when downloading test data, follow http redirects * changelog * Update webknossos/webknossos/administration/task.py Co-authored-by: Norman Rzepka <[email protected]> * format * import --------- Co-authored-by: Norman Rzepka <[email protected]>
1 parent e329e2c commit 7fc7685

File tree

60 files changed

+1399
-367
lines changed

Some content is hidden

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

60 files changed

+1399
-367
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1313
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.13.3...HEAD)
1414

1515
### Breaking Changes
16+
- Task/Project management: `open` tasks have been renamed to `pending`. Use `Task.status.pending_instance_count` instead of `Task.status.open_instance_count`. [#930](https://github.com/scalableminds/webknossos-libs/pull/930)
1617

1718
### Added
1819

webknossos/__generate_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def iterate_request_ids_with_responses() -> Iterable[Tuple[str, bytes]]:
317317
"projectId",
318318
"dataSet",
319319
"status",
320-
"open",
320+
"pending",
321321
"active",
322322
"finished",
323323
##### Annotation #####

webknossos/examples/annotation_project_administration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ def main() -> None:
99
sample_project = Project.get_by_name("sampleProject")
1010
tasks = sample_project.get_tasks()
1111
total_active_instances = sum([task.status.active_instance_count for task in tasks])
12-
total_open_instances = sum([task.status.open_instance_count for task in tasks])
12+
total_pending_instances = sum(
13+
[task.status.pending_instance_count for task in tasks]
14+
)
1315
print(
14-
f"There are {total_active_instances} active and {total_open_instances} open task instances."
16+
f"There are {total_active_instances} active and {total_pending_instances} pending task instances."
1517
)
1618

1719
# Find and download all of the project’s annotations that are already finished by annotators

webknossos/poetry.lock

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

webknossos/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ boltons = "~21.0.0"
3535
cattrs = "^22.2.0"
3636
cluster_tools = { path = "../cluster_tools/", develop = true }
3737
fsspec = "^2022.2.0"
38-
httpx = ">=0.15.4,<0.19.0"
38+
httpx = ">=0.20.0,<=0.24.1"
3939
loxun = "^2.0"
4040
natsort = "^6.2.0"
4141
networkx = "^2.6.2"

webknossos/tests/dataset/test_add_layer_from_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def download_and_unpack(
151151
filename = [filename]
152152
for url_i, filename_i in zip(url, filename):
153153
with NamedTemporaryFile() as download_file:
154-
with httpx.stream("GET", url_i) as response:
154+
with httpx.stream("GET", url_i, follow_redirects=True) as response:
155155
total = int(response.headers["Content-Length"])
156156

157157
with wk.utils.get_rich_progress() as progress:

webknossos/webknossos/administration/task.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from webknossos.client.context import _get_generated_client
1515
from webknossos.dataset.dataset import RemoteDataset
1616
from webknossos.geometry import BoundingBox, Vec3Int
17+
from webknossos.utils import warn_deprecated
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -28,10 +29,15 @@
2829

2930
@attr.frozen
3031
class TaskStatus:
31-
open_instance_count: int
32+
pending_instance_count: int
3233
active_instance_count: int
3334
finished_instance_count: int
3435

36+
@property
37+
def open_instance_count(self) -> int:
38+
warn_deprecated("open_instance_count", "pending_instance_count")
39+
return self.pending_instance_count
40+
3541

3642
@attr.frozen
3743
class Task:
@@ -78,7 +84,7 @@ def create_from_annotations(
7884
"domain": needed_experience_domain,
7985
"value": needed_experience_value,
8086
},
81-
"openInstances": instances,
87+
"pendingInstances": instances,
8288
"projectName": project_name,
8389
"scriptId": script_id,
8490
"boundingBox": bounding_box.to_wkw_dict()
@@ -131,7 +137,7 @@ def create(
131137
"domain": needed_experience_domain,
132138
"value": needed_experience_value,
133139
},
134-
"openInstances": instances,
140+
"pendingInstances": instances,
135141
"projectName": project_name,
136142
"scriptId": script_id,
137143
"dataSet": dataset_name,
@@ -175,7 +181,9 @@ def _from_generated_response(
175181
response.project_id,
176182
response.data_set,
177183
TaskStatus(
178-
response.status.open_, response.status.active, response.status.finished
184+
response.status.pending,
185+
response.status.active,
186+
response.status.finished,
179187
),
180188
)
181189

webknossos/webknossos/client/_generated/api/datastore/dataset_cancel_upload.py

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

44
import httpx
55

6+
from ... import errors
67
from ...client import Client
78
from ...models.dataset_cancel_upload_json_body import DatasetCancelUploadJsonBody
89
from ...types import UNSET, Response, Unset
@@ -32,17 +33,29 @@ def _get_kwargs(
3233
"headers": headers,
3334
"cookies": cookies,
3435
"timeout": client.get_timeout(),
36+
"follow_redirects": client.follow_redirects,
3537
"json": json_json_body,
3638
"params": params,
3739
}
3840

3941

40-
def _build_response(*, response: httpx.Response) -> Response[Any]:
42+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
43+
if response.status_code == HTTPStatus.OK:
44+
return None
45+
if response.status_code == HTTPStatus.BAD_REQUEST:
46+
return None
47+
if client.raise_on_unexpected_status:
48+
raise errors.UnexpectedStatus(response.status_code, response.content)
49+
else:
50+
return None
51+
52+
53+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
4154
return Response(
4255
status_code=HTTPStatus(response.status_code),
4356
content=response.content,
4457
headers=response.headers,
45-
parsed=None,
58+
parsed=_parse_response(client=client, response=response),
4659
)
4760

4861

@@ -63,6 +76,10 @@ def sync_detailed(
6376
token (Union[Unset, None, str]):
6477
json_body (DatasetCancelUploadJsonBody):
6578
79+
Raises:
80+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
81+
httpx.TimeoutException: If the request takes longer than Client.timeout.
82+
6683
Returns:
6784
Response[Any]
6885
"""
@@ -78,7 +95,7 @@ def sync_detailed(
7895
**kwargs,
7996
)
8097

81-
return _build_response(response=response)
98+
return _build_response(client=client, response=response)
8299

83100

84101
async def asyncio_detailed(
@@ -98,6 +115,10 @@ async def asyncio_detailed(
98115
token (Union[Unset, None, str]):
99116
json_body (DatasetCancelUploadJsonBody):
100117
118+
Raises:
119+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
120+
httpx.TimeoutException: If the request takes longer than Client.timeout.
121+
101122
Returns:
102123
Response[Any]
103124
"""
@@ -111,4 +132,4 @@ async def asyncio_detailed(
111132
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
112133
response = await _client.request(**kwargs)
113134

114-
return _build_response(response=response)
135+
return _build_response(client=client, response=response)

webknossos/webknossos/client/_generated/api/datastore/dataset_download.py

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

44
import httpx
55

6+
from ... import errors
67
from ...client import Client
78
from ...types import UNSET, Response, Unset
89

@@ -63,16 +64,28 @@ def _get_kwargs(
6364
"headers": headers,
6465
"cookies": cookies,
6566
"timeout": client.get_timeout(),
67+
"follow_redirects": client.follow_redirects,
6668
"params": params,
6769
}
6870

6971

70-
def _build_response(*, response: httpx.Response) -> Response[Any]:
72+
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
73+
if response.status_code == HTTPStatus.OK:
74+
return None
75+
if response.status_code == HTTPStatus.BAD_REQUEST:
76+
return None
77+
if client.raise_on_unexpected_status:
78+
raise errors.UnexpectedStatus(response.status_code, response.content)
79+
else:
80+
return None
81+
82+
83+
def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
7184
return Response(
7285
status_code=HTTPStatus(response.status_code),
7386
content=response.content,
7487
headers=response.headers,
75-
parsed=None,
88+
parsed=_parse_response(client=client, response=response),
7689
)
7790

7891

@@ -110,6 +123,10 @@ def sync_detailed(
110123
half_byte (Union[Unset, None, bool]):
111124
mapping_name (Union[Unset, None, str]):
112125
126+
Raises:
127+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
128+
httpx.TimeoutException: If the request takes longer than Client.timeout.
129+
113130
Returns:
114131
Response[Any]
115132
"""
@@ -136,7 +153,7 @@ def sync_detailed(
136153
**kwargs,
137154
)
138155

139-
return _build_response(response=response)
156+
return _build_response(client=client, response=response)
140157

141158

142159
async def asyncio_detailed(
@@ -173,6 +190,10 @@ async def asyncio_detailed(
173190
half_byte (Union[Unset, None, bool]):
174191
mapping_name (Union[Unset, None, str]):
175192
193+
Raises:
194+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
195+
httpx.TimeoutException: If the request takes longer than Client.timeout.
196+
176197
Returns:
177198
Response[Any]
178199
"""
@@ -197,4 +218,4 @@ async def asyncio_detailed(
197218
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
198219
response = await _client.request(**kwargs)
199220

200-
return _build_response(response=response)
221+
return _build_response(client=client, response=response)

0 commit comments

Comments
 (0)