diff --git a/src/add_project.py b/src/add_project.py index b9e94bf..d6341e9 100644 --- a/src/add_project.py +++ b/src/add_project.py @@ -8,6 +8,7 @@ from supervisely.project.pointcloud_project import upload_pointcloud_project from supervisely.project.pointcloud_episode_project import upload_pointcloud_episode_project from supervisely.app.v1.app_service import AppService +from wokflow import Workflow if sly.is_development(): @@ -46,7 +47,7 @@ def do(**kwargs): ) api = sly.Api.from_env() - + workflow = Workflow(api) # dest_dir = "/sly_task_data/repo" dest_dir = my_app.data_dir # sly.fs.mkdir(dest_dir) @@ -119,8 +120,8 @@ def do(**kwargs): extra={"event_type": sly.EventType.PROJECT_CREATED, "project_id": project_id}, ) api.task.set_output_project(task_id, project_id, res_project_name) - # ---------------------------------------- Workflow Output --------------------------------------- # - api.app.add_output_project(project_id) + # ---------------------------------------- Workflow Output --------------------------------------- # + workflow.add_output(project_id) # ----------------------------------------------- - ---------------------------------------------- # my_app.stop() diff --git a/src/workflow.py b/src/workflow.py new file mode 100644 index 0000000..9927170 --- /dev/null +++ b/src/workflow.py @@ -0,0 +1,39 @@ +import supervisely as sly +import os + + +def check_compatibility(func): + def wrapper(self, *args, **kwargs): + if self.is_compatible is None: + self.is_compatible = self.check_instance_ver_compatibility() + if not self.is_compatible: + return + return func(self, *args, **kwargs) + + return wrapper + + +class Workflow: + def __init__(self, api: sly.Api, min_instance_version: str = None): + self.is_compatible = None + self.api = api + self._min_instance_version = ( + "6.9.22" if min_instance_version is None else min_instance_version + ) + + def check_instance_ver_compatibility(self): + if self.api.instance_version < self._min_instance_version: + sly.logger.info( + f"Supervisely instance version does not support workflow and versioning features. To use them, please update your instance minimum to version {self._min_instance_version}." + ) + return False + return True + + @check_compatibility + def add_input(self): + raise NotImplementedError("Method is not implemented yet.") + + @check_compatibility + def add_output(self, project_id: int): + self.api.app.workflow.add_output_project(project_id) +