Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic versioning #238

Merged
merged 416 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
416 commits
Select commit Hold shift + click to select a range
2845a0d
Add cleanup on project init errors
May 25, 2021
9742c24
Rename history to log
May 25, 2021
42fe0da
Update source add help
May 25, 2021
d46e50c
Allow building empty project
May 25, 2021
e380891
Fix checkout behaviour
May 25, 2021
2b47dcd
fix gitignore handling and add initial commit
May 25, 2021
5f2a21b
Fix export command
May 25, 2021
68347f6
Fix camvid
May 25, 2021
82b06d8
fix test
May 26, 2021
933464d
Update explain command
May 26, 2021
5adbc3d
Optimize dataset copying
May 28, 2021
0137994
Merge branch 'develop' into zm/vcs-simple-exp
May 28, 2021
f0f1d1d
fixes
May 28, 2021
76097c1
Remove download_source TBC in a patch with remote sources
May 31, 2021
fe0f479
Remove checkout file stub
May 31, 2021
c82eadc
Add pretty status command
Jun 1, 2021
eec574e
Add commit diff output
Jun 2, 2021
b55b639
Skit empty directory in test comparison
Jun 3, 2021
3523261
Add source checkouts
Jun 3, 2021
b768cbd
Add checks for changes outside datumaro on commit, fix gitignore
Jun 3, 2021
743b575
Update models and plugins
Jun 4, 2021
9dc81d1
Remove command_targets
Jun 4, 2021
1736ba8
Merge branch 'develop' into zm/vcs-simple-exp
Jun 4, 2021
a4c8312
Fix tests, remove status checks in transform-based commands
Jun 4, 2021
d82a6ba
Make dvc more quiet
Jun 7, 2021
0ffabfd
Fix model creation
Jun 7, 2021
c45a5bc
Support relative paths inside sources
Jun 8, 2021
7acbea6
Merge branch 'develop' into zm/vcs-simple-exp
Jun 10, 2021
f580e32
Fix tests
Jun 10, 2021
0869d95
Fix kitti
Jun 10, 2021
d3deee2
fixes in tests
Jun 10, 2021
5ff4637
t
Jun 15, 2021
8a790d3
t2
Jun 16, 2021
618627b
Revise item status changes
Jun 17, 2021
2a4733c
Update builtin transforms
Jun 17, 2021
b6758d6
Fix dataset length computation when no source
Jun 17, 2021
285cbbf
move test
Jun 17, 2021
6524816
update chengelog
Jun 17, 2021
f8ad828
Add filter test
Jun 17, 2021
6071377
Merge branch 'zm/update-transforms' into zm/vcs-simple-exp
Jun 17, 2021
b733a6b
Fix transforms affecting categories
Jun 17, 2021
ee14fe0
Filter out ItemTransforms from plugins
Jun 17, 2021
a6f033a
Fix transforms affecting categories
Jun 17, 2021
e65e30b
Merge branch 'zm/update-transforms' into zm/vcs-simple-exp
Jun 17, 2021
6f8bb2e
Optimize categories trnasforms
Jun 17, 2021
704fb6c
Update filters
Jun 17, 2021
5d9b1e6
Merge branch 'zm/update-transforms' into zm/vcs-simple-exp
Jun 17, 2021
3081ca1
fix imports
Jun 17, 2021
585ab9d
Avoid using default docstrings in plugins
Jun 17, 2021
75fae6b
Fix patch saving in VOC, add keep_empty export parameter
Jun 18, 2021
df2e462
Fix flush_changes
Jun 18, 2021
6d80cac
Fix removed images and subsets in dataset patch
Jun 18, 2021
c6b386b
Merge branch 'zm/update-transforms' into zm/vcs-simple-exp
Jun 18, 2021
a3679ad
Update transform stage test
Jun 18, 2021
65f462a
Fix linter warnings
Jun 18, 2021
804b666
Merge branch 'develop' into zm/vcs-simple-exp
Jun 21, 2021
e8f85ba
Update diff command syntax
Jun 21, 2021
98c9c70
Update diff command to support revpaths, merge diff and ediff, update…
Jun 22, 2021
94a1d42
Add invalid source name symbols check
Jun 22, 2021
4caea6f
Add annotation subdir in datumaro importer
Jun 22, 2021
c9a5120
Avoid making categories when they aren't present in all merged datasets
Jun 22, 2021
4668ca5
Refactor revpath in cli, add revpath in merge and explain, update hel…
Jun 22, 2021
0c0b85a
Update cli help
Jun 22, 2021
b98a5d8
fix formatting
Jun 22, 2021
1572325
Merge branch 'develop' into zm/vcs-simple-exp
Jun 23, 2021
ab7221a
Change help line
Jun 28, 2021
db40a93
Merge branch 'develop' into zm/vcs-simple-exp
Jun 28, 2021
ee241cb
Fix arg separator in checkout command
Jul 7, 2021
d9cd860
Fix voc saving problem from comments
Jul 7, 2021
38daadf
Fix saving of restored targets
Jul 7, 2021
6001323
Cosmetic changes in cli
Jul 9, 2021
32a486a
refactor project enums
Jul 9, 2021
88a64f1
Update type annotations in project
Jul 9, 2021
cc4a558
Merge branch 'develop' into zm/vcs-simple-exp
Jul 9, 2021
d40814e
Fix imports
Jul 9, 2021
1b351df
Cleanup pylint suppressions
Jul 9, 2021
9b68db6
Fix tests
Jul 9, 2021
5ac2935
Ignore subprocess bandit warnings
Jul 9, 2021
938a627
ignore pylint warning
Jul 9, 2021
03eff89
ignore harder
Jul 9, 2021
19feb9b
Fix arg separator uses in cli
Jul 9, 2021
ef82bbe
Remove empty line in license headers
Jul 9, 2021
06f3a4b
Add a check for unknown local source data
Jul 12, 2021
c1412d0
Fix chaining transforms in the working tree
Jul 12, 2021
9ee7ae1
Merge branch 'develop' into zm/vcs-simple-exp
Jul 20, 2021
aa8b2c7
Fix tests after merge
Jul 23, 2021
c800040
Clean code
Jul 23, 2021
af34fc2
Update source downloading code, add no_cache, rpath, add more checks
Jul 23, 2021
7ab8d0e
Remove datumaro_project export
Jul 23, 2021
fbc01dd
Merge branch 'develop' into zm/vcs-simple-exp
Jul 23, 2021
7a3167f
Fix newlines
Jul 23, 2021
064baea
Add status test
Jul 23, 2021
54a0fdd
Add more tests
Jul 23, 2021
2b7a989
Merge branch 'develop' into zm/vcs-simple-exp
Jul 27, 2021
407af44
Merge branch 'develop' into zm/vcs-simple-exp
Jul 27, 2021
98d0936
Fix typo
Jul 27, 2021
08282ac
Fix year
Jul 27, 2021
e2a1a16
Improve help
Jul 27, 2021
9305f43
Merge branch 'develop' into zm/vcs-simple-exp
Jul 27, 2021
f54a4e9
Refactor catch_output
Jul 27, 2021
07b3f8e
Fix imports
Jul 27, 2021
69ae30d
Merge branch 'develop' into zm/vcs-simple-exp
Jul 27, 2021
b8feff5
Merge branch 'develop' into zm/vcs-simple-exp
Jul 28, 2021
5b2d992
Add some docs
Jul 28, 2021
824c438
Add default error messages
Jul 28, 2021
6177390
Fix merge errors
Jul 28, 2021
e10f6e1
Fix pylint errors
Jul 28, 2021
7a29e68
Merge branch 'develop' into zm/vcs-simple-exp
Jul 28, 2021
58e38ba
Move type definitions
Jul 28, 2021
2de8be7
Revert early exits in categories multimerge
Jul 28, 2021
ae23cc0
Remove quotes, add regex caching in revpath
Jul 29, 2021
6b8ff87
Format json examples
Jul 29, 2021
923a5e3
Add set
Jul 29, 2021
05136e1
exclude redundant check
Jul 29, 2021
454067f
remove conditional import
Jul 29, 2021
cc2f2ce
Fix context managers
Jul 29, 2021
0c68e0e
Update xcopy call
Jul 29, 2021
846e465
fix version
Jul 29, 2021
a84afe3
Use fullmatch
Jul 30, 2021
e7d602f
Fix import
Jul 30, 2021
64d9add
Fix windows abs paths in revpath
Jul 30, 2021
f9f7eaf
Change escaping
Jul 30, 2021
d2c10c9
Merge branch 'develop' into zm/vcs-simple-exp
Jul 30, 2021
047ba7f
re-ignore warning
Jul 30, 2021
0b09188
Refactor revpath parsing
Aug 3, 2021
17577b7
Add more checks for copytree
Aug 3, 2021
0e6dd68
Fix double use of existack
Aug 3, 2021
441452a
Update datumaro/util/image.py
Aug 3, 2021
d84dad7
Merge branch 'develop' into zm/vcs-simple-exp
Aug 3, 2021
debd53f
Fix ignorefile writing
Aug 3, 2021
359bb22
Fix type annotation for mode
Aug 3, 2021
f302bcd
Restore ruamel.yaml in requirements
Aug 3, 2021
11441c2
Add networkx requirement
Aug 3, 2021
194459d
Remove regex globals
Aug 3, 2021
e909004
Refactor getattr
Aug 4, 2021
a9a84b3
Refactor subgraph
Aug 4, 2021
b319adc
Update comment
Aug 4, 2021
afe4189
Merge branch 'develop' into zm/vcs-simple-exp
Aug 4, 2021
d83fc32
Change property declaration
Aug 5, 2021
ceceb37
Fix has_stages
Aug 5, 2021
82d3332
Add error message for copytree failures
Aug 5, 2021
104c59f
Add some raise from
Aug 5, 2021
54fd1f2
Cli fixes
Aug 5, 2021
be22050
refactor pipeline building code
Aug 6, 2021
e468816
Update _update_ignore_file
Aug 10, 2021
709f38a
Update property declaration
Aug 10, 2021
aeb9be6
Add raise from
Aug 10, 2021
4a8ae4c
Extract subpath check
Aug 10, 2021
eb70c80
Fixes to stage checks
Aug 10, 2021
0d5ae4e
Update log function declaration
Aug 10, 2021
01328b8
Add raise from
Aug 10, 2021
33e0dc1
Replace some subpath checks
Aug 10, 2021
d3924a4
Comment unused git and dvc wrappers
Aug 10, 2021
f8c02ae
Remove plugin help dependency on project in CLI
Aug 11, 2021
f2ac910
Fix coco converter help
Aug 11, 2021
31f8370
Allow full revpaths in stats and validate
Aug 11, 2021
9654a36
Inherit plugin bases from cliplugin
Aug 11, 2021
4a1bf84
Comment dvc run
Aug 11, 2021
61143e8
Remove unused dvc and git bindings
Aug 12, 2021
62f4864
Fix validator plugins
Aug 12, 2021
8b019c0
Fix positional arg conflict with plugin help
Aug 12, 2021
a96a653
Update command descriptions
Aug 13, 2021
96b1b66
fix workaround for positionals
Aug 13, 2021
fa6b3e5
Add comment
Aug 13, 2021
ddb260d
Update lists of dependencies
Aug 16, 2021
ceda7b8
Make git optional
Aug 16, 2021
0477542
Throw errors in Project ctor if no git or dvc available
Aug 17, 2021
2a777a8
Update importerror with modulenotfounderror
Aug 17, 2021
6c51a10
remove extra import
Aug 17, 2021
c0d0eb2
Update ci config
Aug 17, 2021
89d4849
Fix find_project
Aug 24, 2021
c9a836a
Fixes in migration
Aug 24, 2021
02e55ea
Merge branch 'develop' into zm/vcs-simple-exp
Aug 24, 2021
27fc206
Update source name validation
Aug 25, 2021
fd09e94
Fix es
Aug 25, 2021
96718dc
Remove tmp dir suffixes
Aug 25, 2021
9a09573
Add model name checking
Aug 25, 2021
711b446
Clarify rev and ref, rename reference to objectid
Aug 25, 2021
11862d8
Polish some naming
Aug 25, 2021
2841957
Restore escaping in regex
Aug 25, 2021
dabd533
Ignore warning
Aug 25, 2021
8d7cd2e
Change default stage names
Aug 25, 2021
8a24c2d
Add double dash to cp call
Aug 25, 2021
b4e8ae6
Replace some subpath checks
Aug 25, 2021
6e7b642
Fix create command example
Aug 25, 2021
ec79a77
Add some newlines to source add help
Aug 25, 2021
47f9bfe
Add stage cases to revpath tests
Aug 30, 2021
20b952c
add source copying logs
Aug 30, 2021
2bcdb2c
Split datum info info 2 commands
Aug 30, 2021
d45ab05
Introduce readonly projects, avoid downloading when prohibited
Aug 30, 2021
a9af5f7
Forward project readonly property to the datasets
Aug 31, 2021
a59621c
Rename variables, add comments
Aug 31, 2021
ad6d5b7
Disallow early exit from can_retrieve in some cases
Aug 31, 2021
18a130c
Check for inexistent path in importer
Aug 31, 2021
0985bd1
Narrow the list of catched dataset revpath loading errors
Aug 31, 2021
c9cfcee
Add project info tests
Aug 31, 2021
e6a0216
Allow cache materialization in readonly projects
Sep 1, 2021
ec609bd
Fix filter dry-run
Sep 1, 2021
01a8640
Add requirements-default
Sep 1, 2021
45f3431
Update compare_dirs
Sep 1, 2021
7e6a0b0
Add fwd_kwargs in on_error_do
Sep 1, 2021
bc33149
Don't store dvc repo
Sep 1, 2021
0d6e171
Fix tree ctor type annotations
Sep 1, 2021
d0b2958
Merge branch 'develop' into zm/vcs-simple-exp
Sep 1, 2021
7173204
Fix image save on windows
Sep 1, 2021
d6909d1
revert changes
Sep 1, 2021
cbf4f77
Merge branch 'develop' into zm/vcs-simple-exp
Sep 2, 2021
de4668b
Add missing import
Sep 2, 2021
c1ad73f
Fix setup.py
Sep 2, 2021
453a913
Merge branch 'zm/vcs-simple-exp' of https://github.com/openvinotoolki…
Sep 2, 2021
84e4a00
Fix scoping issues (add api)
Sep 2, 2021
9b1c687
Replace rollback with scope
Sep 2, 2021
0f823cf
Update tests
Sep 2, 2021
655505a
Replace rollback uses
Sep 2, 2021
73d7b3f
Fix imports
Sep 2, 2021
e75c7ab
update changelog
Sep 2, 2021
baf6b88
Merge branch 'zm/add-scope' into zm/test-scoped-with-vcs
Sep 3, 2021
564957d
Fix add() type anns in Scope
Sep 3, 2021
51d871e
Replace rollback with scoped in the project
Sep 3, 2021
6b5034c
Update revpath tests
Sep 3, 2021
80d075a
Merge branch 'develop' into zm/test-scoped-with-vcs
Sep 6, 2021
ca1c60d
Update imports
Sep 6, 2021
a434eb8
Update on_error_do call
Sep 6, 2021
559e096
Update TestDir class
Sep 6, 2021
8323e2e
Fix windows file addition in git
Sep 6, 2021
5ea8e1a
Apply scoped to project tests
Sep 6, 2021
e773b86
Fix source dvcfile placement
Sep 7, 2021
83cc4fc
Fix winodws issues
Sep 7, 2021
ba5b78e
Update cli tests
Sep 7, 2021
c4dd0a8
Suppress extra window
Sep 7, 2021
cb4f0ab
Dont hide windows file femoval issues
Sep 7, 2021
2f71d7e
Merge commit 'df4a0d65d85bd3c528c887492a66a482cdb9e9af' into zm/vcs-s…
Sep 7, 2021
8f78e79
Merge pull request #445 from openvinotoolkit/zm/test-scoped-with-vcs
Sep 7, 2021
a0c5a7a
Make migration function static
Sep 7, 2021
7e83496
Add project migrate command, disallow auto migration
Sep 7, 2021
878fda7
Update migration tests
Sep 7, 2021
14f75b2
Reformat file
Sep 7, 2021
877ec12
Consider different source urls in migration
Sep 8, 2021
3ef8529
Prohibit inplace migrations
Sep 8, 2021
d67b8fc
Update migration command interface
Sep 8, 2021
8065bd1
Fix error message
Sep 8, 2021
1598342
Fix old project layout
Sep 8, 2021
e5791a2
Allow to skip problematic sources in migration
Sep 8, 2021
04308c8
Add cleanup on source migration failure
Sep 8, 2021
95e1fb2
Merge pull request #451 from openvinotoolkit/zm/fix-migration
Sep 8, 2021
c77e01e
Merge branch 'develop' into zm/vcs-simple-exp
Sep 8, 2021
520321d
Update changelog
Sep 8, 2021
9d9dd3a
Fix migration tests
Sep 8, 2021
883c3e0
Remove extra import
Sep 8, 2021
bca456b
Update changelog
Sep 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/health_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Installing dependencies
run: |
pip install tensorflow pytest pytest-cov
pip install -e ./
pip install -e .[default]
- name: Code instrumentation
run: |
pytest -v --cov --cov-report xml:coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Installing dependencies
run: |
pip install tensorflow pytest
pip install -e ./
pip install -e .[default]
- name: Unit testing
run: |
pytest -v
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Calling `ProjectDataset.transform()` with a string argument (<https://github.com/openvinotoolkit/datumaro/issues/402>)
- Attributes casting for CVAT format (<https://github.com/openvinotoolkit/datumaro/pull/403>)
- Loading of custom project plugins (<https://github.com/openvinotoolkit/datumaro/issues/404>)
- Reading, writing anno file and saving name of the subset for test subset
- Reading, writing anno file and saving name of the subset for test subset
(<https://github.com/openvinotoolkit/datumaro/pull/447>)

### Security
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include README.md
include requirements-core.txt
include requirements-core.txt
include requirements-default.txt
38 changes: 26 additions & 12 deletions datumaro/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from ..version import VERSION
from . import commands, contexts
from .util import CliException, add_subparser
from .util import add_subparser
from .util.errors import CliException

_log_levels = {
'debug': log.DEBUG,
Expand Down Expand Up @@ -59,22 +60,31 @@ def make_parser():
_LogManager._define_loglevel_option(parser)

known_contexts = [
('project', contexts.project, "Actions with project (deprecated)"),
('project', contexts.project, "Actions with project"),
('source', contexts.source, "Actions with data sources"),
('model', contexts.model, "Actions with models"),
]
known_commands = [
('create', commands.create, "Create project"),
('import', commands.import_, "Create project from existing dataset"),
("Project modification:", None, ''),
('create', commands.create, "Create empty project"),
('add', commands.add, "Add data source to project"),
('remove', commands.remove, "Remove data source from project"),

("", None, ''),
("Project versioning:", None, ''),
('checkout', commands.checkout, "Switch to another branch or revision"),
('commit', commands.commit, "Commit changes in tracked files"),
('log', commands.log, "List history"),
('status', commands.status, "Display current status"),

("", None, ''),
("Dataset and project operations:", None, ''),
('export', commands.export, "Export project in some format"),
('filter', commands.filter, "Filter project"),
('transform', commands.transform, "Transform project"),
('merge', commands.merge, "Merge projects"),
('convert', commands.convert, "Convert dataset into another format"),
('diff', commands.diff, "Compare projects with intersection"),
('ediff', commands.ediff, "Compare projects for equality"),
('filter', commands.filter, "Filter project items"),
('transform', commands.transform, "Modify project items"),
('merge', commands.merge, "Merge datasets"),
('convert', commands.convert, "Convert dataset between formats"),
('diff', commands.diff, "Compare datasets"),
('stats', commands.stats, "Compute project statistics"),
('info', commands.info, "Print project info"),
('explain', commands.explain, "Run Explainable AI algorithm for model"),
Expand Down Expand Up @@ -105,7 +115,8 @@ def make_parser():
subcommands = parser.add_subparsers(title=subcommands_desc,
description="", help=argparse.SUPPRESS)
for command_name, command, _ in known_contexts + known_commands:
add_subparser(subcommands, command_name, command.build_parser)
if command is not None:
add_subparser(subcommands, command_name, command.build_parser)

return parser

Expand All @@ -121,7 +132,10 @@ def main(args=None):
return 1

try:
return args.command(args)
retcode = args.command(args)
if retcode is None:
retcode = 0
return retcode
except CliException as e:
log.error(e)
return 1
Expand Down
4 changes: 2 additions & 2 deletions datumaro/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# pylint: disable=redefined-builtin

from . import (
add, convert, create, diff, ediff, explain, export, filter, import_, info,
merge, remove, stats, transform, validate,
add, checkout, commit, convert, create, diff, explain, export, filter, info,
log, merge, remove, stats, status, transform, validate,
)
70 changes: 70 additions & 0 deletions datumaro/cli/commands/checkout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

import argparse

from datumaro.util.scope import scope_add, scoped

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


def build_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor(help="Navigate to a revision",
description="""
Command forms:|n
1) %(prog)s <revision>|n
2) %(prog)s [--] <source1> ...|n
3) %(prog)s <revision> [--] <source1> <source2> ...|n
|n
1 - Restores a revision and all the sources in the working directory.|n
2, 3 - Restores only specified sources from the specified revision.|n
|s|sThe current revision is used, when not set.|n
|s|s"--" is optionally used to separate source names and revisions.|n
|n
Examples:|n
- Restore the previous revision:|n
|s|s%(prog)s HEAD~1 |n |n
- Restore the saved version of a source in the working tree|n
|s|s%(prog)s -- source-1 |n |n
- Restore a previous version of a source|n
|s|s%(prog)s 33fbfbe my-source
""", formatter_class=MultilineFormatter)

parser.add_argument('_positionals', nargs=argparse.REMAINDER,
help=argparse.SUPPRESS) # workaround for -- eaten by positionals
parser.add_argument('rev', nargs='?',
help="Commit or tag (default: current)")
parser.add_argument('sources', nargs='*',
help="Sources to restore (default: all)")
parser.add_argument('-f', '--force', action='store_true',
help="Allows to overwrite unsaved changes in case of conflicts "
"(default: %(default)s)")
parser.add_argument('-p', '--project', dest='project_dir', default='.',
help="Directory of the project to operate on (default: current dir)")
parser.set_defaults(command=checkout_command)

return parser

@scoped
def checkout_command(args):
has_sep = '--' in args._positionals
if has_sep:
pos = args._positionals.index('--')
if 1 < pos:
raise argparse.ArgumentError(None,
message="Expected no more than 1 revision argument")
else:
pos = 1
args.rev = (args._positionals[:pos] or [None])[0]
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
args.sources = args._positionals[pos + has_sep:]
if has_sep and not args.sources:
raise argparse.ArgumentError('sources', message="When '--' is used, "
"at least 1 source name must be specified")

project = scope_add(load_project(args.project_dir))

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

return 0
54 changes: 54 additions & 0 deletions datumaro/cli/commands/commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (C) 2020-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

import argparse

from datumaro.util.scope import scope_add, scoped

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


def build_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor(help="Create a revision",
description="""
Creates a new revision from the current state of the working directory.|n
|n
Examples:|n
- Create a revision:|n
|s|s%(prog)s -m "Added data"
""", formatter_class=MultilineFormatter)

parser.add_argument('-m', '--message', required=True, help="Commit message")
parser.add_argument('--allow-empty', action='store_true',
help="Allow commits with no changes (default: %(default)s)")
parser.add_argument('--allow-foreign', action='store_true',
help="Allow commits with non-Datumaro changes (default: %(default)s)")
parser.add_argument('--no-cache', action='store_true',
help="Don't put committed datasets into cache, "
"save only metainfo (default: %(default)s)")
parser.add_argument('-p', '--project', dest='project_dir', default='.',
help="Directory of the project to operate on (default: current dir)")
parser.set_defaults(command=commit_command)

return parser

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

old_tree = project.head

new_commit = project.commit(args.message, allow_empty=args.allow_empty,
allow_foreign=args.allow_foreign, no_cache=args.no_cache)

new_tree = project.working_tree
diff = project.diff(old_tree, new_tree)

print("Moved to commit '%s' %s" % (new_commit, args.message))
print(" %s targets changed" % len(diff))
for t, s in diff.items():
print(" %s %s" % (s.name, t))

return 0
51 changes: 30 additions & 21 deletions datumaro/cli/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,41 @@
from datumaro.util.os_util import make_file_name

from ..contexts.project import FilterModes
from ..util import CliException, MultilineFormatter
from ..util import MultilineFormatter
from ..util.errors import CliException
from ..util.project import generate_next_file_name


def build_parser(parser_ctor=argparse.ArgumentParser):
builtin_importers = sorted(Environment().importers.items)
builtin_converters = sorted(Environment().converters.items)
builtin_readers = sorted(
set(Environment().importers) | set(Environment().extractors))
builtin_writers = sorted(Environment().converters)

parser = parser_ctor(help="Convert an existing dataset to another format",
description="""
Converts a dataset from one format to another.
You can add your own formats using a project.|n
|n
Supported input formats: %s|n
|n
Supported output formats: %s|n
|n
Examples:|n
- Export a dataset as a PASCAL VOC dataset, include images:|n
|s|sconvert -i src/path -f voc -- --save-images|n
|n
- Export a dataset as a COCO dataset to a specific directory:|n
|s|sconvert -i src/path -f coco -o path/I/like/
""" % (', '.join(builtin_importers), ', '.join(builtin_converters)),
Converts a dataset from one format to another.
You can add your own formats and do many more by creating a
Datumaro project.|n
|n
This command serves as an alias for the "create", "add", and
"export" commands, allowing to obtain the same results simpler
and faster. Check descriptions of these commands for more info.|n
|n
Supported input formats: {}|n
|n
Supported output formats: {}|n
|n
Examples:|n
- Export a dataset as a PASCAL VOC dataset, include images:|n
|s|s%(prog)s -i src/path -f voc -- --save-images|n
|n
- Export a dataset as a COCO dataset to a specific directory:|n
|s|s%(prog)s -i src/path -f coco -o path/I/like/
""".format(', '.join(builtin_readers), ', '.join(builtin_writers)),
formatter_class=MultilineFormatter)

parser.add_argument('-i', '--input-path', default='.', dest='source',
help="Path to look for a dataset")
help="Input dataset path (default: current dir)")
parser.add_argument('-if', '--input-format',
help="Input dataset format. Will try to detect, if not specified.")
parser.add_argument('-f', '--output-format', required=True,
Expand All @@ -49,13 +56,15 @@ def build_parser(parser_ctor=argparse.ArgumentParser):
parser.add_argument('--overwrite', action='store_true',
help="Overwrite existing files in the save directory")
parser.add_argument('-e', '--filter',
help="Filter expression for dataset items")
help="XML XPath filter expression for dataset items. Read \"filter\" "
"command docs for more info")
parser.add_argument('--filter-mode', default=FilterModes.i.name,
type=FilterModes.parse,
help="Filter mode (options: %s; default: %s)" % \
help="Filter mode, one of %s (default: %s)" % \
(', '.join(FilterModes.list_options()) , '%(default)s'))
parser.add_argument('extra_args', nargs=argparse.REMAINDER,
help="Additional arguments for output format (pass '-- -h' for help)")
help="Additional arguments for output format (pass '-- -h' for help). "
"Must be specified after the main command arguments")
parser.set_defaults(command=convert_command)

return parser
Expand Down
56 changes: 52 additions & 4 deletions datumaro/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,56 @@
#
# SPDX-License-Identifier: MIT

from ..contexts.project import build_create_parser as build_parser
import argparse
import logging as log
import os
import os.path as osp

__all__ = [
'build_parser',
]
from datumaro.components.project import Project
from datumaro.util.os_util import rmtree

from ..util import MultilineFormatter
from ..util.errors import CliException


def build_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor(help="Create empty project",
description="""
Create an empty Datumaro project. A project is required for the most of
Datumaro functionality.|n
|n
Examples:|n
- Create a project in the current directory:|n
|s|s%(prog)s|n
|n
- Create a project in other directory:|n
|s|s%(prog)s -o path/I/like/
""",
formatter_class=MultilineFormatter)

parser.add_argument('-o', '--output-dir', default='.', dest='dst_dir',
help="Save directory for the new project (default: current dir")
parser.add_argument('--overwrite', action='store_true',
help="Overwrite existing files in the save directory")
parser.set_defaults(command=create_command)

return parser

def create_command(args):
project_dir = osp.abspath(args.dst_dir)

existing_project_dir = Project.find_project_dir(project_dir)
if existing_project_dir and os.listdir(existing_project_dir):
if args.overwrite:
rmtree(existing_project_dir)
else:
raise CliException("Directory '%s' already exists "
"(pass --overwrite to overwrite)" % existing_project_dir)

log.info("Creating project at '%s'" % project_dir)

Project.init(project_dir)

log.info("Project has been created at '%s'" % project_dir)

return 0
Loading