Skip to content

Commit

Permalink
comment list --format jsonを指定したときにエラーが発生する不具合を修正 (#918)
Browse files Browse the repository at this point in the history
* `comment list`の不具合修正

* version

* 不具合修正

* format
  • Loading branch information
yuji38kwmt authored Dec 15, 2022
1 parent 290e918 commit 4f37adc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
11 changes: 8 additions & 3 deletions annofabcli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import argparse
import logging
import sys
from typing import Optional, Sequence
from typing import Optional

import annofabcli.annotation.subcommand_annotation
import annofabcli.annotation_specs.subcommand_annotation_specs
Expand All @@ -28,7 +30,7 @@
logger = logging.getLogger(__name__)


def main(arguments: Optional[Sequence[str]] = None):
def main(arguments: Optional[list[str]] = None):
"""
annofabcliコマンドのメイン処理
注意: `deprecated`なツールは、サブコマンド化しない。
Expand All @@ -47,7 +49,10 @@ def main(arguments: Optional[Sequence[str]] = None):
if hasattr(args, "subcommand_func"):
try:
annofabcli.common.cli.load_logging_config_from_args(args)
logger.info(f"sys.argv='{sys.argv}'")
argv = sys.argv
if arguments is not None:
argv = ["annofabcli"] + list(arguments)
logger.info(f"argv={argv}")
args.subcommand_func(args)
except Exception as e:
logger.exception(e)
Expand Down
2 changes: 1 addition & 1 deletion annofabcli/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.74.1"
__version__ = "1.74.2"
10 changes: 8 additions & 2 deletions annofabcli/comment/list_all_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from annofabcli.common.download import DownloadingFile
from annofabcli.common.enums import FormatArgument
from annofabcli.common.facade import AnnofabApiFacade
from annofabcli.common.utils import print_according_to_format, print_csv
from annofabcli.common.visualize import AddProps

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -86,8 +87,13 @@ def main(self):
)

logger.info(f"コメントの件数: {len(comment_list)}")
df = pandas.json_normalize(comment_list)
self.print_according_to_format(df)

output_format = FormatArgument(args.format)
if output_format == FormatArgument.CSV:
df = pandas.json_normalize(comment_list)
print_csv(df, output=args.output)
else:
print_according_to_format(comment_list, output_format, output=args.output)


def parse_args(parser: argparse.ArgumentParser):
Expand Down
27 changes: 19 additions & 8 deletions annofabcli/comment/list_comment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import argparse
import logging
from typing import List, Optional
from typing import Any, List, Optional

import pandas
import requests
Expand All @@ -11,6 +13,7 @@
from annofabcli.common.cli import AbstractCommandLineInterface, ArgumentParser, build_annofabapi_resource_and_login
from annofabcli.common.enums import FormatArgument
from annofabcli.common.facade import AnnofabApiFacade
from annofabcli.common.utils import print_according_to_format, print_csv
from annofabcli.common.visualize import AddProps

logger = logging.getLogger(__name__)
Expand All @@ -21,9 +24,9 @@ def get_comments(self, project_id: str, task_id: str, input_data_id: str):
comments, _ = self.service.api.get_comments(project_id, task_id, input_data_id, query_params={"v": "2"})
return comments

def list_comments(
def get_comment_list(
self, project_id: str, task_id_list: List[str], *, comment_type: Optional[CommentType], exclude_reply: bool
):
) -> list[dict[str, Any]]:
all_comments: List[Comment] = []

for task_id in task_id_list:
Expand All @@ -50,19 +53,27 @@ def list_comments(
except requests.HTTPError:
logger.warning(f"タスク task_id = {task_id} のコメントを取得できませんでした。", exc_info=True)

logger.info(f"コメントの件数: {len(all_comments)}")

visualize = AddProps(self.service, project_id)
all_comments = [visualize.add_properties_to_comment(e) for e in all_comments]
df = pandas.json_normalize(all_comments)
self.print_according_to_format(df)
return all_comments

def main(self):
args = self.args
task_id_list = annofabcli.common.cli.get_list_from_args(args.task_id)
comment_type = CommentType(args.comment_type) if args.comment_type is not None else None

self.list_comments(args.project_id, task_id_list, comment_type=comment_type, exclude_reply=args.exclude_reply)
comment_list = self.get_comment_list(
args.project_id, task_id_list, comment_type=comment_type, exclude_reply=args.exclude_reply
)

logger.info(f"コメントの件数: {len(comment_list)}")

output_format = FormatArgument(args.format)
if output_format == FormatArgument.CSV:
df = pandas.json_normalize(comment_list)
print_csv(df, output=args.output)
else:
print_according_to_format(comment_list, output_format, output=args.output)


def main(args: argparse.Namespace):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "annofabcli"
version = "1.74.1"
version = "1.74.2"
description = "Utility Command Line Interface for AnnoFab"
authors = ["yuji38kwmt"]
license = "MIT"
Expand Down

0 comments on commit 4f37adc

Please sign in to comment.