Skip to content

Commit

Permalink
fix: take comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreLeveau committed Sep 28, 2023
1 parent 243d949 commit a0d7712
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/kili/entrypoints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions src/kili/use_cases/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
)
)
Expand All @@ -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)
9 changes: 4 additions & 5 deletions src/kili/use_cases/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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),
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/kili/use_cases/question/question_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down
24 changes: 10 additions & 14 deletions src/kili/use_cases/tag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand All @@ -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
Expand All @@ -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",)
)
}
Expand All @@ -72,15 +68,15 @@ 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)
]

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:
Expand Down Expand Up @@ -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.
Expand All @@ -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)

0 comments on commit a0d7712

Please sign in to comment.