Skip to content

Commit

Permalink
Merge pull request #3 from supervisely-ecosystem/workflow-test
Browse files Browse the repository at this point in the history
Add Workflow
  • Loading branch information
GoldenAnpu authored Jul 8, 2024
2 parents 8d40321 + 81fb121 commit 87e9a87
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
6 changes: 3 additions & 3 deletions local.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ LOG_LEVEL="debug"

# Almaz
# USER_ID = 330
TEAM_ID = 447
WORKSPACE_ID = 680
# PROJECT_ID = 36910
TEAM_ID = 451
WORKSPACE_ID = 712
PROJECT_ID = 38385
# DATASET_ID = 88187
# DATASET_NAME =

Expand Down
6 changes: 4 additions & 2 deletions src/globals.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import datetime
import os

from distutils.util import strtobool
from dotenv import load_dotenv

import supervisely as sly
from dotenv import load_dotenv

from workflow import Workflow

if sly.is_development():
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api()
workflow = Workflow(api)

app_data = sly.app.get_data_dir()
sly.fs.clean_dir(app_data)
Expand Down
4 changes: 3 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import supervisely as sly

import src.functions as f
import src.globals as g
import supervisely as sly

# * 1. Get project and dataset infos
try:
Expand Down Expand Up @@ -43,6 +44,7 @@
f"{project.name}. {'' if 'dataset' in dataset.name else 'New dataset: '}{dataset.name}"
)
g.api.task.set_output_project(g.task_id, project.id, output_title)
g.workflow.add_output(project)

# * 5. Clean app_data directory
sly.fs.clean_dir(g.app_data)
37 changes: 37 additions & 0 deletions src/workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import supervisely as sly


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.31" 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 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

@check_compatibility
def add_output(self, project_info: sly.ProjectInfo):
self.api.app.workflow.add_output_project(project_info)

0 comments on commit 87e9a87

Please sign in to comment.