Skip to content

Commit 863449f

Browse files
authored
非推奨のJobTypeやJobInfoを削除 (#361)
* copy_annotation_specsを削除する * job typeなどを削除 * update swagger * update test * update test
1 parent a4e44e1 commit 863449f

File tree

9 files changed

+17
-210
lines changed

9 files changed

+17
-210
lines changed

annofabapi/dataclass/job.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from dataclasses_json import DataClassJsonMixin
1717

18-
from annofabapi._utils import deprecated_class
1918
from annofabapi.models import JobStatus, ProjectJobType
2019

2120

@@ -46,37 +45,3 @@ class ProjectJobInfo(DataClassJsonMixin):
4645

4746
updated_datetime: Optional[str]
4847
""""""
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]
64-
""""""
65-
66-
job_id: Optional[str]
67-
""""""
68-
69-
job_status: Optional[JobStatus]
70-
""""""
71-
72-
job_execution: Optional[Dict[str, Any]]
73-
"""ジョブの内部情報"""
74-
75-
job_detail: Optional[Dict[str, Any]]
76-
"""ジョブ結果の内部情報"""
77-
78-
created_datetime: Optional[str]
79-
""""""
80-
81-
updated_datetime: Optional[str]
82-
""""""

annofabapi/models.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4694,26 +4694,3 @@ class WebhookStatus(Enum):
46944694
作業時間の標準偏差(ISO 8601 duration)
46954695
46964696
"""
4697-
4698-
# 以下は2021-09-01以降に廃止する予定
4699-
JobInfo = ProjectJobInfo
4700-
JobInfoContainer = ProjectJobInfoContainer
4701-
4702-
4703-
@deprecated_class(deprecated_date="2021-09-01", new_class_name=f"{ProjectJobType.__module__}.{ProjectJobType.__name__}")
4704-
class JobType(Enum):
4705-
"""
4706-
プロジェクトのジョブ種別
4707-
4708-
.. deprecated:: 2021-09-01
4709-
"""
4710-
4711-
COPY_PROJECT = "copy-project"
4712-
GEN_INPUTS = "gen-inputs"
4713-
GEN_TASKS = "gen-tasks"
4714-
GEN_ANNOTATION = "gen-annotation"
4715-
GEN_TASKS_LIST = "gen-tasks-list"
4716-
GEN_INPUTS_LIST = "gen-inputs-list"
4717-
DELETE_PROJECT = "delete-project"
4718-
INVOKE_HOOK = "invoke-hook"
4719-
MOVE_PROJECT = "move-project"

annofabapi/wrapper.py

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings
1212
from dataclasses import dataclass
1313
from pathlib import Path
14-
from typing import Any, Callable, Dict, List, Optional, Union
14+
from typing import Any, Callable, Dict, List, Optional
1515

1616
import requests
1717

@@ -23,14 +23,12 @@
2323
AdditionalDataDefinitionV1,
2424
AnnotationDataHoldingType,
2525
AnnotationDetail,
26-
AnnotationSpecsV1,
2726
FullAnnotationData,
2827
InputData,
2928
Inspection,
3029
InspectionStatus,
3130
Instruction,
3231
JobStatus,
33-
JobType,
3432
LabelV1,
3533
MyOrganization,
3634
Organization,
@@ -669,39 +667,6 @@ def put_annotation_for_simple_annotation_json(
669667
#########################################
670668
# Public Method : AnnotationSpecs
671669
#########################################
672-
def copy_annotation_specs(
673-
self, src_project_id: str, dest_project_id: str, comment: Optional[str] = None
674-
) -> AnnotationSpecsV1:
675-
"""
676-
アノテーション仕様を、別のプロジェクトにコピーする。
677-
678-
.. deprecated:: 2021-09-01
679-
680-
681-
Note:
682-
誤って実行しないようにすること
683-
684-
Args:
685-
src_project_id: コピー元のproject_id
686-
dest_project_id: コピー先のproject_id
687-
comment: アノテーション仕様を保存するときのコメント。Noneならば、コピーした旨を記載する。
688-
689-
Returns:
690-
put_annotation_specsのContent
691-
"""
692-
warnings.warn("2021-09-01以降に削除します。", FutureWarning)
693-
694-
src_annotation_specs = self.api.get_annotation_specs(src_project_id)[0]
695-
696-
if comment is None:
697-
comment = f"Copied the annotation specification of project {src_project_id} on {str_now()}"
698-
699-
request_body = {
700-
"labels": src_annotation_specs["labels"],
701-
"inspection_phrases": src_annotation_specs["inspection_phrases"],
702-
"comment": comment,
703-
}
704-
return self.api.put_annotation_specs(dest_project_id, request_body=request_body)[0]
705670

706671
@staticmethod
707672
def __get_label_name_en(label: Dict[str, Any]) -> str:
@@ -1753,9 +1718,7 @@ def upload_data_as_instruction_image(self, project_id: str, image_id: str, data:
17531718
#########################################
17541719
# Public Method : Job
17551720
#########################################
1756-
def delete_all_succeeded_job(
1757-
self, project_id: str, job_type: Union[ProjectJobType, JobType]
1758-
) -> List[ProjectJobInfo]:
1721+
def delete_all_succeeded_job(self, project_id: str, job_type: ProjectJobType) -> List[ProjectJobInfo]:
17591722
"""
17601723
成功したジョブをすべて削除する
17611724
@@ -1797,7 +1760,7 @@ def get_all_project_job(self, project_id: str, query_params: Dict[str, Any] = No
17971760
all_jobs.extend(r["list"])
17981761
return all_jobs
17991762

1800-
def job_in_progress(self, project_id: str, job_type: Union[ProjectJobType, JobType]) -> bool:
1763+
def job_in_progress(self, project_id: str, job_type: ProjectJobType) -> bool:
18011764
"""
18021765
ジョブが進行中かどうか
18031766
@@ -1819,7 +1782,7 @@ def job_in_progress(self, project_id: str, job_type: Union[ProjectJobType, JobTy
18191782
def wait_for_completion(
18201783
self,
18211784
project_id: str,
1822-
job_type: Union[ProjectJobType, JobType],
1785+
job_type: ProjectJobType,
18231786
job_access_interval: int = 60,
18241787
max_job_access: int = 10,
18251788
) -> bool:
@@ -1849,7 +1812,7 @@ def wait_for_completion(
18491812
def wait_until_job_finished(
18501813
self,
18511814
project_id: str,
1852-
job_type: Union[ProjectJobType, JobType],
1815+
job_type: ProjectJobType,
18531816
job_id: Optional[str] = None,
18541817
job_access_interval: int = 60,
18551818
max_job_access: int = 360,
@@ -1927,14 +1890,14 @@ def get_job_from_job_id(arg_job_id: str) -> Optional[ProjectJobInfo]:
19271890
)
19281891
return JobStatus.PROGRESS
19291892

1930-
async def _job_in_progress_async(self, project_id: str, job_type: Union[ProjectJobType, JobType]) -> bool:
1893+
async def _job_in_progress_async(self, project_id: str, job_type: ProjectJobType) -> bool:
19311894
loop = asyncio.get_event_loop()
19321895
return await loop.run_in_executor(None, self.job_in_progress, project_id, job_type)
19331896

19341897
async def _wait_until_job_finished_async(
19351898
self,
19361899
project_id: str,
1937-
job_type: Union[ProjectJobType, JobType],
1900+
job_type: ProjectJobType,
19381901
job_id: Optional[str],
19391902
job_access_interval: int,
19401903
max_job_access: int,
@@ -1944,7 +1907,7 @@ async def _wait_until_job_finished_async(
19441907
None, self.wait_until_job_finished, project_id, job_type, job_id, job_access_interval, max_job_access
19451908
)
19461909

1947-
def can_execute_job(self, project_id: str, job_type: Union[ProjectJobType, JobType]) -> bool:
1910+
def can_execute_job(self, project_id: str, job_type: ProjectJobType) -> bool:
19481911
"""
19491912
ジョブが実行できる状態か否か。他のジョブが実行中で同時に実行できない場合はFalseを返す。
19501913
@@ -1955,19 +1918,14 @@ def can_execute_job(self, project_id: str, job_type: Union[ProjectJobType, JobTy
19551918
Returns:
19561919
ジョブが実行できる状態か否か
19571920
"""
1958-
# TODO: JobTypeが削除されたら、この処理も削除する
1959-
new_job_type: ProjectJobType = ProjectJobType(job_type.value) if isinstance(job_type, JobType) else job_type
1960-
1961-
job_type_list = _JOB_CONCURRENCY_LIMIT[new_job_type]
1921+
job_type_list = _JOB_CONCURRENCY_LIMIT[job_type]
19621922

19631923
# tokenがない場合、ログインが複数回発生するので、事前にログインしておく
19641924
if self.api.token_dict is None:
19651925
self.api.login()
19661926

19671927
# 複数のジョブに対して進行中かどうかを確認する
1968-
gather = asyncio.gather(
1969-
*[self._job_in_progress_async(project_id, new_job_type) for new_job_type in job_type_list]
1970-
)
1928+
gather = asyncio.gather(*[self._job_in_progress_async(project_id, job_type) for job_type in job_type_list])
19711929
loop = asyncio.get_event_loop()
19721930
result = loop.run_until_complete(gather)
19731931

@@ -1976,7 +1934,7 @@ def can_execute_job(self, project_id: str, job_type: Union[ProjectJobType, JobTy
19761934
def wait_until_job_is_executable(
19771935
self,
19781936
project_id: str,
1979-
job_type: Union[ProjectJobType, JobType],
1937+
job_type: ProjectJobType,
19801938
job_access_interval: int = 60,
19811939
max_job_access: int = 360,
19821940
) -> bool:
@@ -1993,10 +1951,8 @@ def wait_until_job_is_executable(
19931951
指定した時間(アクセス頻度と回数)待った後、ジョブが実行可能な状態かどうか。進行中のジョブが存在する場合は、ジョブが実行不可能。
19941952
19951953
"""
1996-
# TODO: JobTypeが削除されたら、この処理も削除する
1997-
new_job_type: ProjectJobType = ProjectJobType(job_type.value) if isinstance(job_type, JobType) else job_type
19981954

1999-
job_type_list = _JOB_CONCURRENCY_LIMIT[new_job_type]
1955+
job_type_list = _JOB_CONCURRENCY_LIMIT[job_type]
20001956
# tokenがない場合、ログインが複数回発生するので、事前にログインしておく
20011957
if self.api.token_dict is None:
20021958
self.api.login()

generate/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ cat partial-header/dataclass/common.py partial-header/dataclass/instruction.py
174174
# Job
175175
declare -a model_files=(${MODELS_DIR}/project_job_info.py)
176176
cat partial-header/dataclass/common.py partial-header/dataclass/job.py \
177-
${model_files[@]} partial-footer/dataclass/job.py > ../annofabapi/dataclass/job.py
177+
${model_files[@]} > ../annofabapi/dataclass/job.py
178178

179179
# My
180180
declare -a model_files=(${MODELS_DIR}/my_organization.py ${MODELS_DIR}/my_account.py)

generate/partial-footer/dataclass/job.py

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
# 以下は2021-09-01以降に廃止する予定
2-
JobInfo = ProjectJobInfo
3-
JobInfoContainer = ProjectJobInfoContainer
4-
5-
6-
@deprecated_class(deprecated_date="2021-09-01", new_class_name=f"{ProjectJobType.__module__}.{ProjectJobType.__name__}")
7-
class JobType(Enum):
8-
"""
9-
プロジェクトのジョブ種別
10-
11-
.. deprecated:: 2021-09-01
12-
"""
13-
14-
COPY_PROJECT = "copy-project"
15-
GEN_INPUTS = "gen-inputs"
16-
GEN_TASKS = "gen-tasks"
17-
GEN_ANNOTATION = "gen-annotation"
18-
GEN_TASKS_LIST = "gen-tasks-list"
19-
GEN_INPUTS_LIST = "gen-inputs-list"
20-
DELETE_PROJECT = "delete-project"
21-
INVOKE_HOOK = "invoke-hook"
22-
MOVE_PROJECT = "move-project"

tests/_test_dataclass_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from annofabapi.dataclass.input import InputData
1313
from annofabapi.dataclass.inspection import Inspection
1414
from annofabapi.dataclass.instruction import Instruction, InstructionHistory, InstructionImage
15-
from annofabapi.dataclass.job import JobInfo
15+
from annofabapi.dataclass.job import ProjectJobInfo
1616
from annofabapi.dataclass.my import MyAccount, MyOrganization
1717
from annofabapi.dataclass.organization import Organization, OrganizationActivity
1818
from annofabapi.dataclass.organization_member import OrganizationMember
@@ -124,8 +124,8 @@ def test_job(self):
124124
job_json = test_dir / "job.json"
125125
with job_json.open(encoding="utf-8") as f:
126126
dict_job = json.load(f)
127-
job = JobInfo.from_dict(dict_job)
128-
assert type(job) == JobInfo
127+
job = ProjectJobInfo.from_dict(dict_job)
128+
assert type(job) == ProjectJobInfo
129129

130130

131131
class TestMy:

tests/test_dataclass_webapi.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from annofabapi.dataclass.input import InputData
1111
from annofabapi.dataclass.inspection import Inspection
1212
from annofabapi.dataclass.instruction import Instruction, InstructionHistory, InstructionImage
13-
from annofabapi.dataclass.job import JobInfo, ProjectJobInfo
13+
from annofabapi.dataclass.job import ProjectJobInfo
1414
from annofabapi.dataclass.my import MyAccount, MyOrganization
1515
from annofabapi.dataclass.organization import Organization, OrganizationActivity
1616
from annofabapi.dataclass.organization_member import OrganizationMember
@@ -121,29 +121,6 @@ def test_job(self):
121121
else:
122122
print(f"ジョブが存在しませんでした。")
123123

124-
def test_job_deprecated(self):
125-
job_list = service.wrapper.get_all_project_job(project_id)
126-
if len(job_list) > 0:
127-
job = JobInfo.from_dict(job_list[0])
128-
assert type(job) == JobInfo
129-
130-
else:
131-
print(f"ジョブが存在しませんでした。")
132-
133-
def test_job_deprecated_warning_message(self):
134-
with warnings.catch_warnings(record=True) as found_warnings:
135-
try:
136-
JobInfo()
137-
except Exception:
138-
pass
139-
finally:
140-
assert len(found_warnings) == 1
141-
single_warning = found_warnings[0]
142-
print(single_warning)
143-
assert str(single_warning.message) == (
144-
"deprecated: 'annofabapi.dataclass.job.JobInfo'は2021-09-01以降に廃止します。"
145-
"替わりに'annofabapi.dataclass.job.ProjectJobInfo'を使用してください。"
146-
)
147124

148125

149126
class TestMy:

tests/test_local_models.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
import warnings
21

3-
from annofabapi.models import JobType
4-
5-
6-
class TestDeprecation:
7-
def test_job_deprecated(self):
8-
with warnings.catch_warnings(record=True) as found_warnings:
9-
print(JobType.GEN_ANNOTATION)
10-
assert len(found_warnings) == 1
11-
single_warning = found_warnings[0]
12-
assert str(single_warning.message) == (
13-
"deprecated: 'annofabapi.models.JobType'は2021-09-01以降に廃止します。"
14-
"替わりに'annofabapi.models.ProjectJobType'を使用してください。"
15-
)

0 commit comments

Comments
 (0)