Skip to content

Commit

Permalink
Add Workflow class for managing workflows and versions
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenAnpu committed Jul 5, 2024
1 parent e9eb1c3 commit a5c2b06
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/add_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
39 changes: 39 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a5c2b06

Please sign in to comment.