Skip to content

Commit

Permalink
Rename Open Tasks to Pending Tasks (#930)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
fm3 and normanrz authored Aug 14, 2023
1 parent e329e2c commit 7fc7685
Show file tree
Hide file tree
Showing 60 changed files with 1,399 additions and 367 deletions.
1 change: 1 addition & 0 deletions webknossos/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.13.3...HEAD)

### Breaking Changes
- 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)

### Added

Expand Down
2 changes: 1 addition & 1 deletion webknossos/__generate_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def iterate_request_ids_with_responses() -> Iterable[Tuple[str, bytes]]:
"projectId",
"dataSet",
"status",
"open",
"pending",
"active",
"finished",
##### Annotation #####
Expand Down
6 changes: 4 additions & 2 deletions webknossos/examples/annotation_project_administration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ def main() -> None:
sample_project = Project.get_by_name("sampleProject")
tasks = sample_project.get_tasks()
total_active_instances = sum([task.status.active_instance_count for task in tasks])
total_open_instances = sum([task.status.open_instance_count for task in tasks])
total_pending_instances = sum(
[task.status.pending_instance_count for task in tasks]
)
print(
f"There are {total_active_instances} active and {total_open_instances} open task instances."
f"There are {total_active_instances} active and {total_pending_instances} pending task instances."
)

# Find and download all of the project’s annotations that are already finished by annotators
Expand Down
59 changes: 23 additions & 36 deletions webknossos/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webknossos/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ boltons = "~21.0.0"
cattrs = "^22.2.0"
cluster_tools = { path = "../cluster_tools/", develop = true }
fsspec = "^2022.2.0"
httpx = ">=0.15.4,<0.19.0"
httpx = ">=0.20.0,<=0.24.1"
loxun = "^2.0"
natsort = "^6.2.0"
networkx = "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion webknossos/tests/dataset/test_add_layer_from_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def download_and_unpack(
filename = [filename]
for url_i, filename_i in zip(url, filename):
with NamedTemporaryFile() as download_file:
with httpx.stream("GET", url_i) as response:
with httpx.stream("GET", url_i, follow_redirects=True) as response:
total = int(response.headers["Content-Length"])

with wk.utils.get_rich_progress() as progress:
Expand Down
16 changes: 12 additions & 4 deletions webknossos/webknossos/administration/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from webknossos.client.context import _get_generated_client
from webknossos.dataset.dataset import RemoteDataset
from webknossos.geometry import BoundingBox, Vec3Int
from webknossos.utils import warn_deprecated

logger = logging.getLogger(__name__)

Expand All @@ -28,10 +29,15 @@

@attr.frozen
class TaskStatus:
open_instance_count: int
pending_instance_count: int
active_instance_count: int
finished_instance_count: int

@property
def open_instance_count(self) -> int:
warn_deprecated("open_instance_count", "pending_instance_count")
return self.pending_instance_count


@attr.frozen
class Task:
Expand Down Expand Up @@ -78,7 +84,7 @@ def create_from_annotations(
"domain": needed_experience_domain,
"value": needed_experience_value,
},
"openInstances": instances,
"pendingInstances": instances,
"projectName": project_name,
"scriptId": script_id,
"boundingBox": bounding_box.to_wkw_dict()
Expand Down Expand Up @@ -131,7 +137,7 @@ def create(
"domain": needed_experience_domain,
"value": needed_experience_value,
},
"openInstances": instances,
"pendingInstances": instances,
"projectName": project_name,
"scriptId": script_id,
"dataSet": dataset_name,
Expand Down Expand Up @@ -175,7 +181,9 @@ def _from_generated_response(
response.project_id,
response.data_set,
TaskStatus(
response.status.open_, response.status.active, response.status.finished
response.status.pending,
response.status.active,
response.status.finished,
),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from http import HTTPStatus
from typing import Any, Dict, Union
from typing import Any, Dict, Optional, Union

import httpx

from ... import errors
from ...client import Client
from ...models.dataset_cancel_upload_json_body import DatasetCancelUploadJsonBody
from ...types import UNSET, Response, Unset
Expand Down Expand Up @@ -32,17 +33,29 @@ def _get_kwargs(
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"follow_redirects": client.follow_redirects,
"json": json_json_body,
"params": params,
}


def _build_response(*, response: httpx.Response) -> Response[Any]:
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
if response.status_code == HTTPStatus.OK:
return None
if response.status_code == HTTPStatus.BAD_REQUEST:
return None
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
parsed=_parse_response(client=client, response=response),
)


Expand All @@ -63,6 +76,10 @@ def sync_detailed(
token (Union[Unset, None, str]):
json_body (DatasetCancelUploadJsonBody):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Any]
"""
Expand All @@ -78,7 +95,7 @@ def sync_detailed(
**kwargs,
)

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


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

return _build_response(response=response)
return _build_response(client=client, response=response)
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from http import HTTPStatus
from typing import Any, Dict, Union
from typing import Any, Dict, Optional, Union

import httpx

from ... import errors
from ...client import Client
from ...types import UNSET, Response, Unset

Expand Down Expand Up @@ -63,16 +64,28 @@ def _get_kwargs(
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"follow_redirects": client.follow_redirects,
"params": params,
}


def _build_response(*, response: httpx.Response) -> Response[Any]:
def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]:
if response.status_code == HTTPStatus.OK:
return None
if response.status_code == HTTPStatus.BAD_REQUEST:
return None
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=None,
parsed=_parse_response(client=client, response=response),
)


Expand Down Expand Up @@ -110,6 +123,10 @@ def sync_detailed(
half_byte (Union[Unset, None, bool]):
mapping_name (Union[Unset, None, str]):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Any]
"""
Expand All @@ -136,7 +153,7 @@ def sync_detailed(
**kwargs,
)

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


async def asyncio_detailed(
Expand Down Expand Up @@ -173,6 +190,10 @@ async def asyncio_detailed(
half_byte (Union[Unset, None, bool]):
mapping_name (Union[Unset, None, str]):
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.
Returns:
Response[Any]
"""
Expand All @@ -197,4 +218,4 @@ async def asyncio_detailed(
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)

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

0 comments on commit 7fc7685

Please sign in to comment.