From a0d7712e33dd5a490c7838b7a983053490e8e91f Mon Sep 17 00:00:00 2001 From: Pierre Leveau Date: Thu, 28 Sep 2023 15:19:35 +0200 Subject: [PATCH] fix: take comments --- src/kili/entrypoints/base.py | 3 ++- src/kili/use_cases/asset/__init__.py | 9 ++++--- src/kili/use_cases/project/project.py | 9 ++++--- .../use_cases/question/question_use_case.py | 4 ++-- src/kili/use_cases/tag/__init__.py | 24 ++++++++----------- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/kili/entrypoints/base.py b/src/kili/entrypoints/base.py index 3fb712be9..c93afbeac 100644 --- a/src/kili/entrypoints/base.py +++ b/src/kili/entrypoints/base.py @@ -8,6 +8,7 @@ from kili.core.helpers import format_result from kili.domain.asset import AssetExternalId, AssetId from kili.domain.project import ProjectId +from kili.domain.types import ListOrTuple from kili.use_cases.asset.utils import AssetUseCasesUtils T = TypeVar("T") @@ -34,7 +35,7 @@ def _resolve_asset_ids( asset_ids: Optional[List[str]], external_ids: Optional[List[str]], project_id: Optional[str], - ) -> List[AssetId]: + ) -> ListOrTuple[AssetId]: # FIXME: temporary method to be removed once all methods have been # moved to the new architecture return AssetUseCasesUtils(self.kili_api_gateway).get_asset_ids_or_throw_error( diff --git a/src/kili/use_cases/asset/__init__.py b/src/kili/use_cases/asset/__init__.py index 36163b57a..f318678c8 100644 --- a/src/kili/use_cases/asset/__init__.py +++ b/src/kili/use_cases/asset/__init__.py @@ -2,7 +2,6 @@ import itertools from typing import Dict, Generator, List, Literal, Optional -from kili.adapters.kili_api_gateway import KiliAPIGateway from kili.adapters.kili_api_gateway.helpers.queries import QueryOptions from kili.core.constants import QUERY_BATCH_SIZE from kili.core.helpers import validate_category_search_query @@ -36,14 +35,14 @@ def list_assets( validate_category_search_query(filters.label_category_search) download_media_function, fields = get_download_assets_function( - self._kili_api_gateway, + self.kili_api_gateway, download_media, fields, 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) + assets_gen = self.kili_api_gateway.list_assets(filters, fields, options) if download_media_function is not None: # TODO: modify download_media function so it can take a generator of assets @@ -54,7 +53,7 @@ def list_assets( if label_output_format == "parsed_label": project = LabelParsingProject( - **self._kili_api_gateway.get_project( + **self.kili_api_gateway.get_project( ProjectId(filters.project_id), ("jsonInterface", "inputType") ) ) @@ -66,4 +65,4 @@ def count_assets(self, filters: AssetFilters) -> int: """Send a GraphQL request calling countAssets resolver.""" if filters.label_category_search: validate_category_search_query(filters.label_category_search) - return self._kili_api_gateway.count_assets(filters) + return self.kili_api_gateway.count_assets(filters) diff --git a/src/kili/use_cases/project/project.py b/src/kili/use_cases/project/project.py index 9d398ff38..e20c9ea33 100644 --- a/src/kili/use_cases/project/project.py +++ b/src/kili/use_cases/project/project.py @@ -7,7 +7,6 @@ from tenacity.stop import stop_after_delay from tenacity.wait import wait_fixed -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.mappers import project_data_mapper from kili.adapters.kili_api_gateway.project.types import ProjectDataKiliAPIGatewayInput @@ -32,7 +31,7 @@ def create_project( compliance_tags: Optional[ListOrTuple[ComplianceTag]], ) -> ProjectId: """Create a project.""" - project_id = self._kili_api_gateway.create_project( + project_id = self.kili_api_gateway.create_project( input_type=input_type, json_interface=json_interface, title=title, @@ -49,7 +48,7 @@ def create_project( reraise=True, ): with attempt: - _ = self._kili_api_gateway.get_project(project_id=project_id, fields=("id",)) + _ = self.kili_api_gateway.get_project(project_id=project_id, fields=("id",)) return ProjectId(project_id) @@ -62,7 +61,7 @@ def list_projects( disable_tqdm: Optional[bool], ) -> Generator[Dict, None, None]: """Return a generator of projects that match the filter.""" - return self._kili_api_gateway.list_projects( + return self.kili_api_gateway.list_projects( project_filters, fields, options=QueryOptions(skip=skip, first=first, disable_tqdm=disable_tqdm), @@ -138,4 +137,4 @@ def update_properties_in_project( if "id" not in fields: fields += ("id",) - return self._kili_api_gateway.update_properties_in_project(project_id, project_data, fields) + return self.kili_api_gateway.update_properties_in_project(project_id, project_data, fields) diff --git a/src/kili/use_cases/question/question_use_case.py b/src/kili/use_cases/question/question_use_case.py index 3d825e012..9a2c2d598 100644 --- a/src/kili/use_cases/question/question_use_case.py +++ b/src/kili/use_cases/question/question_use_case.py @@ -7,8 +7,8 @@ from kili.domain.asset.asset import AssetExternalId, AssetId from kili.domain.project import ProjectId from kili.domain.question import QuestionId +from kili.use_cases.asset.utils import AssetUseCasesUtils from kili.use_cases.base import BaseUseCases -from kili.use_cases.utils import UseCasesUtils @dataclass @@ -39,7 +39,7 @@ def create_questions( cast(AssetExternalId, question.asset_external_id) for question in questions ] - asset_ids = UseCasesUtils(self.kili_api_gateway).get_asset_ids_or_throw_error( + asset_ids = AssetUseCasesUtils(self.kili_api_gateway).get_asset_ids_or_throw_error( asset_ids=asset_id_array, external_ids=external_id_array, project_id=project_id ) diff --git a/src/kili/use_cases/tag/__init__.py b/src/kili/use_cases/tag/__init__.py index d28844642..8c69f0e20 100644 --- a/src/kili/use_cases/tag/__init__.py +++ b/src/kili/use_cases/tag/__init__.py @@ -2,7 +2,6 @@ from collections import defaultdict from typing import Dict, List, Optional -from kili.adapters.kili_api_gateway import KiliAPIGateway from kili.adapters.kili_api_gateway.tag.types import UpdateTagReturnData from kili.domain.project import ProjectId from kili.domain.tag import TagId @@ -14,25 +13,22 @@ class TagUseCases(BaseUseCases): """Tag use cases.""" - def __init__(self, kili_api_gateway: KiliAPIGateway) -> None: - self._kili_api_gateway = kili_api_gateway - def get_tags_of_organization(self, fields: ListOrTuple[str]) -> List[Dict]: """Get tags of organization.""" - return self._kili_api_gateway.list_tags_by_org(fields=fields) + return self.kili_api_gateway.list_tags_by_org(fields=fields) def get_tags_of_project(self, project_id: ProjectId, fields: ListOrTuple[str]) -> List[Dict]: """Get tags of project.""" - return self._kili_api_gateway.list_tags_by_project(project_id=project_id, fields=fields) + return self.kili_api_gateway.list_tags_by_project(project_id=project_id, fields=fields) def tag_project( self, project_id: ProjectId, tag_ids: ListOrTuple[TagId], disable_tqdm: Optional[bool] ) -> List[TagId]: """Assign tags to a project.""" - tags_of_orga = self._kili_api_gateway.list_tags_by_org(fields=("id",)) + tags_of_orga = self.kili_api_gateway.list_tags_by_org(fields=("id",)) tags_of_orga_ids = [tag["id"] for tag in tags_of_orga] - tags_of_project = self._kili_api_gateway.list_tags_by_project(project_id, fields=("id",)) + tags_of_project = self.kili_api_gateway.list_tags_by_project(project_id, fields=("id",)) tags_of_project_ids = [tag["id"] for tag in tags_of_project] ret_tags = [] @@ -46,7 +42,7 @@ def tag_project( ret_tags.append(tag_id) else: ret_tags.append( - self._kili_api_gateway.check_tag(project_id=project_id, tag_id=tag_id) + self.kili_api_gateway.check_tag(project_id=project_id, tag_id=tag_id) ) return ret_tags @@ -60,7 +56,7 @@ def untag_project( """Remove tags from a project.""" tag_ids_of_project = { tag["id"] - for tag in self._kili_api_gateway.list_tags_by_project( + for tag in self.kili_api_gateway.list_tags_by_project( project_id=ProjectId(project_id), fields=("id",) ) } @@ -72,7 +68,7 @@ def untag_project( ) return [ - self._kili_api_gateway.uncheck_tag( + self.kili_api_gateway.uncheck_tag( project_id=ProjectId(project_id), tag_id=TagId(tag_id) ) for tag_id in tqdm(tag_ids, desc="Untagging project", disable=disable_tqdm) @@ -80,7 +76,7 @@ def untag_project( def get_tag_ids_from_labels(self, labels: ListOrTuple[str]) -> List[TagId]: """Get tag ids from labels.""" - tags_of_orga = self._kili_api_gateway.list_tags_by_org(fields=("id", "label")) + tags_of_orga = self.kili_api_gateway.list_tags_by_org(fields=("id", "label")) tag_label_to_id = defaultdict(list) for tag in tags_of_orga: @@ -114,7 +110,7 @@ def update_tag(self, tag_id: TagId, new_tag_name: str) -> UpdateTagReturnData: Returns: The updated tag. """ - return self._kili_api_gateway.update_tag(tag_id=tag_id, label=new_tag_name) + return self.kili_api_gateway.update_tag(tag_id=tag_id, label=new_tag_name) def delete_tag(self, tag_id: TagId) -> bool: """Delete the given tag. @@ -129,4 +125,4 @@ def delete_tag(self, tag_id: TagId) -> bool: Returns: Whether the tag was successfully removed. """ - return self._kili_api_gateway.delete_tag(tag_id=tag_id) + return self.kili_api_gateway.delete_tag(tag_id=tag_id)