diff --git a/src/kili/adapters/kili_api_gateway/issue/__init__.py b/src/kili/adapters/kili_api_gateway/issue/__init__.py index 91f176448..656c5c990 100644 --- a/src/kili/adapters/kili_api_gateway/issue/__init__.py +++ b/src/kili/adapters/kili_api_gateway/issue/__init__.py @@ -1,9 +1,12 @@ """Mixin extending Kili API Gateway class with Issue related operations.""" - -from typing import List +from typing import Dict, Generator, List from kili.adapters.kili_api_gateway.base import BaseOperationMixin -from kili.adapters.kili_api_gateway.issue.mappers import issue_where_mapper +from kili.adapters.kili_api_gateway.helpers.queries import ( + PaginatedGraphQLQuery, + QueryOptions, + fragment_builder, +) from kili.adapters.kili_api_gateway.issue.operations import ( GQL_COUNT_ISSUES, GQL_CREATE_ISSUES, @@ -11,8 +14,12 @@ from kili.adapters.kili_api_gateway.issue.types import IssueToCreateKiliAPIGatewayInput from kili.core.utils.pagination import BatchIteratorBuilder from kili.domain.issue import IssueFilters, IssueId, IssueType +from kili.domain.types import ListOrTuple from kili.utils import tqdm +from .mappers import issue_where_mapper +from .operations import get_issues_query + class IssueOperationMixin(BaseOperationMixin): """GraphQL Mixin extending GraphQL Gateway class with Issue related operations.""" @@ -53,3 +60,14 @@ def count_issues(self, filters: IssueFilters) -> int: payload = {"where": where} count_result = self.graphql_client.execute(GQL_COUNT_ISSUES, payload) return count_result["data"] + + def list_issues( + self, filters: IssueFilters, fields: ListOrTuple[str], options: QueryOptions + ) -> Generator[Dict, None, None]: + """Send a GraphQL request calling issues resolver.""" + fragment = fragment_builder(fields) + query = get_issues_query(fragment) + where = issue_where_mapper(filters=filters) + return PaginatedGraphQLQuery(self.graphql_client).execute_query_from_paginated_call( + query, where, options, "Retrieving issues", GQL_COUNT_ISSUES + ) diff --git a/src/kili/adapters/kili_api_gateway/issue/mappers.py b/src/kili/adapters/kili_api_gateway/issue/mappers.py index f539e6f53..2e2595435 100644 --- a/src/kili/adapters/kili_api_gateway/issue/mappers.py +++ b/src/kili/adapters/kili_api_gateway/issue/mappers.py @@ -1,9 +1,11 @@ """GraphQL payload data mappers for asset operations.""" +from typing import Any, Dict + from kili.domain.issue import IssueFilters -def issue_where_mapper(filters: IssueFilters): +def issue_where_mapper(filters: IssueFilters) -> Dict[str, Any]: """Build the GraphQL IssueWhere variable to be sent in an operation.""" return { "project": {"id": filters.project_id}, diff --git a/src/kili/adapters/kili_api_gateway/issue/operations.py b/src/kili/adapters/kili_api_gateway/issue/operations.py index 1f14caad6..b137c9eb0 100644 --- a/src/kili/adapters/kili_api_gateway/issue/operations.py +++ b/src/kili/adapters/kili_api_gateway/issue/operations.py @@ -19,3 +19,14 @@ data: countIssues(where: $where) } """ + + +def get_issues_query(fragment: str) -> str: + """Return the GraphQL issues query.""" + return f""" + query issues($where: IssueWhere!, $first: PageSize!, $skip: Int!) {{ + data: issues(where: $where, first: $first, skip: $skip) {{ + {fragment} + }} + }} + """ diff --git a/src/kili/client.py b/src/kili/client.py index 83fa5162a..d4c6913b1 100644 --- a/src/kili/client.py +++ b/src/kili/client.py @@ -22,7 +22,6 @@ from kili.entrypoints.mutations.user import MutationsUser from kili.entrypoints.queries.data_connection import QueriesDataConnection from kili.entrypoints.queries.data_integration import QueriesDataIntegration -from kili.entrypoints.queries.issue import QueriesIssue from kili.entrypoints.queries.label import QueriesLabel from kili.entrypoints.queries.notification import QueriesNotification from kili.entrypoints.queries.organization import QueriesOrganization @@ -65,7 +64,6 @@ class Kili( # pylint: disable=too-many-ancestors,too-many-instance-attributes MutationsUser, QueriesDataConnection, QueriesDataIntegration, - QueriesIssue, QueriesLabel, QueriesNotification, QueriesOrganization, diff --git a/src/kili/core/graphql/operations/issue/__init__.py b/src/kili/core/graphql/operations/issue/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/kili/core/graphql/operations/issue/queries.py b/src/kili/core/graphql/operations/issue/queries.py deleted file mode 100644 index e80a7816e..000000000 --- a/src/kili/core/graphql/operations/issue/queries.py +++ /dev/null @@ -1,56 +0,0 @@ -"""GraphQL Queries of Issues.""" - -from typing import List, Literal, Optional - -from kili.core.graphql.queries import BaseQueryWhere, GraphQLQuery - - -class IssueWhere(BaseQueryWhere): - """Tuple to be passed to the IssueQuery to restrict query.""" - - # pylint: disable=too-many-arguments - def __init__( - self, - project_id: Optional[str] = None, - asset_id: Optional[str] = None, - asset_id_in: Optional[List[str]] = None, - issue_type: Optional[Literal["QUESTION", "ISSUE"]] = None, - status: Optional[Literal["OPEN", "SOLVED"]] = None, - ) -> None: - self.project_id = project_id - self.asset_id = asset_id - self.asset_id_in = asset_id_in - self.issue_type = issue_type - self.status = status - super().__init__() - - def graphql_where_builder(self): - """Build the GraphQL Where payload sent in the resolver from the SDK IssueWhere.""" - return { - "project": {"id": self.project_id}, - "asset": {"id": self.asset_id}, - "assetIn": self.asset_id_in, - "status": self.status, - "type": self.issue_type, - } - - -class IssueQuery(GraphQLQuery): - """Issue query.""" - - @staticmethod - def query(fragment): - """Return the GraphQL issues query.""" - return f""" - query issues($where: IssueWhere!, $first: PageSize!, $skip: Int!) {{ - data: issues(where: $where, first: $first, skip: $skip) {{ - {fragment} - }} - }} - """ - - COUNT_QUERY = """ - query countIssues($where: IssueWhere!) { - data: countIssues(where: $where) - } - """ diff --git a/src/kili/domain/issue.py b/src/kili/domain/issue.py index 1085e9a6d..d0be85f57 100644 --- a/src/kili/domain/issue.py +++ b/src/kili/domain/issue.py @@ -2,6 +2,8 @@ from dataclasses import dataclass from typing import List, Literal, NewType, Optional +from kili.domain.project import ProjectId + IssueType = Literal["ISSUE", "QUESTION"] IssueStatus = Literal["OPEN", "SOLVED"] IssueId = NewType("IssueId", str) @@ -11,7 +13,7 @@ class IssueFilters: """Issue filters for running an issue search.""" - project_id: str + project_id: ProjectId asset_id: Optional[str] = None asset_id_in: Optional[List[str]] = None issue_type: Optional[IssueType] = None diff --git a/src/kili/entrypoints/queries/issue/__init__.py b/src/kili/entrypoints/queries/issue/__init__.py deleted file mode 100644 index e6e0e7f44..000000000 --- a/src/kili/entrypoints/queries/issue/__init__.py +++ /dev/null @@ -1,163 +0,0 @@ -"""Issue queries.""" -from typing import Dict, Generator, Iterable, List, Literal, Optional, overload - -from typeguard import typechecked - -from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions -from kili.core.graphql.operations.issue.queries import IssueQuery, IssueWhere -from kili.domain.types import ListOrTuple -from kili.entrypoints.base import BaseOperationEntrypointMixin -from kili.presentation.client.helpers.common_validators import ( - disable_tqdm_if_as_generator, -) -from kili.utils.logcontext import for_all_methods, log_call - - -@for_all_methods(log_call, exclude=["__init__"]) -class QueriesIssue(BaseOperationEntrypointMixin): - """Set of Issue queries.""" - - # pylint: disable=too-many-arguments - - @overload - def issues( - self, - project_id: str, - fields: ListOrTuple[str] = ( - "id", - "createdAt", - "status", - "type", - ), - first: Optional[int] = None, - skip: int = 0, - disable_tqdm: Optional[bool] = None, - asset_id: Optional[str] = None, - asset_id_in: Optional[List[str]] = None, - issue_type: Optional[Literal["QUESTION", "ISSUE"]] = None, - status: Optional[Literal["OPEN", "SOLVED"]] = None, - *, - as_generator: Literal[True], - ) -> Generator[Dict, None, None]: ... - - @overload - def issues( - self, - project_id: str, - fields: ListOrTuple[str] = ( - "id", - "createdAt", - "status", - "type", - ), - first: Optional[int] = None, - skip: int = 0, - disable_tqdm: Optional[bool] = None, - asset_id: Optional[str] = None, - asset_id_in: Optional[List[str]] = None, - issue_type: Optional[Literal["QUESTION", "ISSUE"]] = None, - status: Optional[Literal["OPEN", "SOLVED"]] = None, - *, - as_generator: Literal[False] = False, - ) -> List[Dict]: ... - - @typechecked - def issues( - self, - project_id: str, - fields: ListOrTuple[str] = ( - "id", - "createdAt", - "status", - "type", - "assetId", - ), - first: Optional[int] = None, - skip: int = 0, - disable_tqdm: Optional[bool] = None, - asset_id: Optional[str] = None, - asset_id_in: Optional[List[str]] = None, - issue_type: Optional[Literal["QUESTION", "ISSUE"]] = None, - status: Optional[Literal["OPEN", "SOLVED"]] = None, - *, - as_generator: bool = False, - ) -> Iterable[Dict]: - # pylint: disable=line-too-long - """Get a generator or a list of issues that match a set of criteria. - - !!! Info "Issues or Questions" - An `Issue` object both represent an issue and a question in the app. - To create them, two different methods are provided: `create_issues` and `create_questions`. - However to query issues and questions, we currently provide this unique method that retrieves both of them. - - Args: - project_id: Project ID the issue belongs to. - asset_id: Id of the asset whose returned issues are associated to. - asset_id_in: List of Ids of assets whose returned issues are associated to. - issue_type: Type of the issue to return. An issue object both represents issues and questions in the app. - status: Status of the issues to return. - fields: All the fields to request among the possible fields for the assets. - See [the documentation](https://docs.kili-technology.com/reference/graphql-api#issue) for all possible fields. - first: Maximum number of issues to return. - skip: Number of issues to skip (they are ordered by their date of creation, first to last). - disable_tqdm: If `True`, the progress bar will be disabled - as_generator: If `True`, a generator on the issues is returned. - - Returns: - An iterable of issues objects represented as `dict`. - - Examples: - >>> kili.issues(project_id=project_id, fields=['author.email']) # List all issues of a project and their authors - """ - if asset_id and asset_id_in: - raise ValueError( - "You cannot provide both `asset_id` and `asset_id_in` at the same time" - ) - where = IssueWhere( - project_id=project_id, - asset_id=asset_id, - asset_id_in=asset_id_in, - issue_type=issue_type, - status=status, - ) - disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm) - options = QueryOptions(disable_tqdm, first, skip) - issues_gen = IssueQuery(self.graphql_client, self.http_client)(where, fields, options) - if as_generator: - return issues_gen - return list(issues_gen) - - @typechecked - def count_issues( - self, - project_id: str, - asset_id: Optional[str] = None, - asset_id_in: Optional[List[str]] = None, - issue_type: Optional[Literal["QUESTION", "ISSUE"]] = None, - status: Optional[Literal["OPEN", "SOLVED"]] = None, - ) -> int: - """Count and return the number of issues with the given constraints. - - Args: - project_id: Project ID the issue belongs to. - asset_id: Asset id whose returned issues are associated to. - asset_id_in: List of asset ids whose returned issues are associated to. - issue_type: Type of the issue to return. An issue object both - represents issues and questions in the app - status: Status of the issues to return. - - Returns: - The number of issues with the parameters provided - """ - if asset_id and asset_id_in: - raise ValueError( - "You cannot provide both `asset_id` and `asset_id_in` at the same time" - ) - where = IssueWhere( - project_id=project_id, - asset_id=asset_id, - asset_id_in=asset_id_in, - issue_type=issue_type, - status=status, - ) - return IssueQuery(self.graphql_client, self.http_client).count(where) diff --git a/src/kili/presentation/client/asset.py b/src/kili/presentation/client/asset.py index aa99e9417..05dc7b8d0 100644 --- a/src/kili/presentation/client/asset.py +++ b/src/kili/presentation/client/asset.py @@ -15,6 +15,7 @@ from typeguard import typechecked +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.domain.asset import AssetFilters from kili.domain.issue import IssueStatus, IssueType from kili.domain.types import ListOrTuple @@ -437,12 +438,10 @@ def assets( assets_gen = asset_use_cases.list_assets( filters, fields, - first, - skip, - disable_tqdm, - download_media, - local_media_dir, - label_output_format, + download_media=download_media, + local_media_dir=local_media_dir, + label_output_format=label_output_format, + options=QueryOptions(disable_tqdm=disable_tqdm, first=first, skip=skip), ) if format == "pandas": diff --git a/src/kili/presentation/client/internal.py b/src/kili/presentation/client/internal.py index b254a36a6..39acdbb0b 100644 --- a/src/kili/presentation/client/internal.py +++ b/src/kili/presentation/client/internal.py @@ -5,6 +5,7 @@ from typeguard import typechecked from kili.adapters.kili_api_gateway import KiliAPIGateway +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.domain.api_key import ApiKeyFilters from kili.domain.types import ListOrTuple from kili.entrypoints.mutations.organization import MutationsOrganization @@ -96,7 +97,9 @@ def api_keys( """ api_key_use_cases = ApiKeyUseCases(self.kili_api_gateway) filters = ApiKeyFilters(api_key_id=api_key_id, user_id=user_id, api_key=api_key) - api_keys_gen = api_key_use_cases.list_api_keys(filters, fields, first, skip, disable_tqdm) + api_keys_gen = api_key_use_cases.list_api_keys( + filters, fields, QueryOptions(first=first, skip=skip, disable_tqdm=disable_tqdm) + ) if as_generator: return api_keys_gen diff --git a/src/kili/presentation/client/issue.py b/src/kili/presentation/client/issue.py index b8f6557ba..1f1fd90e8 100644 --- a/src/kili/presentation/client/issue.py +++ b/src/kili/presentation/client/issue.py @@ -1,12 +1,18 @@ +# pylint: disable=too-many-arguments """Client presentation methods for issues.""" from itertools import repeat -from typing import Dict, List, Literal, Optional +from typing import Dict, Generator, Iterable, List, Literal, Optional, overload from typeguard import typechecked +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions +from kili.domain.issue import IssueFilters, IssueStatus, IssueType +from kili.domain.project import ProjectId +from kili.domain.types import ListOrTuple from kili.presentation.client.helpers.common_validators import ( assert_all_arrays_have_same_size, + disable_tqdm_if_as_generator, ) from kili.use_cases.issue import IssueUseCases from kili.use_cases.issue.types import IssueToCreateUseCaseInput @@ -50,3 +56,153 @@ def create_issues( issue_service = IssueUseCases(self.kili_api_gateway) issue_ids = issue_service.create_issues(project_id=project_id, issues=issues) return [{"id": issue_id} for issue_id in issue_ids] + + @typechecked + def count_issues( + self, + project_id: str, + asset_id: Optional[str] = None, + asset_id_in: Optional[List[str]] = None, + issue_type: Optional[IssueType] = None, + status: Optional[IssueStatus] = None, + ) -> int: + """Count and return the number of issues with the given constraints. + + Args: + project_id: Project ID the issue belongs to. + asset_id: Asset id whose returned issues are associated to. + asset_id_in: List of asset ids whose returned issues are associated to. + issue_type: Type of the issue to return. An issue object both + represents issues and questions in the app. + status: Status of the issues to return. + + Returns: + The number of issues that match the given constraints. + """ + if asset_id and asset_id_in: + raise ValueError( + "You cannot provide both `asset_id` and `asset_id_in` at the same time." + ) + return IssueUseCases(self.kili_api_gateway).count_issues( + IssueFilters( + project_id=ProjectId(project_id), + asset_id=asset_id, + asset_id_in=asset_id_in, + issue_type=issue_type, + status=status, + ) + ) + + @overload + def issues( + self, + project_id: str, + fields: ListOrTuple[str] = ( + "id", + "createdAt", + "status", + "type", + "assetId", + ), + first: Optional[int] = None, + skip: int = 0, + disable_tqdm: Optional[bool] = None, + asset_id: Optional[str] = None, + asset_id_in: Optional[List[str]] = None, + issue_type: Optional[IssueType] = None, + status: Optional[IssueStatus] = None, + *, + as_generator: Literal[True], + ) -> Generator[Dict, None, None]: ... + + @overload + def issues( + self, + project_id: str, + fields: ListOrTuple[str] = ( + "id", + "createdAt", + "status", + "type", + "assetId", + ), + first: Optional[int] = None, + skip: int = 0, + disable_tqdm: Optional[bool] = None, + asset_id: Optional[str] = None, + asset_id_in: Optional[List[str]] = None, + issue_type: Optional[IssueType] = None, + status: Optional[IssueStatus] = None, + *, + as_generator: Literal[False] = False, + ) -> List[Dict]: ... + + @typechecked + def issues( + self, + project_id: str, + fields: ListOrTuple[str] = ( + "id", + "createdAt", + "status", + "type", + "assetId", + ), + first: Optional[int] = None, + skip: int = 0, + disable_tqdm: Optional[bool] = None, + asset_id: Optional[str] = None, + asset_id_in: Optional[List[str]] = None, + issue_type: Optional[IssueType] = None, + status: Optional[IssueStatus] = None, + *, + as_generator: bool = False, + ) -> Iterable[Dict]: + # pylint: disable=line-too-long + """Get a generator or a list of issues that match a set of criteria. + + !!! Info "Issues or Questions" + An `Issue` object both represent an issue and a question in the app. + To create them, two different methods are provided: `create_issues` and `create_questions`. + However to query issues and questions, we currently provide this unique method that retrieves both of them. + + Args: + project_id: Project ID the issue belongs to. + asset_id: Id of the asset whose returned issues are associated to. + asset_id_in: List of Ids of assets whose returned issues are associated to. + issue_type: Type of the issue to return. An issue object both represents issues and questions in the app. + status: Status of the issues to return. + fields: All the fields to request among the possible fields for the assets. + See [the documentation](https://docs.kili-technology.com/reference/graphql-api#issue) for all possible fields. + first: Maximum number of issues to return. + skip: Number of issues to skip (they are ordered by their date of creation, first to last). + disable_tqdm: If `True`, the progress bar will be disabled + as_generator: If `True`, a generator on the issues is returned. + + Returns: + An iterable of issues objects represented as `dict`. + + Examples: + >>> kili.issues(project_id=project_id, fields=['author.email']) # List all issues of a project and their authors + """ + if asset_id and asset_id_in: + raise ValueError( + "You cannot provide both `asset_id` and `asset_id_in` at the same time." + ) + + disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm) + options = QueryOptions(disable_tqdm=disable_tqdm, first=first, skip=skip) + issues_gen = IssueUseCases(self.kili_api_gateway).list_issues( + IssueFilters( + project_id=ProjectId(project_id), + asset_id=asset_id, + asset_id_in=asset_id_in, + issue_type=issue_type, + status=status, + ), + fields=fields, + options=options, + ) + if as_generator: + return issues_gen + return list(issues_gen) diff --git a/src/kili/presentation/client/project.py b/src/kili/presentation/client/project.py index c3e3bef0b..688d780ab 100644 --- a/src/kili/presentation/client/project.py +++ b/src/kili/presentation/client/project.py @@ -14,10 +14,14 @@ from typeguard import typechecked +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.core.enums import ProjectType from kili.domain.project import ComplianceTag, InputType, ProjectFilters, ProjectId from kili.domain.tag import TagId from kili.domain.types import ListOrTuple +from kili.presentation.client.helpers.common_validators import ( + disable_tqdm_if_as_generator, +) from kili.use_cases.project.project import ProjectUseCases from kili.use_cases.tag import TagUseCases from kili.utils.logcontext import for_all_methods, log_call @@ -237,6 +241,8 @@ def projects( TagUseCases(self.kili_api_gateway).get_tag_ids_from_labels(tags_in) if tags_in else None ) + disable_tqdm = disable_tqdm_if_as_generator(as_generator, disable_tqdm) + projects_gen = ProjectUseCases(self.kili_api_gateway).list_projects( ProjectFilters( id=ProjectId(project_id) if project_id else None, @@ -251,9 +257,7 @@ def projects( tag_ids=tag_ids, ), fields, - first, - skip, - disable_tqdm, + options=QueryOptions(disable_tqdm=disable_tqdm, first=first, skip=skip), ) if as_generator: diff --git a/src/kili/use_cases/api_key/__init__.py b/src/kili/use_cases/api_key/__init__.py index 56cb7c1a7..a292cc79e 100644 --- a/src/kili/use_cases/api_key/__init__.py +++ b/src/kili/use_cases/api_key/__init__.py @@ -1,7 +1,7 @@ """Api Keys use cases.""" import warnings from datetime import datetime, timedelta -from typing import Dict, Generator, Optional +from typing import Dict, Generator from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.domain.api_key import ApiKeyFilters @@ -14,15 +14,9 @@ class ApiKeyUseCases(BaseUseCases): # pylint: disable=too-many-arguments def list_api_keys( - self, - filters: ApiKeyFilters, - fields: ListOrTuple[str], - first: Optional[int], - skip: int, - disable_tqdm: Optional[bool], + self, filters: ApiKeyFilters, fields: ListOrTuple[str], options: QueryOptions ) -> Generator[Dict, None, None]: """List api keys with given options.""" - options = QueryOptions(skip=skip, first=first, disable_tqdm=disable_tqdm) return self._kili_api_gateway.list_api_keys(filters, fields, options) def count_api_keys(self, filters: ApiKeyFilters) -> int: diff --git a/src/kili/use_cases/asset/__init__.py b/src/kili/use_cases/asset/__init__.py index c53c326a4..fbdfc5ad3 100644 --- a/src/kili/use_cases/asset/__init__.py +++ b/src/kili/use_cases/asset/__init__.py @@ -23,9 +23,7 @@ def list_assets( self, filters: AssetFilters, fields: ListOrTuple[str], - first: Optional[int], - skip: int, - disable_tqdm: Optional[bool], + options: QueryOptions, download_media: bool, local_media_dir: Optional[str], label_output_format: Literal["dict", "parsed_label"], @@ -41,7 +39,6 @@ def list_assets( ProjectId(filters.project_id), local_media_dir, ) - options = QueryOptions(skip=skip, first=first, disable_tqdm=disable_tqdm) assets_gen = self._kili_api_gateway.list_assets(filters, fields, options) if download_media_function is not None: diff --git a/src/kili/use_cases/issue/__init__.py b/src/kili/use_cases/issue/__init__.py index 25a575552..6320ab8ac 100644 --- a/src/kili/use_cases/issue/__init__.py +++ b/src/kili/use_cases/issue/__init__.py @@ -1,9 +1,11 @@ """Issue use cases.""" -from typing import List +from typing import Dict, Generator, List +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.adapters.kili_api_gateway.issue.types import IssueToCreateKiliAPIGatewayInput -from kili.domain.issue import IssueId +from kili.domain.issue import IssueFilters, IssueId +from kili.domain.types import ListOrTuple from kili.entrypoints.mutations.issue.helpers import get_labels_asset_ids_map from kili.use_cases.base import BaseUseCases from kili.use_cases.issue.types import IssueToCreateUseCaseInput @@ -30,3 +32,13 @@ def create_issues( for issue in issues ] return self._kili_api_gateway.create_issues(type_="ISSUE", issues=gateway_issues) + + def count_issues(self, filters: IssueFilters) -> int: + """Count issues.""" + return self._kili_api_gateway.count_issues(filters) + + def list_issues( + self, filters: IssueFilters, fields: ListOrTuple[str], options: QueryOptions + ) -> Generator[Dict, None, None]: + """List issues.""" + return self._kili_api_gateway.list_issues(filters=filters, fields=fields, options=options) diff --git a/src/kili/use_cases/project/project.py b/src/kili/use_cases/project/project.py index ff37eeb15..9030c2c94 100644 --- a/src/kili/use_cases/project/project.py +++ b/src/kili/use_cases/project/project.py @@ -56,16 +56,10 @@ def list_projects( self, project_filters: ProjectFilters, fields: ListOrTuple[str], - first: Optional[int], - skip: int, - disable_tqdm: Optional[bool], + options: QueryOptions, ) -> Generator[Dict, None, None]: """Return a generator of projects that match the filter.""" - return self._kili_api_gateway.list_projects( - project_filters, - fields, - options=QueryOptions(skip=skip, first=first, disable_tqdm=disable_tqdm), - ) + return self._kili_api_gateway.list_projects(project_filters, fields, options=options) def count_projects(self, project_filters: ProjectFilters) -> int: """Return the number of projects that match the filter.""" diff --git a/tests/integration/use_cases/test_asset.py b/tests/integration/use_cases/test_asset.py index 47e9c9dfa..0007fc80c 100644 --- a/tests/integration/use_cases/test_asset.py +++ b/tests/integration/use_cases/test_asset.py @@ -1,4 +1,5 @@ from kili.adapters.kili_api_gateway import KiliAPIGateway +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.domain.asset import AssetFilters from kili.use_cases.asset import AssetUseCases from kili.use_cases.asset.media_downloader import MediaDownloader @@ -20,12 +21,10 @@ def test_given_query_parameters_I_can_query_assets(kili_api_gateway: KiliAPIGate asset_gen = asset_use_cases.list_assets( filters, fields, - first=None, - skip=0, - disable_tqdm=False, download_media=False, local_media_dir=None, label_output_format="dict", + options=QueryOptions(disable_tqdm=False, first=None, skip=0), ) # then @@ -90,12 +89,10 @@ def test_given_query_parameters_I_can_query_assets_and_get_their_labels_parsed( asset_gen = asset_use_cases.list_assets( filters, fields, - first=None, - skip=0, - disable_tqdm=False, download_media=False, local_media_dir=None, label_output_format="parsed_label", + options=QueryOptions(first=None, skip=0, disable_tqdm=False), ) # then @@ -125,12 +122,10 @@ def test_given_query_parameters_I_can_query_assets_and_download_their_media( asset_use_cases.list_assets( filters, fields, - first=None, - skip=0, - disable_tqdm=False, download_media=True, local_media_dir="temp_dir", label_output_format="dict", + options=QueryOptions(first=None, skip=0, disable_tqdm=False), ) # then diff --git a/tests/integration/use_cases/test_project.py b/tests/integration/use_cases/test_project.py index a4e7de639..d1726ae52 100644 --- a/tests/integration/use_cases/test_project.py +++ b/tests/integration/use_cases/test_project.py @@ -1,6 +1,7 @@ from types import GeneratorType from kili.adapters.kili_api_gateway import KiliAPIGateway +from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.adapters.kili_api_gateway.project.types import ProjectDataKiliAPIGatewayInput from kili.domain.project import ProjectFilters, ProjectId from kili.domain.types import ListOrTuple @@ -52,9 +53,7 @@ def test_when_i_query_projects_i_get_a_generator_of_projects(kili_api_gateway: K tag_ids=None, ), fields=("id", "title", "jsonInterface", "inputType"), - first=None, - skip=0, - disable_tqdm=None, + options=QueryOptions(disable_tqdm=None, first=None, skip=0), ) # Then