Skip to content

Commit

Permalink
improve docs for pagination iterable and make sure it inherrits from
Browse files Browse the repository at this point in the history
iterable
  • Loading branch information
bisgaard-itis committed Nov 18, 2024
1 parent 16eed5e commit 7925a79
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions clients/python/src/osparc/_api_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import shutil
from ._utils import (
DEFAULT_TIMEOUT_SECONDS,
PaginationGenerator,
PaginationIterable,
compute_sha256,
file_chunk_generator,
)
Expand Down Expand Up @@ -271,15 +271,15 @@ def _search_files(
file_id: Optional[str] = None,
sha256_checksum: Optional[str] = None,
timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS,
) -> PaginationGenerator:
) -> PaginationIterable:
def _pagination_method():
return super(FilesApi, self).search_files_page(
file_id=file_id,
sha256_checksum=sha256_checksum,
_request_timeout=timeout_seconds,
)

return PaginationGenerator(
return PaginationIterable(
first_page_callback=_pagination_method,
api_client=self.api_client,
base_url=self.api_client.configuration.host,
Expand Down
8 changes: 4 additions & 4 deletions clients/python/src/osparc/_api_solvers_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ._utils import (
_DEFAULT_PAGINATION_LIMIT,
_DEFAULT_PAGINATION_OFFSET,
PaginationGenerator,
PaginationIterable,
)

import warnings
Expand Down Expand Up @@ -47,7 +47,7 @@ def list_solver_ports(
)
return page.items if page.items else []

def iter_jobs(self, solver_key: str, version: str, **kwargs) -> PaginationGenerator:
def iter_jobs(self, solver_key: str, version: str, **kwargs) -> PaginationIterable:
"""Returns an iterator through which one can iterate over
all Jobs submitted to the solver
Expand All @@ -72,14 +72,14 @@ def _pagination_method():
**kwargs,
)

return PaginationGenerator(
return PaginationIterable(
first_page_callback=_pagination_method,
api_client=self.api_client,
base_url=self.api_client.configuration.host,
auth=self._auth,
)

def jobs(self, solver_key: str, version: str, **kwargs) -> PaginationGenerator:
def jobs(self, solver_key: str, version: str, **kwargs) -> PaginationIterable:
warnings.warn(
"The 'jobs' method is deprecated and will be removed in a future version. "
"Please use 'iter_jobs' instead.",
Expand Down
8 changes: 4 additions & 4 deletions clients/python/src/osparc/_api_studies_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ._utils import (
_DEFAULT_PAGINATION_LIMIT,
_DEFAULT_PAGINATION_OFFSET,
PaginationGenerator,
PaginationIterable,
)
import warnings

Expand Down Expand Up @@ -65,7 +65,7 @@ def clone_study(self, study_id: str, **kwargs):
kwargs = {**kwargs, **ParentProjectInfo().model_dump(exclude_none=True)}
return super().clone_study(study_id, **kwargs)

def iter_studies(self, **kwargs) -> PaginationGenerator:
def iter_studies(self, **kwargs) -> PaginationIterable:
def _pagination_method():
page_study = self.list_studies(
limit=_DEFAULT_PAGINATION_LIMIT,
Expand All @@ -75,14 +75,14 @@ def _pagination_method():
assert isinstance(page_study, PageStudy) # nosec
return page_study

return PaginationGenerator(
return PaginationIterable(
first_page_callback=_pagination_method,
api_client=self.api_client,
base_url=self.api_client.configuration.host,
auth=self._auth,
)

def studies(self, **kwargs) -> PaginationGenerator:
def studies(self, **kwargs) -> PaginationIterable:
warnings.warn(
"The 'studies' method is deprecated and will be removed in a future version. "
"Please use 'iter_studies' instead.",
Expand Down
8 changes: 5 additions & 3 deletions clients/python/src/osparc/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hashlib
from pathlib import Path
from typing import AsyncGenerator, Callable, Generator, Optional, Tuple, TypeVar, Union

from collections.abc import Iterable
import httpx
from osparc_client import (
ApiClient,
Expand Down Expand Up @@ -30,8 +30,10 @@
T = TypeVar("T", Job, File, Solver, Study)


class PaginationGenerator:
"""Class for wrapping paginated http methods as generators"""
class PaginationIterable(Iterable):
"""Class for wrapping paginated http methods as iterables. It supports two simple operations:
- for elm in pagination_iterable:
- len(pagination_iterable)"""

def __init__(
self,
Expand Down

0 comments on commit 7925a79

Please sign in to comment.