Skip to content

Commit

Permalink
Merge pull request #445 from openvinotoolkit/zm/test-scoped-with-vcs
Browse files Browse the repository at this point in the history
Use Scope for VCS
  • Loading branch information
Maxim Zhiltsov authored Sep 7, 2021
2 parents 2f71d7e + cb4f0ab commit 8f78e79
Show file tree
Hide file tree
Showing 25 changed files with 1,226 additions and 995 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Annotation-related classes were moved into a new module,
`datumaro.components.annotation`
(<https://github.com/openvinotoolkit/datumaro/pull/439>)
- Rollback utilities replaced with Scope utilities
(<https://github.com/openvinotoolkit/datumaro/pull/444>)

### Deprecated
- TBD
Expand Down
5 changes: 4 additions & 1 deletion datumaro/cli/commands/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import argparse

from datumaro.util.scope import scope_add, scoped

from ..util import MultilineFormatter
from ..util.project import load_project

Expand Down Expand Up @@ -45,6 +47,7 @@ def build_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def checkout_command(args):
has_sep = '--' in args._positionals
if has_sep:
Expand All @@ -60,7 +63,7 @@ def checkout_command(args):
raise argparse.ArgumentError('sources', message="When '--' is used, "
"at least 1 source name must be specified")

project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

project.checkout(rev=args.rev, sources=args.sources, force=args.force)

Expand Down
5 changes: 4 additions & 1 deletion datumaro/cli/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import argparse

from datumaro.util.scope import scope_add, scoped

from ..util import MultilineFormatter
from ..util.project import load_project

Expand Down Expand Up @@ -32,8 +34,9 @@ def build_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def commit_command(args):
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

old_tree = project.head

Expand Down
23 changes: 16 additions & 7 deletions datumaro/cli/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from datumaro.components.errors import ProjectNotFoundError
from datumaro.components.operations import DistanceComparator, ExactComparator
from datumaro.util import error_rollback, on_error_do
from datumaro.util.os_util import rmtree
from datumaro.util.scope import on_error_do, scope_add, scoped

from ..contexts.project.diff import DiffVisualizer
from ..util import MultilineFormatter
Expand Down Expand Up @@ -132,7 +132,7 @@ def _parse_comparison_method(s):

return parser

@error_rollback
@scoped
def diff_command(args):
dst_dir = args.dst_dir
if dst_dir:
Expand All @@ -149,22 +149,31 @@ def diff_command(args):

project = None
try:
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))
except ProjectNotFoundError:
if args.project_dir:
raise

try:
if not args.second_target:
first_dataset = project.working_tree.make_dataset()
second_dataset = parse_full_revpath(args.first_target, project)
second_dataset, target_project = \
parse_full_revpath(args.first_target, project)
if target_project:
scope_add(target_project)
else:
first_dataset = parse_full_revpath(args.first_target, project)
second_dataset = parse_full_revpath(args.second_target, project)
first_dataset, target_project = \
parse_full_revpath(args.first_target, project)
if target_project:
scope_add(target_project)

second_dataset, target_project = \
parse_full_revpath(args.second_target, project)
if target_project:
scope_add(target_project)
except Exception as e:
raise CliException(str(e))


if args.method is ComparisonMethod.equality:
if args.ignore_field:
args.ignore_field = eq_default_if
Expand Down
10 changes: 8 additions & 2 deletions datumaro/cli/commands/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os.path as osp

from datumaro.util.image import is_image, load_image, save_image
from datumaro.util.scope import scope_add, scoped

from ..util import MultilineFormatter
from ..util.project import load_project, parse_full_revpath
Expand Down Expand Up @@ -110,11 +111,12 @@ def build_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def explain_command(args):
from matplotlib import cm
import cv2

project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

model = project.working_tree.models.make_executable_model(args.model)

Expand Down Expand Up @@ -168,7 +170,11 @@ def explain_command(args):
cv2.waitKey(0)

else:
dataset = parse_full_revpath(args.target or 'project', project)
dataset, target_project = \
parse_full_revpath(args.target or 'project', project)
if target_project:
scope_add(target_project)

log.info("Running inference explanation for '%s'" % args.target)

for item in dataset:
Expand Down
8 changes: 6 additions & 2 deletions datumaro/cli/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
DatasetMergeError, MissingObjectError, ProjectNotFoundError,
)
from datumaro.components.extractor import AnnotationType
from datumaro.util.scope import scope_add, scoped

from ..util import MultilineFormatter
from ..util.project import load_project, parse_full_revpath
Expand Down Expand Up @@ -55,17 +56,20 @@ def build_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def info_command(args):
project = None
try:
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))
except ProjectNotFoundError:
if args.project_dir:
raise

try:
# TODO: avoid computing working tree hashes
dataset = parse_full_revpath(args.target, project)
dataset, target_project = parse_full_revpath(args.target, project)
if target_project:
scope_add(target_project)
except DatasetMergeError as e:
dataset = None
dataset_problem = "Can't merge project sources automatically: %s " \
Expand Down
5 changes: 4 additions & 1 deletion datumaro/cli/commands/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import argparse

from datumaro.util.scope import scope_add, scoped

from ..util.project import load_project


Expand All @@ -18,8 +20,9 @@ def build_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def log_command(args):
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

revisions = project.history(args.max_count)
if revisions:
Expand Down
9 changes: 7 additions & 2 deletions datumaro/cli/commands/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DatasetMergeError, DatasetQualityError, ProjectNotFoundError,
)
from datumaro.components.operations import IntersectMerge
from datumaro.util.scope import scope_add, scoped

from ..util import MultilineFormatter
from ..util.errors import CliException
Expand Down Expand Up @@ -102,6 +103,7 @@ def _group(s):

return parser

@scoped
def merge_command(args):
dst_dir = args.dst_dir
if dst_dir:
Expand All @@ -114,7 +116,7 @@ def merge_command(args):

project = None
try:
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))
except ProjectNotFoundError:
if args.project_dir:
raise
Expand All @@ -125,7 +127,10 @@ def merge_command(args):
source_datasets.append(project.working_tree.make_dataset())

for t in args.targets:
source_datasets.append(parse_full_revpath(t, project))
target_dataset, target_project = parse_full_revpath(t, project)
if target_project:
scope_add(target_project)
source_datasets.append(target_dataset)
except Exception as e:
raise CliException(str(e))

Expand Down
4 changes: 3 additions & 1 deletion datumaro/cli/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse

from datumaro.cli.util import MultilineFormatter
from datumaro.util.scope import scope_add, scoped

from ..util.project import load_project

Expand All @@ -24,8 +25,9 @@ def build_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def status_command(args):
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

statuses = project.status()

Expand Down
21 changes: 14 additions & 7 deletions datumaro/cli/contexts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from datumaro.components.errors import ProjectNotFoundError
from datumaro.components.project import Environment
from datumaro.util import error_rollback, on_error_do
from datumaro.util.os_util import rmtree
from datumaro.util.scope import on_error_do, scope_add, scoped

from ..util import MultilineFormatter, add_subparser
from ..util.errors import CliException
Expand Down Expand Up @@ -53,13 +53,13 @@ def build_add_parser(parser_ctor=argparse.ArgumentParser):

return parser

@error_rollback
@scoped
def add_command(args):
show_plugin_help = '-h' in args.extra_args or '--help' in args.extra_args

project = None
try:
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))
except ProjectNotFoundError:
if not show_plugin_help and args.project_dir:
raise
Expand Down Expand Up @@ -125,8 +125,9 @@ def build_remove_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def remove_command(args):
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

project.remove_model(args.name)
project.save()
Expand Down Expand Up @@ -165,6 +166,7 @@ def build_run_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def run_command(args):
dst_dir = args.dst_dir
if dst_dir:
Expand All @@ -175,8 +177,12 @@ def run_command(args):
dst_dir = generate_next_file_name('%s-inference' % args.model_name)
dst_dir = osp.abspath(dst_dir)

project = load_project(args.project_dir)
dataset = parse_full_revpath(args.target, project)
project = scope_add(load_project(args.project_dir))

dataset, target_project = parse_full_revpath(args.target, project)
if target_project:
scope_add(target_project)

model = project.make_model(args.model_name)
inference = dataset.run_model(model)
inference.save(dst_dir)
Expand All @@ -198,8 +204,9 @@ def build_info_parser(parser_ctor=argparse.ArgumentParser):

return parser

@scoped
def info_command(args):
project = load_project(args.project_dir)
project = scope_add(load_project(args.project_dir))

if args.name:
print(project.models[args.name])
Expand Down
Loading

0 comments on commit 8f78e79

Please sign in to comment.