Skip to content

Commit 6af69cc

Browse files
committed
Fix cli export
1 parent 1613a5c commit 6af69cc

File tree

8 files changed

+64
-17
lines changed

8 files changed

+64
-17
lines changed

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pip install -e .
1717
# pip install superannotate
1818

1919
# for testing
20-
pip install pytest pytest-xdist
20+
pip install pytest pytest-xdist pytest-timeout
2121

2222
# for coverage
2323
pip install coverage pytest-cov

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
timeout = 300
3+
timeout_method=thread

superannotate/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,16 @@ def export_project(command_name, args):
318318

319319
parts = args.project.split('/')
320320
if len(parts) == 1:
321-
project, folder = parts[0], None
321+
project, project_folder = parts[0], None
322322
elif len(parts) == 2:
323-
project, folder = parts
323+
project, project_folder = parts
324324
else:
325325
raise SABaseException(
326326
0, "Project should be in format <project>[/<folder>]"
327327
)
328328
export = sa.prepare_export(
329-
project, [folder],
329+
project,
330+
None if project_folder is None else [project_folder],
330331
annotation_statuses=args.annotation_statuses,
331332
include_fuse=args.include_fuse
332333
)

superannotate/annotation_helpers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
from .exceptions import SABaseException
66

77

8-
def _create_empty_annotation_json():
9-
return {"instances": [], "metadata": {}, "comments": [], "tags": []}
8+
def fill_in_missing(annotation_json):
9+
for field in ["instances", "comments", "tags"]:
10+
if field not in annotation_json:
11+
annotation_json[field] = []
12+
if "metadata" not in annotation_json:
13+
annotation_json["metadata"] = {}
1014

1115

1216
def _preprocess_annotation_json(annotation_json):
@@ -15,7 +19,10 @@ def _preprocess_annotation_json(annotation_json):
1519
path = annotation_json
1620
annotation_json = json.load(open(annotation_json))
1721
elif annotation_json is None:
18-
annotation_json = _create_empty_annotation_json()
22+
annotation_json = {}
23+
24+
fill_in_missing(annotation_json)
25+
1926
return (annotation_json, path)
2027

2128

superannotate/db/annotation_classes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ def download_annotation_classes_json(project, folder):
296296

297297

298298
def fill_class_and_attribute_names(annotations_json, annotation_classes_dict):
299+
if "instances" not in annotations_json:
300+
return
299301
for r in annotations_json["instances"]:
300302
if "classId" not in r or r["classId"] not in annotation_classes_dict:
301303
continue
@@ -319,6 +321,8 @@ def fill_class_and_attribute_names(annotations_json, annotation_classes_dict):
319321

320322

321323
def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
324+
if "instances" not in annotation_json:
325+
return
322326
for ann in annotation_json["instances"]:
323327
if "className" not in ann:
324328
logger.warning("No className in annotation instance")

superannotate/db/images.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
add_annotation_bbox_to_json, add_annotation_comment_to_json,
1515
add_annotation_cuboid_to_json, add_annotation_ellipse_to_json,
1616
add_annotation_point_to_json, add_annotation_polygon_to_json,
17-
add_annotation_polyline_to_json, add_annotation_template_to_json
17+
add_annotation_polyline_to_json, add_annotation_template_to_json,
18+
fill_in_missing
1819
)
1920
from ..api import API
2021
from ..exceptions import SABaseException
@@ -748,6 +749,8 @@ def _get_image_pre_or_annotations(project, image_name, pre):
748749
f"{pre}annotation_mask_filename": None
749750
}
750751
)
752+
753+
fill_in_missing(result[f"{pre}annotation_json"])
751754
return result
752755

753756

tests/test_cli.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def test_cli_image_upload_project_export(tmpdir):
2222
shell=True
2323
)
2424
project = PROJECT_NAME
25+
subprocess.run(
26+
f'superannotatecli create-folder --project "{PROJECT_NAME}" --name folder1',
27+
check=True,
28+
shell=True
29+
)
2530
sa.create_annotation_classes_from_classes_json(
2631
PROJECT_NAME, "./tests/sample_recursive_test/classes/classes.json"
2732
)
@@ -40,25 +45,49 @@ def test_cli_image_upload_project_export(tmpdir):
4045
time.sleep(1)
4146
assert len(sa.search_images(project)) == 2
4247

48+
subprocess.run(
49+
f'superannotatecli upload-images --project "{PROJECT_NAME}/folder1" --folder ./tests/sample_recursive_test --extensions=jpg --set-annotation-status QualityCheck',
50+
check=True,
51+
shell=True
52+
)
53+
time.sleep(1)
54+
assert len(sa.search_images(f"{PROJECT_NAME}/folder1")) == 1
55+
4356
sa.upload_annotations_from_folder_to_project(
4457
project, "./tests/sample_recursive_test"
4558
)
59+
test_dir1 = tmpdir / "test1"
60+
test_dir1.mkdir()
61+
subprocess.run(
62+
f'superannotatecli export-project --project "{PROJECT_NAME}" --folder {test_dir1}',
63+
check=True,
64+
shell=True
65+
)
66+
67+
assert len(list(test_dir1.glob("*.json"))) == 1
68+
assert len(list(test_dir1.glob("*.jpg"))) == 0
69+
assert len(list(test_dir1.glob("*.png"))) == 0
70+
71+
test_dir2 = tmpdir / "test2"
72+
test_dir2.mkdir()
4673
subprocess.run(
47-
f'superannotatecli export-project --project "{PROJECT_NAME}" --folder {tmpdir}',
74+
f'superannotatecli export-project --project "{PROJECT_NAME}" --folder {test_dir2} --include-fuse',
4875
check=True,
4976
shell=True
5077
)
5178

52-
assert len(list(tmpdir.glob("*.json"))) == 1
53-
assert len(list(tmpdir.glob("*.jpg"))) == 0
54-
assert len(list(tmpdir.glob("*.png"))) == 0
79+
assert len(list(test_dir2.glob("*.json"))) == 1
80+
assert len(list(test_dir2.glob("*.jpg"))) == 1
81+
assert len(list(test_dir2.glob("*.png"))) == 1
5582

83+
test_dir3 = tmpdir / "test3"
84+
test_dir3.mkdir()
5685
subprocess.run(
57-
f'superannotatecli export-project --project "{PROJECT_NAME}" --folder {tmpdir} --include-fuse',
86+
f'superannotatecli export-project --project "{PROJECT_NAME}/folder1" --folder {test_dir3}',
5887
check=True,
5988
shell=True
6089
)
6190

62-
assert len(list(tmpdir.glob("*.json"))) == 1
63-
assert len(list(tmpdir.glob("*.jpg"))) == 1
64-
assert len(list(tmpdir.glob("*.png"))) == 1
91+
assert len(list(test_dir3.glob("*.json"))) == 1
92+
assert len(list(test_dir3.glob("*.jpg"))) == 0
93+
assert len(list(test_dir3.glob("*.png"))) == 0

tests/test_folders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_copy_images(tmpdir):
276276

277277
ann2 = sa.get_image_annotations(project2, "example_image_2.jpg")
278278

279-
assert "instances" not in ann2["annotation_json"]
279+
assert len(ann2["annotation_json"]["instances"]) == 0
280280

281281
num_images = sa.get_project_image_count(project2)
282282
assert num_images == 2

0 commit comments

Comments
 (0)