Skip to content

Commit

Permalink
annofabapi v0.64.0に対応する (#892)
Browse files Browse the repository at this point in the history
* poetry update

* 対応

* dataclassの変更

* format

* put_annotationの引数指定

* version up
  • Loading branch information
yuji38kwmt authored Nov 2, 2022
1 parent 8a15dd3 commit 55e750c
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 142 deletions.
2 changes: 1 addition & 1 deletion annofabcli/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.73.1"
__version__ = "1.73.2"
16 changes: 8 additions & 8 deletions annofabcli/annotation/annotation_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from typing import Any, Dict, List, Optional, Union

import more_itertools
from annofabapi.dataclass.annotation import AdditionalData
from annofabapi.dataclass.annotation import AdditionalDataV1
from annofabapi.models import AdditionalDataDefinitionType
from annofabapi.utils import get_message_for_i18n
from dataclasses_json import DataClassJsonMixin

AttributeValue = Optional[Union[str, int, bool]]


def _get_attribute_to_api(additional_data: dict[str, Any], attribute_value: AttributeValue) -> AdditionalData:
def _get_attribute_to_api(additional_data: dict[str, Any], attribute_value: AttributeValue) -> AdditionalDataV1:
"""API用の属性情報を取得する。
Args:
Expand All @@ -34,7 +34,7 @@ def get_attribute_name(additional_data: dict[str, Any]) -> str:
"additional_data_definition_id": additional_data_definition_id,
}
if attribute_value is None:
return AdditionalData.from_dict(result, infer_missing=True)
return AdditionalDataV1.from_dict(result, infer_missing=True)

additional_data_type: str = additional_data["type"]
if additional_data_type == AdditionalDataDefinitionType.FLAG.value:
Expand Down Expand Up @@ -75,12 +75,12 @@ def get_attribute_name(additional_data: dict[str, Any]) -> str:
choice_info = tmp[0]
result["choice"] = choice_info["choice_id"]

return AdditionalData.from_dict(result, infer_missing=True)
return AdditionalDataV1.from_dict(result, infer_missing=True)


def convert_attributes_from_cli_to_api(
attributes: dict[str, AttributeValue], annotation_specs: dict[str, Any], label_id: Optional[str] = None
) -> list[AdditionalData]:
) -> list[AdditionalDataV1]:
"""
CLI用の属性をAPI用の属性に変換します。
Expand Down Expand Up @@ -113,7 +113,7 @@ def get_label_name(label_info: dict[str, Any]) -> str:
if e["additional_data_definition_id"] in tmp_additional_data_definition_ids
]

attributes_for_webapi: list[AdditionalData] = []
attributes_for_webapi: list[AdditionalDataV1] = []
for attribute_name, attribute_value in attributes.items():
additional_data = more_itertools.first_true(
tmp_additionals,
Expand Down Expand Up @@ -154,7 +154,7 @@ class AnnotationQueryForCLI(DataClassJsonMixin):
label: str
"""ラベル名(英語)"""

# attributes: Optional[List[AdditionalData]] = None
# attributes: Optional[List[AdditionalDataV1]] = None
attributes: Optional[Dict[str, AttributeValue]] = None
"""
keyが属性名(英語),valueが属性値のdict。
Expand Down Expand Up @@ -198,5 +198,5 @@ class AnnotationQueryForAPI(DataClassJsonMixin):
label_id: str
"""ラベルID"""

attributes: Optional[List[AdditionalData]] = None
attributes: Optional[List[AdditionalDataV1]] = None
"""属性IDと属性値のList"""
12 changes: 6 additions & 6 deletions annofabcli/annotation/change_annotation_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from typing import Any, Dict, List, Optional

import annofabapi
from annofabapi.dataclass.annotation import AdditionalDataV1
from annofabapi.dataclass.task import Task
from annofabapi.models import ProjectMemberRole, TaskStatus

import annofabcli
from annofabcli.annotation.annotation_query import (
AdditionalData,
AnnotationQueryForAPI,
AnnotationQueryForCLI,
convert_attributes_from_cli_to_api,
Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(
self.dump_annotation_obj = DumpAnnotationMain(service, project_id)

def change_annotation_attributes(
self, annotation_list: List[Dict[str, Any]], attributes: List[AdditionalData]
self, annotation_list: List[Dict[str, Any]], attributes: List[AdditionalDataV1]
) -> Optional[List[Dict[str, Any]]]:
"""
アノテーション属性値を変更する。
Expand Down Expand Up @@ -117,7 +117,7 @@ def change_attributes_for_task(
self,
task_id: str,
annotation_query: AnnotationQueryForAPI,
attributes: List[AdditionalData],
attributes: List[AdditionalDataV1],
backup_dir: Optional[Path] = None,
task_index: Optional[int] = None,
) -> bool:
Expand Down Expand Up @@ -173,7 +173,7 @@ def change_attributes_for_task_wrapper(
self,
tpl: tuple[int, str],
annotation_query: AnnotationQueryForAPI,
attributes: List[AdditionalData],
attributes: List[AdditionalDataV1],
backup_dir: Optional[Path] = None,
) -> bool:
task_index, task_id = tpl
Expand All @@ -193,7 +193,7 @@ def change_annotation_attributes_for_task_list(
self,
task_id_list: List[str],
annotation_query: AnnotationQueryForAPI,
attributes: List[AdditionalData],
attributes: List[AdditionalDataV1],
backup_dir: Optional[Path] = None,
parallelism: Optional[int] = None,
):
Expand Down Expand Up @@ -267,7 +267,7 @@ def get_annotation_query_for_api(
@classmethod
def get_attributes_for_api(
cls, str_attributes: str, annotation_specs: dict[str, Any], label_id: str
) -> list[AdditionalData]:
) -> list[AdditionalDataV1]:
"""
CLIから受け取った`--attributes`の値から、APIに渡す属性情報を返す。
"""
Expand Down
2 changes: 1 addition & 1 deletion annofabcli/annotation/change_annotation_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _to_request_body_elm(annotation: Dict[str, Any]):
annotation["project_id"],
annotation["task_id"],
annotation["input_data_id"],
{
request_body={
"project_id": annotation["project_id"],
"task_id": annotation["task_id"],
"input_data_id": annotation["input_data_id"],
Expand Down
12 changes: 6 additions & 6 deletions annofabcli/annotation/import_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import Any, Dict, Iterator, List, Optional, Union

import annofabapi
from annofabapi.dataclass.annotation import AdditionalData, AnnotationDetail
from annofabapi.dataclass.annotation import AdditionalDataV1, AnnotationDetailV1
from annofabapi.models import (
AdditionalDataDefinitionType,
AdditionalDataDefinitionV1,
Expand Down Expand Up @@ -161,15 +161,15 @@ def _get_data_holding_type_from_data(cls, label_info: Dict[str, Any]) -> Annotat
return AnnotationDataHoldingType.OUTER
return AnnotationDataHoldingType.INNER

def _to_additional_data_list(self, attributes: Dict[str, Any], label_info: LabelV1) -> List[AdditionalData]:
additional_data_list: List[AdditionalData] = []
def _to_additional_data_list(self, attributes: Dict[str, Any], label_info: LabelV1) -> List[AdditionalDataV1]:
additional_data_list: List[AdditionalDataV1] = []
for key, value in attributes.items():
specs_additional_data = self._get_additional_data_from_attribute_name(key, label_info)
if specs_additional_data is None:
logger.warning(f"アノテーション仕様に attribute_name={key} が存在しません。")
continue

additional_data = AdditionalData(
additional_data = AdditionalDataV1(
additional_data_definition_id=specs_additional_data["additional_data_definition_id"],
flag=None,
integer=None,
Expand Down Expand Up @@ -200,7 +200,7 @@ def _to_additional_data_list(self, attributes: Dict[str, Any], label_info: Label

def _to_annotation_detail_for_request(
self, parser: SimpleAnnotationParser, detail: ImportedSimpleAnnotationDetail, now_datetime: str
) -> Optional[AnnotationDetail]:
) -> Optional[AnnotationDetailV1]:
"""
Request Bodyに渡すDataClassに変換する。塗りつぶし画像があれば、それをS3にアップロードする。
Expand Down Expand Up @@ -233,7 +233,7 @@ def _get_annotation_id(arg_label_info: LabelV1) -> str:

data_holding_type = self._get_data_holding_type_from_data(label_info)

dest_obj = AnnotationDetail(
dest_obj = AnnotationDetailV1(
label_id=label_info["label_id"],
annotation_id=_get_annotation_id(label_info),
account_id=self.service.api.account_id,
Expand Down
10 changes: 5 additions & 5 deletions annofabcli/annotation/restore_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, Dict, Iterator, List, Optional

import annofabapi
from annofabapi.dataclass.annotation import Annotation, AnnotationDetail
from annofabapi.dataclass.annotation import AnnotationDetailV1, AnnotationV1
from annofabapi.models import AnnotationDataHoldingType, ProjectMemberRole, TaskStatus
from annofabapi.parser import (
SimpleAnnotationParser,
Expand Down Expand Up @@ -47,8 +47,8 @@ def __init__(
self.is_force = is_force

def _to_annotation_detail_for_request(
self, parser: SimpleAnnotationParser, detail: AnnotationDetail
) -> AnnotationDetail:
self, parser: SimpleAnnotationParser, detail: AnnotationDetailV1
) -> AnnotationDetailV1:
"""
Request Bodyに渡すDataClassに変換する。塗りつぶし画像があれば、それをS3にアップロードする。
Expand All @@ -75,9 +75,9 @@ def _to_annotation_detail_for_request(
return detail

def parser_to_request_body(self, parser: SimpleAnnotationParser) -> Dict[str, Any]:
# infer_missing=Trueを指定する理由:Optional型のキーが存在しない場合でも、Annotationデータクラスのインスタンスを生成できるようにするため
# infer_missing=Trueを指定する理由:Optional型のキーが存在しない場合でも、AnnotationV1データクラスのインスタンスを生成できるようにするため
# https://qiita.com/yuji38kwmt/items/c5b56f70da3b8a70ba31
annotation: Annotation = Annotation.from_dict(parser.load_json(), infer_missing=True)
annotation: AnnotationV1 = AnnotationV1.from_dict(parser.load_json(), infer_missing=True)
request_details: List[Dict[str, Any]] = []
for detail in annotation.details:
request_detail = self._to_annotation_detail_for_request(parser, detail)
Expand Down
4 changes: 2 additions & 2 deletions annofabcli/common/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import annofabapi
import annofabapi.utils
import more_itertools
from annofabapi.dataclass.annotation import AdditionalData
from annofabapi.dataclass.annotation import AdditionalDataV1
from annofabapi.dataclass.input import InputData
from annofabapi.dataclass.task import Task
from annofabapi.models import (
Expand All @@ -30,7 +30,7 @@ class AnnotationQuery(DataClassJsonMixin):
"""

label_id: str
attributes: Optional[List[AdditionalData]] = None
attributes: Optional[List[AdditionalDataV1]] = None


@dataclass
Expand Down
Loading

0 comments on commit 55e750c

Please sign in to comment.