Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fm3 committed Nov 6, 2023
1 parent 07ec794 commit 564aaf6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
pip install poetry
poetry install --extras all
- name: Check if git is dirty
run: |
git diff --no-ext-diff --quiet --exit-code
[[ -z $(git status -s) ]]
- name: Python tests, refreshing the network snapshots
env:
WK_TOKEN: ${{ secrets.WK_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion webknossos/tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_health(client: WkApiClient) -> None:


def test_annotation_info(auth_client: WkApiClient) -> None:
annotation_id = "570ba0092a7c0e980056fe9b" # pylint: disable=redefined-builtin
annotation_id = "570ba0092a7c0e980056fe9b"
typ = "Explorational"
api_annotation = auth_client.annotation_info(annotation_id)
assert api_annotation.id == annotation_id
Expand Down
2 changes: 1 addition & 1 deletion webknossos/webknossos/client/_upload_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .context import _get_context, _WebknossosContext

DEFAULT_SIMULTANEOUS_UPLOADS = 5
MAXIMUM_RETRY_COUNT = 5
MAXIMUM_RETRY_COUNT = 4


class LayerToLink(NamedTuple):
Expand Down
28 changes: 12 additions & 16 deletions webknossos/webknossos/client/apiclient/_abstract_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

Query = Dict[str, Optional[Union[str, int, float, bool]]]

LONG_TIMEOUT_SECONDS = 7200.0
LONG_TIMEOUT_SECONDS = 7200.0 # 2 hours


class AbstractApiClient(ABC):
Expand Down Expand Up @@ -50,10 +50,9 @@ def _get_json_paginated(
"pageNumber": page_number,
"includeTotalCount": True,
}
query_adapted = pagination_query.copy()
if query is not None:
query_adapted.update(query)
response = self._get(route, query_adapted)
pagination_query.update(query)
response = self._get(route, pagination_query)
return self._parse_json(
response, response_type
), self._extract_total_count_header(response)
Expand All @@ -67,7 +66,7 @@ def _post_json(
route: str,
body_structured: Any,
query: Optional[Query] = None,
retry_count: int = 1,
retry_count: int = 0,
timeout_seconds: Optional[float] = None,
) -> None:
body_json = self._prepare_for_json(body_structured)
Expand Down Expand Up @@ -134,7 +133,7 @@ def _post(
query: Optional[Query] = None,
multipart_data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
retry_count: int = 1,
retry_count: int = 0,
timeout_seconds: Optional[float] = None,
) -> httpx.Response:
return self._request(
Expand All @@ -156,19 +155,19 @@ def _request(
body_json: Optional[Any] = None,
multipart_data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
retry_count: int = 1,
retry_count: int = 0,
timeout_seconds: Optional[float] = None,
) -> httpx.Response:
assert (
retry_count > 0
), f"Cannot perform request with retry_count < 1, got {retry_count}"
retry_count >= 0
), f"Cannot perform request with retry_count < 0, got {retry_count}"
url = self.url_from_route(route)
response = None
for _ in range(retry_count):
for _ in range(retry_count + 1):
response = httpx.request(
method,
url,
params=self._filter_query(query),
params=self._omit_none_values_in_query(query),
json=body_json,
data=multipart_data,
files=files,
Expand All @@ -178,14 +177,11 @@ def _request(
if response.status_code == 200 or response.status_code == 400:
# Stop retrying in case of success or bad request
break
assert (
response is not None
), "Got no http response. Was retry_count less than one?"
assert response is not None, "Got no http response object"
self._assert_good_response(response)
return response

# Omit all entries where the value is None
def _filter_query(self, query: Optional[Query]) -> Optional[Query]:
def _omit_none_values_in_query(self, query: Optional[Query]) -> Optional[Query]:
if query is None:
return None
return {k: v for (k, v) in query.items() if v is not None}
Expand Down
2 changes: 1 addition & 1 deletion webknossos/webknossos/client/apiclient/_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
custom_converter = cattrs.Converter()

# Structuring and destructuring used for the attrs classes in apiclient.models.
# The server expects and sends camelCase fields, we want snake_Case here
# The server expects and sends camelCase fields, we want snake_case here
# However, the case conversion should happen only for the attrs classes,
# and not for dicts that may contain user data (e.g. user experiences)

Expand Down

0 comments on commit 564aaf6

Please sign in to comment.