Skip to content

Commit 477485f

Browse files
authored
ジョブ関係のクラスの名前変更 (#327)
* update pyproject.toml * annofab v0.111.0 * devcontainer上でdockerが動かない問題の対応 * update dockerfile * update dataclass * update poetry * Jobtype -> projectJobtype * update swagger * update poetry * update wrapper * dowgrade jedi.ipythonバグを避けるため * JobInfoを追加 * get_all_project_jobのquery_paramsは必須でないので、デフォルト値をNoneにする * JobInfoを追加 * stacklevelを追加 * update test * 引数job_typeに対してProjectJobTypeとJobTypeの両方を利用できるようにする * jobtypeをProjectJobTypeに変更 * generate.shを修正 * update * version up * update poetry * 未使用のメソッドを削除 * poetry update * update readthedocs requirements.txt
1 parent 3c30dcd commit 477485f

23 files changed

+1117
-319
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ RUN set -x \
9191
# docker / docker-compose in devcontainer
9292
RUN set -x \
9393
&& mkdir -p /usr/local/devcontainer-tool/bin \
94-
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker https://raw.githubusercontent.com/thamaji/devcontainer-docker/main/docker \
94+
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker https://github.com/thamaji/devcontainer-docker/releases/download/v1.0.1/docker \
9595
&& chmod +x /usr/local/devcontainer-tool/bin/docker \
96-
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker-compose https://github.com/thamaji/devcontainer-compose/releases/download/v1.0.0/docker-compose \
96+
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker-compose https://github.com/thamaji/devcontainer-compose/releases/download/v1.0.2/docker-compose \
9797
&& chmod +x /usr/local/devcontainer-tool/bin/docker-compose
9898
ENV PATH=/usr/local/devcontainer-tool/bin:${PATH}
9999

100+
100101
# python3.8, make
101102
RUN set -x \
102103
&& apt-get update \

annofabapi/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.45.2"
1+
__version__ = "0.46.0"

annofabapi/_utils.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import enum
2+
import warnings
3+
from functools import wraps
4+
from typing import Optional
5+
6+
7+
def _issue_deprecated_warning_with_class(
8+
cls, stacklevel: int, deprecated_date: str, new_class_name: Optional[str] = None
9+
):
10+
"""非推奨なクラスに対する警告メッセージを出力する。"""
11+
old_class_name = f"{cls.__module__}.{cls.__name__}"
12+
message = f"deprecated: '{old_class_name}'は{deprecated_date}以降に廃止します。"
13+
if new_class_name is not None:
14+
message += f"替わりに'{new_class_name}'を使用してください。"
15+
warnings.warn(message, FutureWarning, stacklevel=stacklevel)
16+
17+
18+
def _process_class(cls, deprecated_date: str, new_class_name: Optional[str] = None):
19+
def decorator(function):
20+
@wraps(function)
21+
def wrapped(*args, **kwargs):
22+
_issue_deprecated_warning_with_class(
23+
cls, stacklevel=3, deprecated_date=deprecated_date, new_class_name=new_class_name
24+
)
25+
return function(*args, **kwargs)
26+
27+
return wrapped
28+
29+
cls.__init__ = decorator(cls.__init__) # type: ignore
30+
return cls
31+
32+
33+
def _process_enum_class(cls, deprecated_date: str, new_class_name: Optional[str] = None):
34+
def getattribute(self, name):
35+
_issue_deprecated_warning_with_class(
36+
cls, stacklevel=4, deprecated_date=deprecated_date, new_class_name=new_class_name
37+
)
38+
return super(type(self), self).__getattribute__(name)
39+
40+
cls.__getattribute__ = getattribute
41+
return cls
42+
43+
44+
def deprecated_class(_cls=None, *, deprecated_date: str, new_class_name: Optional[str] = None):
45+
"""クラスを非推奨にします。"""
46+
47+
def wrap(cls):
48+
if issubclass(cls, enum.Enum):
49+
return _process_enum_class(cls, deprecated_date=deprecated_date, new_class_name=new_class_name)
50+
else:
51+
return _process_class(cls, deprecated_date=deprecated_date, new_class_name=new_class_name)
52+
53+
if _cls is None:
54+
return wrap
55+
return wrap(_cls)

annofabapi/dataclass/inspection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class Inspection(DataClassJsonMixin):
5050
annotation_id: Optional[str]
5151
"""アノテーションID。[値の制約についてはこちら。](#section/API-Convention/APIID)<br> annotation_type が classification の場合は label_id と同じ値が格納されます。 """
5252

53+
label_id: Optional[str]
54+
""""""
55+
5356
data: InspectionData
5457
""""""
5558

annofabapi/dataclass/job.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,52 @@
1515

1616
from dataclasses_json import DataClassJsonMixin
1717

18-
from annofabapi.models import JobStatus, JobType
18+
from annofabapi._utils import deprecated_class
19+
from annofabapi.models import JobStatus, ProjectJobType
1920

2021

2122
@dataclass
22-
class JobInfo(DataClassJsonMixin):
23+
class ProjectJobInfo(DataClassJsonMixin):
2324
""" """
2425

2526
project_id: Optional[str]
2627
"""プロジェクトID。[値の制約についてはこちら。](#section/API-Convention/APIID) """
2728

28-
job_type: Optional[JobType]
29+
job_type: Optional[ProjectJobType]
30+
""""""
31+
32+
job_id: Optional[str]
33+
""""""
34+
35+
job_status: Optional[JobStatus]
36+
""""""
37+
38+
job_execution: Optional[Dict[str, Any]]
39+
"""ジョブの内部情報"""
40+
41+
job_detail: Optional[Dict[str, Any]]
42+
"""ジョブ結果の内部情報"""
43+
44+
created_datetime: Optional[str]
45+
""""""
46+
47+
updated_datetime: Optional[str]
48+
""""""
49+
50+
51+
# 2021-09-01以降に削除する予定
52+
@deprecated_class(deprecated_date="2021-09-01", new_class_name=f"{ProjectJobInfo.__module__}.{ProjectJobInfo.__name__}")
53+
@dataclass
54+
class JobInfo(DataClassJsonMixin):
55+
"""プロジェクトのジョブ情報
56+
57+
.. deprecated:: 2021-09-01
58+
"""
59+
60+
project_id: Optional[str]
61+
"""プロジェクトID。[値の制約についてはこちら。](#section/API-Convention/APIID) """
62+
63+
job_type: Optional[ProjectJobType]
2964
""""""
3065

3166
job_id: Optional[str]

annofabapi/dataclass/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ class Task(DataClassJsonMixin):
9696
account_id: Optional[str]
9797
""""""
9898

99-
histories_by_phase: Optional[List[TaskHistoryShort]]
99+
histories_by_phase: List[TaskHistoryShort]
100100
"""簡易的なタスク履歴(あるフェーズを誰が担当したか)"""
101101

102102
work_time_span: int
103103
"""累計実作業時間(ミリ秒)"""
104104

105-
number_of_rejections: Optional[int]
105+
number_of_rejections: int
106106
"""このタスクが差戻しされた回数(すべてのフェーズでの差戻し回数の合計 このフィールドは、どのフェーズで何回差戻されたかを区別できないため、廃止予定です。 `histories_by_phase` で各フェーズの回数を計算することで、差戻し回数が分かります。 例)`acceptance`フェーズが3回ある場合、`acceptance`フェーズで2回差し戻しされたことになります。 """
107107

108108
started_datetime: Optional[str]

annofabapi/generated_api.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ def delete_project_job(
10111011
10121012
Args:
10131013
project_id (str): プロジェクトID (required)
1014-
job_type (JobType): ジョブの種別。[詳細はこちら](#section/JobType)。 (required)
1014+
job_type (ProjectJobType): ジョブの種別。[詳細はこちら](#section/ProjectJobType)。 (required)
10151015
job_id (str): ジョブID (required)
10161016
10171017
Returns:
@@ -1024,28 +1024,60 @@ def delete_project_job(
10241024
keyword_params: Dict[str, Any] = {}
10251025
return self._request_wrapper(http_method, url_path, **keyword_params)
10261026

1027+
def get_organization_job(
1028+
self, organization_name: str, query_params: Optional[Dict[str, Any]] = None, **kwargs
1029+
) -> Tuple[Any, requests.Response]:
1030+
"""組織のバックグラウンドジョブ情報取得
1031+
https://annofab.com/docs/api/#operation/getOrganizationJob
1032+
1033+
1034+
authorizations: AllOrganizationMember
1035+
1036+
1037+
組織のバックグラウンドジョブの情報を取得します。 取得されるジョブ情報は、作成日付の新しい順にソートされています。 バックグラウンドジョブ情報は、完了(失敗含む)から14日経過後に自動で削除されます。
1038+
1039+
Args:
1040+
organization_name (str): 組織名 (required)
1041+
query_params (Dict[str, Any]): Query Parameters
1042+
type (str): 取得するジョブの種別。[詳細はこちら](#section/OrganizationJobType)。
1043+
page (int): 検索結果のうち、取得したいページの番号(1始まり) 現在は未実装のパラメータです。(今後対応予定)
1044+
limit (int): 1ページあたりの取得するデータ件数。 未指定時は1件のみ取得。
1045+
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時
1046+
1047+
Returns:
1048+
Tuple[OrganizationJobInfoContainer, requests.Response]
1049+
1050+
1051+
"""
1052+
url_path = f"/organizations/{organization_name}/jobs"
1053+
http_method = "GET"
1054+
keyword_params: Dict[str, Any] = {
1055+
"query_params": query_params,
1056+
}
1057+
return self._request_wrapper(http_method, url_path, **keyword_params)
1058+
10271059
def get_project_job(
10281060
self, project_id: str, query_params: Optional[Dict[str, Any]] = None, **kwargs
10291061
) -> Tuple[Any, requests.Response]:
1030-
"""バックグラウンドジョブ情報取得
1062+
"""プロジェクトのバックグラウンドジョブ情報取得
10311063
https://annofab.com/docs/api/#operation/getProjectJob
10321064
10331065
10341066
authorizations: AllProjectMember
10351067
10361068
1037-
バックグラウンドジョブの情報を取得します。 取得されるジョブ情報は、作成日付の新しい順にソートされています。 バックグラウンドジョブ情報は、完了(失敗含む)から14日経過後に自動で削除されます。
1069+
プロジェクトのバックグラウンドジョブの情報を取得します。 取得されるジョブ情報は、作成日付の新しい順にソートされています。 バックグラウンドジョブ情報は、完了(失敗含む)から14日経過後に自動で削除されます。
10381070
10391071
Args:
10401072
project_id (str): プロジェクトID (required)
10411073
query_params (Dict[str, Any]): Query Parameters
1042-
type (JobType): 取得するジョブの種別。[詳細はこちら](#section/JobType)。 (required)
1074+
type (ProjectJobType): 取得するジョブの種別。[詳細はこちら](#section/ProjectJobType)。
10431075
page (int): 検索結果のうち、取得したいページの番号(1始まり) 現在は未実装のパラメータです。(今後対応予定)
10441076
limit (int): 1ページあたりの取得するデータ件数。 未指定時は1件のみ取得。
10451077
exclusive_start_created_datetime (str): 取得するデータの直前の作成日時
10461078
10471079
Returns:
1048-
Tuple[JobInfoContainer, requests.Response]
1080+
Tuple[ProjectJobInfoContainer, requests.Response]
10491081
10501082
10511083
"""
@@ -1410,6 +1442,7 @@ def get_projects_of_organization(
14101442
except_account_id (str): 指定したアカウントIDをメンバーに持たないプロジェクトで絞り込む。
14111443
title (str): プロジェクトタイトルでの部分一致検索。1文字以上あれば使用します。利便性のため、大文字小文字は区別しません。
14121444
status (ProjectStatus): 指定した状態のプロジェクトで絞り込む。未指定時は全プロジェクト。
1445+
plugin_id (str): 指定したプラグインIDを使用しているプロジェクトで絞り込む。未指定時は指定なし。
14131446
input_data_type (InputDataType): 指定した入力データ種別でプロジェクトを絞り込む。未指定時は全プロジェクト。
14141447
sort_by (str): `date` を指定することでプロジェクトの最新のタスク更新時間の順にソートして出力する。 未指定時はプロジェクト名でソートする。
14151448

0 commit comments

Comments
 (0)