Skip to content

Commit

Permalink
Addes --yes flag to skip prompts when importing (#360)
Browse files Browse the repository at this point in the history
* added --yes flag for skipping prompts when importing
  • Loading branch information
simedw authored Feb 25, 2022
1 parent cef92a9 commit 81dd77e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
10 changes: 8 additions & 2 deletions darwin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _run(args: Namespace, parser: ArgumentParser) -> None:
elif args.action == "pull":
f.pull_dataset(args.dataset, args.only_annotations, args.folders, args.video_frames)
elif args.action == "import":
f.dataset_import(args.dataset, args.format, args.files, args.append)
f.dataset_import(args.dataset, args.format, args.files, args.append, not args.yes)
elif args.action == "convert":
f.dataset_convert(args.dataset, args.format, args.output_dir)
elif args.action == "set-file-status":
Expand All @@ -125,7 +125,13 @@ def _run(args: Namespace, parser: ArgumentParser) -> None:
f.help(parser, "dataset")
elif args.action == "comment":
f.post_comment(
args.dataset, args.file, args.text, args.x, args.y, args.w, args.h,
args.dataset,
args.file,
args.text,
args.x,
args.y,
args.w,
args.h,
)


Expand Down
12 changes: 8 additions & 4 deletions darwin/cli_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,15 @@ def file_upload_callback(file_name, file_total_bytes, file_bytes_sent):

if already_existing_items:
console.print(
f"Skipped {len(already_existing_items)} files already in the dataset.\n", style="warning",
f"Skipped {len(already_existing_items)} files already in the dataset.\n",
style="warning",
)

if upload_manager.error_count or other_skipped_items:
error_count = upload_manager.error_count + len(other_skipped_items)
console.print(
f"{error_count} files couldn't be uploaded because an error occurred.\n", style="error",
f"{error_count} files couldn't be uploaded because an error occurred.\n",
style="error",
)

if not verbose and upload_manager.error_count:
Expand Down Expand Up @@ -659,7 +661,9 @@ def file_upload_callback(file_name, file_total_bytes, file_bytes_sent):
_error(f"No files found")


def dataset_import(dataset_slug: str, format: str, files: List[PathLike], append: bool) -> None:
def dataset_import(
dataset_slug: str, format: str, files: List[PathLike], append: bool, class_prompt: bool = True
) -> None:
"""
Imports annotation files to the given dataset.
Exits the application if no dataset with the given slug is found.
Expand All @@ -682,7 +686,7 @@ def dataset_import(dataset_slug: str, format: str, files: List[PathLike], append
try:
parser: ImportParser = get_importer(format)
dataset: RemoteDataset = client.get_remote_dataset(dataset_identifier=dataset_slug)
import_annotations(dataset, parser, files, append)
import_annotations(dataset, parser, files, append, class_prompt)
except ImporterNotFoundError:
_error(f"Unsupported import format: {format}, currently supported: {import_formats}")
except AttributeError:
Expand Down
15 changes: 9 additions & 6 deletions darwin/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def import_annotations(
importer: Callable[[Path], Union[List[dt.AnnotationFile], dt.AnnotationFile, None]],
file_paths: List[PathLike],
append: bool,
class_prompt: bool = True,
) -> None:
"""
Imports the given given Annotations into the given Dataset.
Expand All @@ -132,15 +133,17 @@ def import_annotations(
Dataset where the Annotations will be imported to.
importer : Callable[[Path], Union[List[dt.AnnotationFile], dt.AnnotationFile, None]]
Parsing module containing the logic to parse the given Annotation files given in
`files_path`. See `importer/format` for a list of out of supported parsers.
``files_path``. See ``importer/format`` for a list of out of supported parsers.
file_paths : List[PathLike]
A list of `Path`'s or strings containing the Annotations we wish to import.
A list of ``Path``'s or strings containing the Annotations we wish to import.
append : bool
If `True` appends the given annotations to the datasets. If `False` will override them.
If ``True`` appends the given annotations to the datasets. If ``False`` will override them.
class_prompt : bool
If ``False`` classes will be created and added to the datasets without requiring a user's prompt.
Returns
-------
None
None
Raises
-------
Expand Down Expand Up @@ -190,7 +193,7 @@ def import_annotations(
for local_file in local_files_missing_remotely:
print(f"\t{local_file.path}: '{local_file.full_path}'")

if not secure_continue_request():
if class_prompt and not secure_continue_request():
return

local_classes_not_in_dataset, local_classes_not_in_team = _resolve_annotation_classes(
Expand All @@ -216,7 +219,7 @@ def import_annotations(
print(
f"\t{missing_class.name}, type: {missing_class.annotation_internal_type or missing_class.annotation_type}"
)
if not secure_continue_request():
if class_prompt and not secure_continue_request():
return
for missing_class in local_classes_not_in_team:
dataset.create_annotation_class(
Expand Down
3 changes: 3 additions & 0 deletions darwin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def __init__(self):

parser_import.add_argument("files", type=str, nargs="+", help="Annotation files (or folders) to import.")
parser_import.add_argument("--append", action="store_true", help="Append annotations instead of overwriting.")
parser_import.add_argument(
"--yes", action="store_true", help="Skips prompts for creating and adding classes to dataset"
)

# Convert
parser_convert = dataset_action.add_parser("convert", help="Converts darwin json to other annotation formats.")
Expand Down
1 change: 0 additions & 1 deletion tests/darwin/cli_functions_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import builtins
import logging
import sys
from unittest.mock import call, patch

Expand Down

0 comments on commit 81dd77e

Please sign in to comment.