diff --git a/Pipfile.lock b/Pipfile.lock index ac930d0f..8d91b397 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -17,10 +17,10 @@ "develop": { "annofabapi": { "hashes": [ - "sha256:31b192d5d8f3c75a72120843fc53012b3e91d4d9244a4c26a4da596b86c1b4e5", - "sha256:49735827ac05ed464b56912653525b205fcbcb4fac74027da3a7083f3c1fc2db" + "sha256:0a0685256cbf0e208781c150758f8d32bb3577551ebcd9dcec71ed8efe3c84fa", + "sha256:9c39dd356b36d7c8653e854e6a1788059ade40e229bfe48f371a3af547cacdeb" ], - "version": "==0.25.0" + "version": "==0.25.2" }, "annofabcli": { "editable": true, @@ -848,10 +848,10 @@ }, "zipp": { "hashes": [ - "sha256:57147f6b0403b59f33fd357f169f860e031303415aeb7d04ede4839d23905ab8", - "sha256:7ae5ccaca427bafa9760ac3cd8f8c244bfc259794b5b6bb9db4dda2241575d09" + "sha256:b338014b9bc7102ca69e0fb96ed07215a8954d2989bc5d83658494ab2ba634af", + "sha256:e013e7800f60ec4dde789ebf4e9f7a54236e4bbf5df2a1a4e20ce9e1d9609d67" ], - "version": "==2.0.0" + "version": "==2.0.1" } } } diff --git a/annofabcli/__main__.py b/annofabcli/__main__.py index 72614547..2eb5fc8b 100644 --- a/annofabcli/__main__.py +++ b/annofabcli/__main__.py @@ -47,9 +47,9 @@ def main(arguments: Optional[Sequence[str]] = None): annofabcli.organization_member.subcommand_organization_member.add_parser(subparsers) annofabcli.project.subcommand_project.add_parser(subparsers) annofabcli.project_member.subcommand_project_member.add_parser(subparsers) - annofabcli.task.subcommand_task.add_parser(subparsers) annofabcli.statistics.subcommand_statistics.add_parser(subparsers) annofabcli.supplementary.subcommand_supplementary.add_parser(subparsers) + annofabcli.task.subcommand_task.add_parser(subparsers) annofabcli.filesystem.subcommand_filesystem.add_parser(subparsers) annofabcli.experimental.subcommand_experimental.add_parser(subparsers) @@ -61,6 +61,7 @@ def main(arguments: Optional[Sequence[str]] = None): if hasattr(args, "subcommand_func"): try: + annofabcli.cli.load_logging_config_from_args(args) args.subcommand_func(args) except Exception as e: logger.exception(e) diff --git a/annofabcli/__version__.py b/annofabcli/__version__.py index 4bd6f7be..d84d79d4 100644 --- a/annofabcli/__version__.py +++ b/annofabcli/__version__.py @@ -1 +1 @@ -__version__ = "1.18.2" +__version__ = "1.19.0" diff --git a/annofabcli/annotation/list_annotation_count.py b/annofabcli/annotation/list_annotation_count.py index dd24faac..cc0f037d 100644 --- a/annofabcli/annotation/list_annotation_count.py +++ b/annofabcli/annotation/list_annotation_count.py @@ -211,7 +211,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListAnnotationCount(service, facade, args).main() diff --git a/annofabcli/annotation/subcommand_annotation.py b/annofabcli/annotation/subcommand_annotation.py index 65aa763a..5bf45776 100644 --- a/annofabcli/annotation/subcommand_annotation.py +++ b/annofabcli/annotation/subcommand_annotation.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "アノテーション関係のサブコマンド" description = "アノテーション関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/annotation_specs/list_annotation_specs_history.py b/annofabcli/annotation_specs/list_annotation_specs_history.py index 596af68e..b1fbab56 100644 --- a/annofabcli/annotation_specs/list_annotation_specs_history.py +++ b/annofabcli/annotation_specs/list_annotation_specs_history.py @@ -38,7 +38,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) AnnotationSpecsHistories(service, facade, args).main() diff --git a/annofabcli/annotation_specs/list_annotation_specs_label.py b/annofabcli/annotation_specs/list_annotation_specs_label.py index 32501b31..1204807c 100644 --- a/annofabcli/annotation_specs/list_annotation_specs_label.py +++ b/annofabcli/annotation_specs/list_annotation_specs_label.py @@ -160,7 +160,7 @@ def parse_args(parser: argparse.ArgumentParser): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) PrintAnnotationSpecsLabel(service, facade, args).main() diff --git a/annofabcli/annotation_specs/print_label_color.py b/annofabcli/annotation_specs/print_label_color.py index 771850f2..9923b968 100644 --- a/annofabcli/annotation_specs/print_label_color.py +++ b/annofabcli/annotation_specs/print_label_color.py @@ -66,7 +66,7 @@ def parse_args(parser: argparse.ArgumentParser): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) PrintLabelColor(service, facade, args).main() diff --git a/annofabcli/annotation_specs/subcommand_annotation_specs.py b/annofabcli/annotation_specs/subcommand_annotation_specs.py index f81a4133..4950bc53 100644 --- a/annofabcli/annotation_specs/subcommand_annotation_specs.py +++ b/annofabcli/annotation_specs/subcommand_annotation_specs.py @@ -22,5 +22,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "アノテーション仕様関係のサブコマンド" description = "アノテーション仕様関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/common/cli.py b/annofabcli/common/cli.py index fb8624cc..a06773a2 100644 --- a/annofabcli/common/cli.py +++ b/annofabcli/common/cli.py @@ -8,12 +8,14 @@ import getpass import json import logging +import os from typing import Any, Dict, List, Optional, Tuple import annofabapi import jmespath import pandas import requests +from annofabapi.api import DEFAULT_ENDPOINT_URL from annofabapi.exceptions import AnnofabApiException from annofabapi.models import OrganizationMemberRole, ProjectMemberRole @@ -27,16 +29,19 @@ logger = logging.getLogger(__name__) -def build_annofabapi_resource_and_login() -> annofabapi.Resource: +def build_annofabapi_resource_and_login(args: argparse.Namespace) -> annofabapi.Resource: """ - annofabapi.Resourceインスタンスを生成する。 + annofabapi.Resourceインスタンスを生成したあと、ログインする。 + + Args: + args: コマンドライン引数の情報 Returns: annofabapi.Resourceインスタンス """ - service = build_annofabapi_resource() + service = build_annofabapi_resource(args) try: service.api.login() @@ -50,9 +55,10 @@ def build_annofabapi_resource_and_login() -> annofabapi.Resource: def add_parser( subparsers: argparse._SubParsersAction, - subcommand_name: str, - subcommand_help: str, + command_name: str, + command_help: str, description: str, + is_subcommand: bool = True, epilog: Optional[str] = None, ) -> argparse.ArgumentParser: """ @@ -60,17 +66,19 @@ def add_parser( Args: subparsers: - subcommand_name: - subcommand_help: - description: - epilog: + command_name: + command_help: 1階層上のコマンドヘルプに表示される コマンドの説明(簡易的な説明) + description: ヘルプ出力に表示される説明(詳細な説明) + is_subcommand: サブコマンドかどうか. `annofabcli project`はコマンド、`annofabcli project list`はサブコマンドとみなす。 + epilog: ヘルプ出力後に表示される内容。デフォルトはNoneです。 Returns: サブコマンドのparser """ + parents = [create_parent_parser()] if is_subcommand else [] parser = subparsers.add_parser( - subcommand_name, parents=[create_parent_parser()], description=description, help=subcommand_help, epilog=epilog + command_name, parents=parents, description=description, help=command_help, epilog=epilog ) parser.set_defaults(command_help=parser.print_help) return parser @@ -85,6 +93,19 @@ def create_parent_parser() -> argparse.ArgumentParser: group.add_argument("--yes", action="store_true", help="処理中に現れる問い合わせに対して、常に'yes'と回答します。") + # EXAMPLE_CREDENTAILS = '{"user_id": "test_user", "password": "test_password"}' + # group.add_argument( + # "--credentials", + # type=str, + # help=f"AnnoFabにログインするユーザの認証情報をJSON形式で指定します。" + # f"(ex) `{EXAMPLE_CREDENTAILS}` ." + # f"`file://`を先頭に付けると、JSON形式のファイルを指定できます。", + # ) + + group.add_argument( + "--endpoint_url", type=str, help=f"AnnoFab WebAPIのエンドポイントを指定します。指定しない場合は'{DEFAULT_ENDPOINT_URL}'です。" + ) + group.add_argument( "--logdir", type=str, default=".log", help="ログファイルを保存するディレクトリを指定します。指定しない場合は`.log`ディレクトリ'にログファイルが保存されます。" ) @@ -182,21 +203,56 @@ def get_wait_options_from_args( return default_wait_options -def load_logging_config_from_args(args: argparse.Namespace): +def load_logging_config_from_args(args: argparse.Namespace) -> None: """ - args情報から、logging設定ファイルを読み込む + args情報から、logging設定ファイルを読み込む. + 以下のコマンドライン引数からlogging設定ファイルを読み込む。 + ``--disable_log`` が指定されている場合は、loggerを設定しない。 + + * --logdir + * --disable_log + * --logging_yaml + Args: args: Command引数情報 """ - log_dir = args.logdir - logging_yaml_file = args.logging_yaml if hasattr(args, "logging_yaml") else None - annofabcli.utils.load_logging_config(log_dir, logging_yaml_file) + if args.disable_log: + return + + annofabcli.utils.load_logging_config(args.logdir, args.logging_yaml) + + +def get_endpoint_url(args: argparse.Namespace) -> str: + """ + AnnoFab WebAPIのエンドポイントURLを、以下の優先順位で取得する。 + + 1. コマンドライン引数 ``--endpoint_url`` + 2. 環境変数 ``ANNOFAB_ENDPOINT_URL`` + + 取得できない場合は、デフォルトの ``https://annofab.com`` を返す。 + Args: + args: コマンドライン引数情報 + + Returns: + AnnoFab WebAPIのエンドポイントURL -def build_annofabapi_resource() -> annofabapi.Resource: """ - annofabapi.Resourceインスタナスを生成する。 + endpoint_url = args.endpoint_url + if endpoint_url is not None: + return endpoint_url + + endpoint_url = os.environ.get("ANNOFAB_ENDPOINT_URL") + if endpoint_url is not None: + return endpoint_url + + return DEFAULT_ENDPOINT_URL + + +def build_annofabapi_resource(args: argparse.Namespace) -> annofabapi.Resource: + """ + annofabapi.Resourceインスタンスを生成する。 以下の順にAnnoFabの認証情報を読み込む。 1. `.netrc`ファイル 2. 環境変数`ANNOFAB_USER_ID` , `ANNOFAB_PASSWORD` @@ -207,16 +263,28 @@ def build_annofabapi_resource() -> annofabapi.Resource: annofabapi.Resourceインスタンス """ - + endpoint_url = get_endpoint_url(args) + if endpoint_url != DEFAULT_ENDPOINT_URL: + logger.info(f"AnnoFab WebAPIのエンドポイントURL: {endpoint_url}") + + # # コマンドライン引数から認証情報を取得する + # dict_credentials = annofabcli.common.cli.get_json_from_args(args.credentials) + # if dict_credentials is not None: + # return annofabapi.build( + # dict_credentials.get("user_id"), dict_credentials.get("password"), endpoint_url=endpoint_url + # ) + + # '.netrc'ファイルから認証情報を取得する try: - return annofabapi.build_from_netrc() + return annofabapi.build_from_netrc(endpoint_url) except AnnofabApiException: - logger.info("`.netrc`ファイルにはAnnoFab認証情報が存在しなかった") + logger.debug("`.netrc`ファイルにはAnnoFab認証情報が存在しなかった") + # 環境変数から認証情報を取得する try: - return annofabapi.build_from_env() + return annofabapi.build_from_env(endpoint_url) except AnnofabApiException: - logger.info("`環境変数`ANNOFAB_USER_ID` or `ANNOFAB_PASSWORD`が空だった") + logger.debug("`環境変数`ANNOFAB_USER_ID` or `ANNOFAB_PASSWORD`が空だった") # 標準入力から入力させる login_user_id = "" @@ -227,7 +295,7 @@ def build_annofabapi_resource() -> annofabapi.Resource: while login_password == "": login_password = getpass.getpass("Enter AnnoFab Password: ") - return annofabapi.build(login_user_id, login_password) + return annofabapi.build(login_user_id, login_password, endpoint_url=endpoint_url) def prompt_yesno(msg: str) -> bool: @@ -387,9 +455,6 @@ def process_common_args(self, args: argparse.Namespace): Args: args: コマンドライン引数 """ - if not args.disable_log: - load_logging_config_from_args(args) - self.all_yes = args.yes if hasattr(args, "query"): self.query = args.query diff --git a/annofabcli/common/utils.py b/annofabcli/common/utils.py index 6dd4936a..5ca39507 100644 --- a/annofabcli/common/utils.py +++ b/annofabcli/common/utils.py @@ -45,7 +45,6 @@ def load_logging_config(log_dir: str, logging_yaml_file: Optional[str] = None): Args: log_dir: ログの出力先 - log_filename: ログのファイル名 logging_yaml_file: ログ設定ファイル。指定しない場合、`data/logging.yaml`を読み込む. 指定した場合、log_dir, log_filenameは無視する。 """ diff --git a/annofabcli/deprecated_register_annotation_from_full_zip.py b/annofabcli/deprecated_register_annotation_from_full_zip.py index c266ca8b..28a9c011 100644 --- a/annofabcli/deprecated_register_annotation_from_full_zip.py +++ b/annofabcli/deprecated_register_annotation_from_full_zip.py @@ -351,7 +351,7 @@ def parse_args(parser: argparse.ArgumentParser): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) RegisterAnnotation(service, facade).main(args) diff --git a/annofabcli/experimental/find_break_error.py b/annofabcli/experimental/find_break_error.py index ef42e31f..de23c4e2 100644 --- a/annofabcli/experimental/find_break_error.py +++ b/annofabcli/experimental/find_break_error.py @@ -215,7 +215,7 @@ def _timedelta_to_HM(td: datetime.timedelta): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) FindBreakError(service, facade, args).main() diff --git a/annofabcli/experimental/list_labor_worktime.py b/annofabcli/experimental/list_labor_worktime.py index 287adbff..2e991f16 100644 --- a/annofabcli/experimental/list_labor_worktime.py +++ b/annofabcli/experimental/list_labor_worktime.py @@ -207,7 +207,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListLaborWorktime(service, facade, args).main() diff --git a/annofabcli/experimental/subcommand_experimental.py b/annofabcli/experimental/subcommand_experimental.py index 8dc8c51d..a1296cf0 100644 --- a/annofabcli/experimental/subcommand_experimental.py +++ b/annofabcli/experimental/subcommand_experimental.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "アルファ版のサブコマンド" description = "アルファ版のサブコマンド。予告なしに削除されたり、コマンドライン引数が変わったりします。" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/filesystem/subcommand_filesystem.py b/annofabcli/filesystem/subcommand_filesystem.py index 8a71f93d..a8fd73d5 100644 --- a/annofabcli/filesystem/subcommand_filesystem.py +++ b/annofabcli/filesystem/subcommand_filesystem.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "ファイル操作関係(Web APIにアクセスしない)のサブコマンド" description = "ファイル操作関係(Web APIにアクセスしない)のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/filesystem/write_annotation_image.py b/annofabcli/filesystem/write_annotation_image.py index ac3ad108..6b34d1cd 100644 --- a/annofabcli/filesystem/write_annotation_image.py +++ b/annofabcli/filesystem/write_annotation_image.py @@ -48,7 +48,6 @@ def is_target_parser(parser: SimpleAnnotationParser) -> bool: return is_target_parser def main(self, args): - annofabcli.common.cli.load_logging_config_from_args(args) logger.info(f"args: {args}") image_size = annofabcli.common.cli.get_input_data_size(args.image_size) diff --git a/annofabcli/input_data/delete_input_data.py b/annofabcli/input_data/delete_input_data.py index 7c8d3bee..6d8e5637 100644 --- a/annofabcli/input_data/delete_input_data.py +++ b/annofabcli/input_data/delete_input_data.py @@ -82,7 +82,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) DeleteInputData(service, facade, args).main() diff --git a/annofabcli/input_data/list_input_data.py b/annofabcli/input_data/list_input_data.py index 37d53d50..792e7601 100644 --- a/annofabcli/input_data/list_input_data.py +++ b/annofabcli/input_data/list_input_data.py @@ -292,7 +292,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListInputData(service, facade, args).main() @@ -328,7 +328,8 @@ def parse_args(parser: argparse.ArgumentParser): type=str, help="段階的に入力データを取得するための情報をJSON形式で指定します。 " '(ex) `{"first":"2019-01-01", "last":"2019-01-31", "days":7}` ' - "このオプションを駆使すれば、10,000件以上のデータを取得できます。", + "このオプションを駆使すれば、10,000件以上のデータを取得できます。" + "`file://`を先頭に付けると、JSON形式のファイルを指定できます。", ) parser.add_argument("--add_details", action="store_true", help="入力データの詳細情報を表示します(`parent_task_id_list`)") diff --git a/annofabcli/input_data/put_input_data.py b/annofabcli/input_data/put_input_data.py index 7330178a..1889a63f 100644 --- a/annofabcli/input_data/put_input_data.py +++ b/annofabcli/input_data/put_input_data.py @@ -343,7 +343,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) PutInputData(service, facade, args).main() diff --git a/annofabcli/input_data/subcommand_input_data.py b/annofabcli/input_data/subcommand_input_data.py index 99c3312a..b19b66b5 100644 --- a/annofabcli/input_data/subcommand_input_data.py +++ b/annofabcli/input_data/subcommand_input_data.py @@ -22,5 +22,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "入力データ関係のサブコマンド" description = "入力データ関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/inspection_comment/list_inspections.py b/annofabcli/inspection_comment/list_inspections.py index 9ec180df..68ec3707 100644 --- a/annofabcli/inspection_comment/list_inspections.py +++ b/annofabcli/inspection_comment/list_inspections.py @@ -214,7 +214,7 @@ def parse_args(parser: argparse.ArgumentParser): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) PrintInspections(service, facade, args).main() diff --git a/annofabcli/inspection_comment/list_unprocessed_inspections.py b/annofabcli/inspection_comment/list_unprocessed_inspections.py index da9cd2da..52b35a69 100644 --- a/annofabcli/inspection_comment/list_unprocessed_inspections.py +++ b/annofabcli/inspection_comment/list_unprocessed_inspections.py @@ -90,7 +90,7 @@ def validate(args: argparse.Namespace): def main(args: argparse.Namespace): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) if not validate(args): diff --git a/annofabcli/inspection_comment/subcommand_inspection_comment.py b/annofabcli/inspection_comment/subcommand_inspection_comment.py index 042299b6..f5f210ac 100644 --- a/annofabcli/inspection_comment/subcommand_inspection_comment.py +++ b/annofabcli/inspection_comment/subcommand_inspection_comment.py @@ -20,5 +20,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "検査コメント関係のサブコマンド" description = "検査コメント関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/instruction/subcommand_instruction.py b/annofabcli/instruction/subcommand_instruction.py index 3935d7b2..81825bf8 100644 --- a/annofabcli/instruction/subcommand_instruction.py +++ b/annofabcli/instruction/subcommand_instruction.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "作業ガイド関係のサブコマンド" description = "作業ガイド関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/instruction/upload_instruction.py b/annofabcli/instruction/upload_instruction.py index 61fac23e..20ebef78 100644 --- a/annofabcli/instruction/upload_instruction.py +++ b/annofabcli/instruction/upload_instruction.py @@ -69,7 +69,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) UploadInstruction(service, facade, args).main() diff --git a/annofabcli/job/list_job.py b/annofabcli/job/list_job.py index 900f2fbb..dc1b8ce2 100644 --- a/annofabcli/job/list_job.py +++ b/annofabcli/job/list_job.py @@ -61,7 +61,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListJob(service, facade, args).main() diff --git a/annofabcli/job/list_last_job.py b/annofabcli/job/list_last_job.py index 40af462c..4339ab40 100644 --- a/annofabcli/job/list_last_job.py +++ b/annofabcli/job/list_last_job.py @@ -129,7 +129,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListLastJob(service, facade, args).main() diff --git a/annofabcli/job/subcommand_job.py b/annofabcli/job/subcommand_job.py index 503b18cd..8ec26452 100644 --- a/annofabcli/job/subcommand_job.py +++ b/annofabcli/job/subcommand_job.py @@ -20,5 +20,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "ジョブ関係のサブコマンド" description = "ジョブ関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/labor/list_worktime_by_user.py b/annofabcli/labor/list_worktime_by_user.py index b3ab1cb4..dc2c307a 100644 --- a/annofabcli/labor/list_worktime_by_user.py +++ b/annofabcli/labor/list_worktime_by_user.py @@ -441,7 +441,7 @@ def main(self) -> None: def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListWorktimeByUser(service, facade, args).main() diff --git a/annofabcli/labor/subcommand_labor.py b/annofabcli/labor/subcommand_labor.py index c5ae9976..926a768d 100644 --- a/annofabcli/labor/subcommand_labor.py +++ b/annofabcli/labor/subcommand_labor.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "労務管理関係のサブコマンド" description = "労務管理関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/organization_member/list_organization_member.py b/annofabcli/organization_member/list_organization_member.py index d0701a27..fe475084 100644 --- a/annofabcli/organization_member/list_organization_member.py +++ b/annofabcli/organization_member/list_organization_member.py @@ -32,7 +32,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListOrganizationMember(service, facade, args).main() diff --git a/annofabcli/organization_member/subcommand_organization_member.py b/annofabcli/organization_member/subcommand_organization_member.py index b711724e..f57e20bc 100644 --- a/annofabcli/organization_member/subcommand_organization_member.py +++ b/annofabcli/organization_member/subcommand_organization_member.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "組織メンバ関係のサブコマンド" description = "組織メンバ関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/project/copy_project.py b/annofabcli/project/copy_project.py index 63652355..c89f676d 100644 --- a/annofabcli/project/copy_project.py +++ b/annofabcli/project/copy_project.py @@ -122,7 +122,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) CopyProject(service, facade, args).main() diff --git a/annofabcli/project/diff_projects.py b/annofabcli/project/diff_projects.py index af155a35..e7d40d68 100644 --- a/annofabcli/project/diff_projects.py +++ b/annofabcli/project/diff_projects.py @@ -409,7 +409,7 @@ def parse_args(parser: argparse.ArgumentParser): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) DiffProjecs(service, facade, args).main() diff --git a/annofabcli/project/download.py b/annofabcli/project/download.py index 1b25592e..bf3f2481 100644 --- a/annofabcli/project/download.py +++ b/annofabcli/project/download.py @@ -127,7 +127,7 @@ def main(self): def main(args: argparse.Namespace): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) Download(service, facade, args).main() diff --git a/annofabcli/project/list_project.py b/annofabcli/project/list_project.py index bb17c7d6..49532e46 100644 --- a/annofabcli/project/list_project.py +++ b/annofabcli/project/list_project.py @@ -116,7 +116,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListProject(service, facade, args).main() diff --git a/annofabcli/project/subcommand_project.py b/annofabcli/project/subcommand_project.py index d9c8ba07..a3d694b3 100644 --- a/annofabcli/project/subcommand_project.py +++ b/annofabcli/project/subcommand_project.py @@ -26,5 +26,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "プロジェクト関係のサブコマンド" description = "プロジェクト関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/project/update_annotation_zip.py b/annofabcli/project/update_annotation_zip.py index e684ae0f..d6399a5a 100644 --- a/annofabcli/project/update_annotation_zip.py +++ b/annofabcli/project/update_annotation_zip.py @@ -189,7 +189,7 @@ def main(self): def main(args: argparse.Namespace): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) UpdateAnnotationZip(service, facade, args).main() diff --git a/annofabcli/project_member/change_project_members.py b/annofabcli/project_member/change_project_members.py index 0b38ee84..6c3d9089 100644 --- a/annofabcli/project_member/change_project_members.py +++ b/annofabcli/project_member/change_project_members.py @@ -161,7 +161,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ChangeProjectMembers(service, facade, args).main() diff --git a/annofabcli/project_member/copy_project_members.py b/annofabcli/project_member/copy_project_members.py index 9e6113ce..1991d262 100644 --- a/annofabcli/project_member/copy_project_members.py +++ b/annofabcli/project_member/copy_project_members.py @@ -128,7 +128,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) CopyProjectMembers(service, facade, args).main() diff --git a/annofabcli/project_member/delete_users.py b/annofabcli/project_member/delete_users.py index 2bf6f4da..3137d759 100644 --- a/annofabcli/project_member/delete_users.py +++ b/annofabcli/project_member/delete_users.py @@ -74,7 +74,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) DeleteUser(service, facade, args).main() diff --git a/annofabcli/project_member/invite_users.py b/annofabcli/project_member/invite_users.py index 652ab68d..144c076b 100644 --- a/annofabcli/project_member/invite_users.py +++ b/annofabcli/project_member/invite_users.py @@ -78,7 +78,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) InviteUser(service, facade, args).main() diff --git a/annofabcli/project_member/list_users.py b/annofabcli/project_member/list_users.py index 83c570c4..f509a5d7 100644 --- a/annofabcli/project_member/list_users.py +++ b/annofabcli/project_member/list_users.py @@ -120,7 +120,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListUser(service, facade, args).main() diff --git a/annofabcli/project_member/put_project_members.py b/annofabcli/project_member/put_project_members.py index 5535940d..7c5c8b33 100644 --- a/annofabcli/project_member/put_project_members.py +++ b/annofabcli/project_member/put_project_members.py @@ -177,7 +177,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) PutProjectMembers(service, facade, args).main() diff --git a/annofabcli/project_member/subcommand_project_member.py b/annofabcli/project_member/subcommand_project_member.py index 14a22f2d..fc00b030 100644 --- a/annofabcli/project_member/subcommand_project_member.py +++ b/annofabcli/project_member/subcommand_project_member.py @@ -28,5 +28,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "プロジェクトメンバ関係のサブコマンド" description = "プロジェクトメンバ関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/statistics/subcommand_statistics.py b/annofabcli/statistics/subcommand_statistics.py index 457f7c89..0dd302b6 100644 --- a/annofabcli/statistics/subcommand_statistics.py +++ b/annofabcli/statistics/subcommand_statistics.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "統計関係のサブコマンド" description = "統計関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/statistics/visualize_statistics.py b/annofabcli/statistics/visualize_statistics.py index 6cc4fc79..5793cddd 100644 --- a/annofabcli/statistics/visualize_statistics.py +++ b/annofabcli/statistics/visualize_statistics.py @@ -170,7 +170,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) VisualizeStatistics(service, facade, args).main() @@ -234,5 +234,5 @@ def add_parser(subparsers: argparse._SubParsersAction): description = "統計情報を可視化したファイルを出力します。毎日 03:00JST頃に更新されます。" epilog = "チェッカーまたはオーナロールを持つユーザで実行してください。" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description, epilog) + parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description, epilog=epilog) parse_args(parser) diff --git a/annofabcli/supplementary/list_supplementary_data.py b/annofabcli/supplementary/list_supplementary_data.py index 8f76dadd..a3241ccb 100644 --- a/annofabcli/supplementary/list_supplementary_data.py +++ b/annofabcli/supplementary/list_supplementary_data.py @@ -60,7 +60,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListSupplementaryData(service, facade, args).main() diff --git a/annofabcli/supplementary/subcommand_supplementary.py b/annofabcli/supplementary/subcommand_supplementary.py index decbaa60..567ca300 100644 --- a/annofabcli/supplementary/subcommand_supplementary.py +++ b/annofabcli/supplementary/subcommand_supplementary.py @@ -18,5 +18,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "補助情報関係のサブコマンド" description = "補助情報関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/annofabcli/task/cancel_acceptance.py b/annofabcli/task/cancel_acceptance.py index 2d0af86c..8487f65e 100644 --- a/annofabcli/task/cancel_acceptance.py +++ b/annofabcli/task/cancel_acceptance.py @@ -75,7 +75,7 @@ def main(self): def main(args: argparse.Namespace): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) CancelAcceptance(service, facade, args).main() diff --git a/annofabcli/task/change_operator.py b/annofabcli/task/change_operator.py index f23f67fb..5600036c 100644 --- a/annofabcli/task/change_operator.py +++ b/annofabcli/task/change_operator.py @@ -107,7 +107,7 @@ def main(self): def main(args: argparse.Namespace): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ChangeOperator(service, facade, args).main() diff --git a/annofabcli/task/complete_tasks.py b/annofabcli/task/complete_tasks.py index 8682ec54..4478535e 100644 --- a/annofabcli/task/complete_tasks.py +++ b/annofabcli/task/complete_tasks.py @@ -197,7 +197,7 @@ def parse_args(parser: argparse.ArgumentParser): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ComleteTasks(service, facade, args).main() diff --git a/annofabcli/task/delete_tasks.py b/annofabcli/task/delete_tasks.py index 3d25ec3a..ffc7a12b 100644 --- a/annofabcli/task/delete_tasks.py +++ b/annofabcli/task/delete_tasks.py @@ -104,7 +104,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) DeleteTask(service, facade, args).main() diff --git a/annofabcli/task/list_tasks.py b/annofabcli/task/list_tasks.py index f5e3e9a1..25b2e6f6 100644 --- a/annofabcli/task/list_tasks.py +++ b/annofabcli/task/list_tasks.py @@ -180,7 +180,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) ListTasks(service, facade, args).main() diff --git a/annofabcli/task/put_tasks.py b/annofabcli/task/put_tasks.py index 5fe6148b..8ecb52a0 100644 --- a/annofabcli/task/put_tasks.py +++ b/annofabcli/task/put_tasks.py @@ -71,7 +71,7 @@ def main(self): def main(args): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) PutTask(service, facade, args).main() diff --git a/annofabcli/task/reject_tasks.py b/annofabcli/task/reject_tasks.py index c49064bf..fbd1f3c0 100644 --- a/annofabcli/task/reject_tasks.py +++ b/annofabcli/task/reject_tasks.py @@ -202,7 +202,7 @@ def main(self): def main(args: argparse.Namespace): - service = build_annofabapi_resource_and_login() + service = build_annofabapi_resource_and_login(args) facade = AnnofabApiFacade(service) RejectTasks(service, facade, args).main() diff --git a/annofabcli/task/subcommand_task.py b/annofabcli/task/subcommand_task.py index 8aef2b2e..a45e6fd1 100644 --- a/annofabcli/task/subcommand_task.py +++ b/annofabcli/task/subcommand_task.py @@ -30,5 +30,7 @@ def add_parser(subparsers: argparse._SubParsersAction): subcommand_help = "タスク関係のサブコマンド" description = "タスク関係のサブコマンド" - parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description) + parser = annofabcli.common.cli.add_parser( + subparsers, subcommand_name, subcommand_help, description, is_subcommand=False + ) parse_args(parser) diff --git a/setup.py b/setup.py index b83bdb81..61f023be 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ keywords="annofab api cli", url="https://github.com/kurusugawa-computer/annofab-cli", install_requires=[ - "annofabapi>=0.25.0", + "annofabapi>=0.25.2", "requests", "pillow", "pyyaml", diff --git a/tests/test_main.py b/tests/test_main.py index 469ba36e..cdddcbf5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -47,6 +47,10 @@ def test_annotation(self): class TestAnnotationSpecs: command_name = "annotation_specs" + def test_annotation_specs_histories(self): + out_file = str(out_path / "anotaton_specs_histories.csv") + main([self.command_name, "history", "--project_id", project_id, "--output", out_file]) + def test_annotation_specs_list_label(self): out_file = str(out_path / "anotation_specs_list_label.json") main([self.command_name, "list_label", "--project_id", project_id, "--output", out_file]) @@ -87,10 +91,6 @@ def test_annotation_specs_list_label_color(self): ] ) - def test_annotation_specs_histories(self): - out_file = str(out_path / "anotaton_specs_histories.csv") - main([self.command_name, "history", "--project_id", project_id, "--output", out_file]) - class TestFilesystem: def test_filesystem(self): @@ -453,6 +453,42 @@ def test_list_project_member(self): class TestTask: command_name = "task" + def test_cancel_acceptance(self): + main([self.command_name, "cancel_acceptance", "--project_id", project_id, "--task_id", task_id, "--yes"]) + + def test_change_operator(self): + # user指定 + main( + [ + self.command_name, + "change_operator", + "--project_id", + project_id, + "--task_id", + task_id, + "--user_id", + user_id, + "--yes", + ] + ) + + # 未割り当て + main( + [ + self.command_name, + "change_operator", + "--project_id", + project_id, + "--task_id", + task_id, + "--not_assign", + "--yes", + ] + ) + + def test_delete_task(self): + main([self.command_name, "delete", "--project_id", project_id, "--task_id", "not-exists-task", "--yes"]) + def test_list(self): out_file = str(out_path / "task.csv") main( @@ -489,12 +525,6 @@ def test_list_with_task_json(self): ] ) - def test_cancel_acceptance(self): - main([self.command_name, "cancel_acceptance", "--project_id", project_id, "--task_id", task_id, "--yes"]) - - def test_delete_task(self): - main([self.command_name, "delete", "--project_id", project_id, "--task_id", "not-exists-task", "--yes"]) - def test_reject_task(self): inspection_comment = datetime.datetime.now().isoformat() main( @@ -517,36 +547,6 @@ def test_put_task(self): [self.command_name, "put", "--project_id", project_id, "--csv", csv_file,] ) - def test_change_operator(self): - # user指定 - main( - [ - self.command_name, - "change_operator", - "--project_id", - project_id, - "--task_id", - task_id, - "--user_id", - user_id, - "--yes", - ] - ) - - # 未割り当て - main( - [ - self.command_name, - "change_operator", - "--project_id", - project_id, - "--task_id", - task_id, - "--not_assign", - "--yes", - ] - ) - # def test_complete_task(self): # main([ # self.command_name, 'complete', '--project_id', project_id, '--inspection_list', '--inspection_status', 'no_correction_required', '--yes'