Skip to content

Commit

Permalink
非推奨のJobTypeやJobInfoを削除 (#361)
Browse files Browse the repository at this point in the history
* copy_annotation_specsを削除する

* job typeなどを削除

* update swagger

* update test

* update test
  • Loading branch information
yuji38kwmt committed Sep 22, 2021
1 parent a4e44e1 commit 863449f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 210 deletions.
35 changes: 0 additions & 35 deletions annofabapi/dataclass/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from dataclasses_json import DataClassJsonMixin

from annofabapi._utils import deprecated_class
from annofabapi.models import JobStatus, ProjectJobType


Expand Down Expand Up @@ -46,37 +45,3 @@ class ProjectJobInfo(DataClassJsonMixin):

updated_datetime: Optional[str]
""""""


# 2021-09-01以降に削除する予定
@deprecated_class(deprecated_date="2021-09-01", new_class_name=f"{ProjectJobInfo.__module__}.{ProjectJobInfo.__name__}")
@dataclass
class JobInfo(DataClassJsonMixin):
"""プロジェクトのジョブ情報
.. deprecated:: 2021-09-01
"""

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

job_type: Optional[ProjectJobType]
""""""

job_id: Optional[str]
""""""

job_status: Optional[JobStatus]
""""""

job_execution: Optional[Dict[str, Any]]
"""ジョブの内部情報"""

job_detail: Optional[Dict[str, Any]]
"""ジョブ結果の内部情報"""

created_datetime: Optional[str]
""""""

updated_datetime: Optional[str]
""""""
23 changes: 0 additions & 23 deletions annofabapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4694,26 +4694,3 @@ class WebhookStatus(Enum):
作業時間の標準偏差(ISO 8601 duration)
"""

# 以下は2021-09-01以降に廃止する予定
JobInfo = ProjectJobInfo
JobInfoContainer = ProjectJobInfoContainer


@deprecated_class(deprecated_date="2021-09-01", new_class_name=f"{ProjectJobType.__module__}.{ProjectJobType.__name__}")
class JobType(Enum):
"""
プロジェクトのジョブ種別
.. deprecated:: 2021-09-01
"""

COPY_PROJECT = "copy-project"
GEN_INPUTS = "gen-inputs"
GEN_TASKS = "gen-tasks"
GEN_ANNOTATION = "gen-annotation"
GEN_TASKS_LIST = "gen-tasks-list"
GEN_INPUTS_LIST = "gen-inputs-list"
DELETE_PROJECT = "delete-project"
INVOKE_HOOK = "invoke-hook"
MOVE_PROJECT = "move-project"
68 changes: 12 additions & 56 deletions annofabapi/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import warnings
from dataclasses import dataclass
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Union
from typing import Any, Callable, Dict, List, Optional

import requests

Expand All @@ -23,14 +23,12 @@
AdditionalDataDefinitionV1,
AnnotationDataHoldingType,
AnnotationDetail,
AnnotationSpecsV1,
FullAnnotationData,
InputData,
Inspection,
InspectionStatus,
Instruction,
JobStatus,
JobType,
LabelV1,
MyOrganization,
Organization,
Expand Down Expand Up @@ -669,39 +667,6 @@ def put_annotation_for_simple_annotation_json(
#########################################
# Public Method : AnnotationSpecs
#########################################
def copy_annotation_specs(
self, src_project_id: str, dest_project_id: str, comment: Optional[str] = None
) -> AnnotationSpecsV1:
"""
アノテーション仕様を、別のプロジェクトにコピーする。
.. deprecated:: 2021-09-01
Note:
誤って実行しないようにすること
Args:
src_project_id: コピー元のproject_id
dest_project_id: コピー先のproject_id
comment: アノテーション仕様を保存するときのコメント。Noneならば、コピーした旨を記載する。
Returns:
put_annotation_specsのContent
"""
warnings.warn("2021-09-01以降に削除します。", FutureWarning)

src_annotation_specs = self.api.get_annotation_specs(src_project_id)[0]

if comment is None:
comment = f"Copied the annotation specification of project {src_project_id} on {str_now()}"

request_body = {
"labels": src_annotation_specs["labels"],
"inspection_phrases": src_annotation_specs["inspection_phrases"],
"comment": comment,
}
return self.api.put_annotation_specs(dest_project_id, request_body=request_body)[0]

@staticmethod
def __get_label_name_en(label: Dict[str, Any]) -> str:
Expand Down Expand Up @@ -1753,9 +1718,7 @@ def upload_data_as_instruction_image(self, project_id: str, image_id: str, data:
#########################################
# Public Method : Job
#########################################
def delete_all_succeeded_job(
self, project_id: str, job_type: Union[ProjectJobType, JobType]
) -> List[ProjectJobInfo]:
def delete_all_succeeded_job(self, project_id: str, job_type: ProjectJobType) -> List[ProjectJobInfo]:
"""
成功したジョブをすべて削除する
Expand Down Expand Up @@ -1797,7 +1760,7 @@ def get_all_project_job(self, project_id: str, query_params: Dict[str, Any] = No
all_jobs.extend(r["list"])
return all_jobs

def job_in_progress(self, project_id: str, job_type: Union[ProjectJobType, JobType]) -> bool:
def job_in_progress(self, project_id: str, job_type: ProjectJobType) -> bool:
"""
ジョブが進行中かどうか
Expand All @@ -1819,7 +1782,7 @@ def job_in_progress(self, project_id: str, job_type: Union[ProjectJobType, JobTy
def wait_for_completion(
self,
project_id: str,
job_type: Union[ProjectJobType, JobType],
job_type: ProjectJobType,
job_access_interval: int = 60,
max_job_access: int = 10,
) -> bool:
Expand Down Expand Up @@ -1849,7 +1812,7 @@ def wait_for_completion(
def wait_until_job_finished(
self,
project_id: str,
job_type: Union[ProjectJobType, JobType],
job_type: ProjectJobType,
job_id: Optional[str] = None,
job_access_interval: int = 60,
max_job_access: int = 360,
Expand Down Expand Up @@ -1927,14 +1890,14 @@ def get_job_from_job_id(arg_job_id: str) -> Optional[ProjectJobInfo]:
)
return JobStatus.PROGRESS

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

async def _wait_until_job_finished_async(
self,
project_id: str,
job_type: Union[ProjectJobType, JobType],
job_type: ProjectJobType,
job_id: Optional[str],
job_access_interval: int,
max_job_access: int,
Expand All @@ -1944,7 +1907,7 @@ async def _wait_until_job_finished_async(
None, self.wait_until_job_finished, project_id, job_type, job_id, job_access_interval, max_job_access
)

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

job_type_list = _JOB_CONCURRENCY_LIMIT[new_job_type]
job_type_list = _JOB_CONCURRENCY_LIMIT[job_type]

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

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

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

job_type_list = _JOB_CONCURRENCY_LIMIT[new_job_type]
job_type_list = _JOB_CONCURRENCY_LIMIT[job_type]
# tokenがない場合、ログインが複数回発生するので、事前にログインしておく
if self.api.token_dict is None:
self.api.login()
Expand Down
2 changes: 1 addition & 1 deletion generate/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ cat partial-header/dataclass/common.py partial-header/dataclass/instruction.py
# Job
declare -a model_files=(${MODELS_DIR}/project_job_info.py)
cat partial-header/dataclass/common.py partial-header/dataclass/job.py \
${model_files[@]} partial-footer/dataclass/job.py > ../annofabapi/dataclass/job.py
${model_files[@]} > ../annofabapi/dataclass/job.py

# My
declare -a model_files=(${MODELS_DIR}/my_organization.py ${MODELS_DIR}/my_account.py)
Expand Down
32 changes: 0 additions & 32 deletions generate/partial-footer/dataclass/job.py

This file was deleted.

22 changes: 0 additions & 22 deletions generate/partial-footer/models_partial_footer.py
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
# 以下は2021-09-01以降に廃止する予定
JobInfo = ProjectJobInfo
JobInfoContainer = ProjectJobInfoContainer


@deprecated_class(deprecated_date="2021-09-01", new_class_name=f"{ProjectJobType.__module__}.{ProjectJobType.__name__}")
class JobType(Enum):
"""
プロジェクトのジョブ種別
.. deprecated:: 2021-09-01
"""

COPY_PROJECT = "copy-project"
GEN_INPUTS = "gen-inputs"
GEN_TASKS = "gen-tasks"
GEN_ANNOTATION = "gen-annotation"
GEN_TASKS_LIST = "gen-tasks-list"
GEN_INPUTS_LIST = "gen-inputs-list"
DELETE_PROJECT = "delete-project"
INVOKE_HOOK = "invoke-hook"
MOVE_PROJECT = "move-project"
6 changes: 3 additions & 3 deletions tests/_test_dataclass_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from annofabapi.dataclass.input import InputData
from annofabapi.dataclass.inspection import Inspection
from annofabapi.dataclass.instruction import Instruction, InstructionHistory, InstructionImage
from annofabapi.dataclass.job import JobInfo
from annofabapi.dataclass.job import ProjectJobInfo
from annofabapi.dataclass.my import MyAccount, MyOrganization
from annofabapi.dataclass.organization import Organization, OrganizationActivity
from annofabapi.dataclass.organization_member import OrganizationMember
Expand Down Expand Up @@ -124,8 +124,8 @@ def test_job(self):
job_json = test_dir / "job.json"
with job_json.open(encoding="utf-8") as f:
dict_job = json.load(f)
job = JobInfo.from_dict(dict_job)
assert type(job) == JobInfo
job = ProjectJobInfo.from_dict(dict_job)
assert type(job) == ProjectJobInfo


class TestMy:
Expand Down
25 changes: 1 addition & 24 deletions tests/test_dataclass_webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from annofabapi.dataclass.input import InputData
from annofabapi.dataclass.inspection import Inspection
from annofabapi.dataclass.instruction import Instruction, InstructionHistory, InstructionImage
from annofabapi.dataclass.job import JobInfo, ProjectJobInfo
from annofabapi.dataclass.job import ProjectJobInfo
from annofabapi.dataclass.my import MyAccount, MyOrganization
from annofabapi.dataclass.organization import Organization, OrganizationActivity
from annofabapi.dataclass.organization_member import OrganizationMember
Expand Down Expand Up @@ -121,29 +121,6 @@ def test_job(self):
else:
print(f"ジョブが存在しませんでした。")

def test_job_deprecated(self):
job_list = service.wrapper.get_all_project_job(project_id)
if len(job_list) > 0:
job = JobInfo.from_dict(job_list[0])
assert type(job) == JobInfo

else:
print(f"ジョブが存在しませんでした。")

def test_job_deprecated_warning_message(self):
with warnings.catch_warnings(record=True) as found_warnings:
try:
JobInfo()
except Exception:
pass
finally:
assert len(found_warnings) == 1
single_warning = found_warnings[0]
print(single_warning)
assert str(single_warning.message) == (
"deprecated: 'annofabapi.dataclass.job.JobInfo'は2021-09-01以降に廃止します。"
"替わりに'annofabapi.dataclass.job.ProjectJobInfo'を使用してください。"
)


class TestMy:
Expand Down
14 changes: 0 additions & 14 deletions tests/test_local_models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
import warnings

from annofabapi.models import JobType


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

0 comments on commit 863449f

Please sign in to comment.