Skip to content

Commit 6d1e644

Browse files
authored
Merge pull request #272 from superannotateai/friday
Friday
2 parents 54fb559 + 369ecc1 commit 6d1e644

File tree

11 files changed

+179
-56
lines changed

11 files changed

+179
-56
lines changed

src/superannotate/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import os
33
import sys
44

5+
import requests
6+
import superannotate.lib.core as constances
7+
from packaging.version import parse
58
from superannotate.lib.app.analytics.class_analytics import attribute_distribution
69
from superannotate.lib.app.analytics.class_analytics import class_distribution
710
from superannotate.lib.app.annotation_helpers import add_annotation_bbox_to_json
@@ -298,9 +301,27 @@
298301

299302
__author__ = "Superannotate"
300303

304+
301305
WORKING_DIR = os.path.split(os.path.realpath(__file__))[0]
302306
sys.path.append(WORKING_DIR)
303307
logging.getLogger("botocore").setLevel(logging.CRITICAL)
304308
logging.config.fileConfig(
305309
os.path.join(WORKING_DIR, "logging.conf"), disable_existing_loggers=False
306310
)
311+
312+
local_version = parse(__version__)
313+
if local_version.is_prerelease:
314+
logging.info(constances.PACKAGE_VERSION_INFO_MESSAGE.format(__version__))
315+
req = requests.get('https://pypi.python.org/pypi/superannotate/json')
316+
if req.ok:
317+
releases = req.json().get('releases', [])
318+
pip_version = parse('0')
319+
for release in releases:
320+
ver = parse(release)
321+
if not ver.is_prerelease or local_version.is_prerelease:
322+
pip_version = max(pip_version, ver)
323+
if pip_version.major > local_version.major:
324+
logging.warning(constances.PACKAGE_VERSION_MAJOR_UPGRADE.format(local_version, pip_version))
325+
elif pip_version > local_version:
326+
logging.warning(constances.PACKAGE_VERSION_UPGRADE.format(local_version, pip_version)
327+
)

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,8 +2315,11 @@ def attach_image_urls_to_project(
23152315
constances.ProjectType.VIDEO.value,
23162316
constances.ProjectType.DOCUMENT.value,
23172317
]:
2318-
raise AppException(LIMITED_FUNCTIONS[project["project"].project_type])
2319-
2318+
raise AppException(
2319+
constances.INVALID_PROJECT_TYPE_TO_PROCESS.format(
2320+
constances.ProjectType.get_name(project["project"].project_type)
2321+
)
2322+
)
23202323
images_to_upload, duplicate_images = get_paths_and_duplicated_from_csv(attachments)
23212324
use_case = controller.interactive_attach_urls(
23222325
project_name=project_name,
@@ -2374,8 +2377,12 @@ def attach_video_urls_to_project(
23742377
project = controller.get_project_metadata(project_name).data
23752378
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
23762379

2377-
if not project["project"].project_type == constances.ProjectType.VIDEO.value:
2378-
raise AppException(LIMITED_FUNCTIONS[project["project"].project_type])
2380+
if project["project"].project_type != constances.ProjectType.VIDEO.value:
2381+
raise AppException(
2382+
constances.INVALID_PROJECT_TYPE_TO_PROCESS.format(
2383+
constances.ProjectType.get_name(project["project"].project_type)
2384+
)
2385+
)
23792386

23802387
images_to_upload, duplicate_images = get_paths_and_duplicated_from_csv(attachments)
23812388
use_case = controller.interactive_attach_urls(
@@ -3585,8 +3592,12 @@ def attach_document_urls_to_project(
35853592
project = controller.get_project_metadata(project_name).data
35863593
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
35873594

3588-
if not project["project"].project_type == constances.ProjectType.DOCUMENT.value:
3589-
raise AppException(LIMITED_FUNCTIONS[project["project"].project_type])
3595+
if project["project"].project_type != constances.ProjectType.DOCUMENT.value:
3596+
raise AppException(
3597+
constances.INVALID_PROJECT_TYPE_TO_PROCESS.format(
3598+
constances.ProjectType.get_name(project["project"].project_type)
3599+
)
3600+
)
35903601

35913602
images_to_upload, duplicate_images = get_paths_and_duplicated_from_csv(attachments)
35923603

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
TOKEN = "ca95ed96f80e8ec3be791e2d3097cf51"
1+
TOKEN = "e741d4863e7e05b1a45833d01865ef0d"

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def search_annotation_classes(*args, **kwargs):
358358
"event_name": "search_annotation_classes",
359359
"properties": {
360360
"project_name": get_project_name(project),
361-
"name_prefix": name_prefix,
361+
"Prefix": bool(name_prefix),
362362
},
363363
}
364364

src/superannotate/lib/core/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
ATTACHING_UPLOAD_STATE_ERROR = "You cannot attach URLs in this type of project. Please attach it in an external storage project."
6464
UPLOADING_UPLOAD_STATE_ERROR = "You cannot upload files in this type of project. Please upload it in an basic storage project."
6565

66+
INVALID_PROJECT_TYPE_TO_PROCESS = "The function does not support projects of type {}."
6667
DEPRECATED_VIDEO_PROJECTS_MESSAGE = (
6768
"The function does not support projects containing videos attached with URLs"
6869
)
@@ -101,6 +102,15 @@
101102
)
102103
MOVE_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to move exceeds the limit of 500 000 items per project."
103104

105+
PACKAGE_VERSION_INFO_MESSAGE = "Development version {} of SuperAnnotate SDK is being used."
106+
107+
PACKAGE_VERSION_MAJOR_UPGRADE = "There is a major upgrade of SuperAnnotate Python SDK available on PyPI. " \
108+
"We recommend upgrading. Run 'pip install --upgrade superannotate' to " \
109+
"upgrade from your version {} to {}."
110+
111+
PACKAGE_VERSION_UPGRADE = "There is a newer version of SuperAnnotate Python SDK available on PyPI." \
112+
" Run 'pip install --upgrade superannotate' to" \
113+
" upgrade from your version {} to {}"
104114
__alL__ = (
105115
ProjectType,
106116
UserRole,

src/superannotate/lib/core/usecases/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,7 @@ def execute(self):
763763
image_ids=image_ids,
764764
)
765765
if not res.ok:
766-
self._response.errors = res.json().get("error")
767-
return self._response
766+
res.raise_for_status()
768767

769768
success_images = []
770769
failed_images = []
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
11
import os
22
from os.path import dirname
3+
from os.path import join
34

45
import src.superannotate as sa
6+
from src.superannotate import AppException
7+
import src.superannotate.lib.core as constances
58
from tests.integration.base import BaseTestCase
69

710

811
class TestDocumentUrls(BaseTestCase):
912
PROJECT_NAME = "document attach urls"
10-
PATH_TO_URLS = "data_set/csv_files/text_urls.csv"
11-
PATH_TO_50K_URLS = "data_set/501_urls.csv"
13+
PATH_TO_URLS = "csv_files/text_urls.csv"
14+
PATH_TO_50K_URLS = "501_urls.csv"
1215
PROJECT_DESCRIPTION = "desc"
1316
PROJECT_TYPE = "Document"
1417

18+
@property
19+
def csv_path(self):
20+
return os.path.join(dirname(dirname(__file__)), "data_set")
21+
1522
def test_attach_documents_urls(self):
1623
uploaded, could_not_upload, existing_images = sa.attach_document_urls_to_project(
1724
self.PROJECT_NAME,
18-
os.path.join(dirname(dirname(__file__)), self.PATH_TO_URLS),
25+
join(self.csv_path, self.PATH_TO_URLS)
1926
)
2027
self.assertEqual(len(uploaded), 11)
2128
self.assertEqual(len(could_not_upload), 0)
2229
self.assertEqual(len(existing_images), 1)
2330

2431
uploaded, could_not_upload, existing_images = sa.attach_document_urls_to_project(
2532
self.PROJECT_NAME,
26-
os.path.join(dirname(dirname(__file__)), self.PATH_TO_URLS),
33+
join(self.csv_path, self.PATH_TO_URLS),
2734
)
2835
self.assertEqual(len(uploaded), 2)
2936
self.assertEqual(len(could_not_upload), 0)
3037
self.assertEqual(len(existing_images), 10)
3138

39+
def test_attach_video_urls_to_vector_project(self):
40+
try:
41+
sa.create_project("1", "!", "vector")
42+
with self.assertRaisesRegexp(AppException, constances.INVALID_PROJECT_TYPE_TO_PROCESS.format("Vector")):
43+
sa.attach_document_urls_to_project("1", join(self.csv_path, self.PATH_TO_URLS),)
44+
except AssertionError:
45+
raise
46+
except Exception:
47+
sa.delete_project("1")
3248

3349
def test_limitation(self):
3450
self.assertRaises(
3551
Exception,
3652
sa.attach_document_urls_to_project,
3753
self.PROJECT_NAME,
38-
os.path.join(dirname(dirname(__file__)), self.PATH_TO_50K_URLS)
54+
join(self.csv_path, self.PATH_TO_50K_URLS)
3955
)

tests/integration/test_attach_video_urls.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from os.path import dirname
33

44
import src.superannotate as sa
5+
from src.superannotate import AppException
6+
import src.superannotate.lib.core as constances
57
from tests.integration.base import BaseTestCase
68

79

@@ -19,7 +21,7 @@ def csv_path(self):
1921

2022
@property
2123
def csv_path_without_name_column(self):
22-
return os.path.join(dirname(dirname(__file__)), self.PATH_TO_URLS)
24+
return os.path.join(dirname(dirname(__file__)), self.PATH_TO_URLS_WITHOUT_NAMES)
2325

2426
def test_attach_video_urls(self):
2527
uploaded, could_not_upload, existing_images = sa.attach_video_urls_to_project(
@@ -30,14 +32,24 @@ def test_attach_video_urls(self):
3032
self.assertEqual(len(could_not_upload), 0)
3133
self.assertEqual(len(existing_images), 1)
3234

35+
def test_attach_video_urls_to_vector_project(self):
36+
try:
37+
sa.create_project("1", "!", "vector")
38+
with self.assertRaisesRegexp(AppException, constances.INVALID_PROJECT_TYPE_TO_PROCESS.format("Vector")):
39+
sa.attach_video_urls_to_project("1", self.csv_path)
40+
except AssertionError:
41+
raise
42+
except Exception:
43+
sa.delete_project("1")
44+
3345
def test_attach_video_urls_without_name_column(self):
3446
uploaded, could_not_upload, existing_images = sa.attach_video_urls_to_project(
3547
self.PROJECT_NAME,
3648
self.csv_path_without_name_column
3749
)
38-
self.assertEqual(len(uploaded), 7)
50+
self.assertEqual(len(uploaded), 8)
3951
self.assertEqual(len(could_not_upload), 0)
40-
self.assertEqual(len(existing_images), 1)
52+
self.assertEqual(len(existing_images), 0)
4153

4254
def test_get_exports(self):
4355
sa.attach_video_urls_to_project(

tests/integration/test_depricated_functions_document.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import src.superannotate as sa
66
from src.superannotate import AppException
77
from src.superannotate.lib.core import LIMITED_FUNCTIONS
8+
from src.superannotate.lib.core import INVALID_PROJECT_TYPE_TO_PROCESS
89
from src.superannotate.lib.core import ProjectType
910
from src.superannotate.lib.core import DEPRICATED_DOCUMENT_VIDEO_MESSAGE
1011

@@ -21,6 +22,7 @@ class TestDeprecatedFunctionsDocument(TestCase):
2122
PROJECT_DESCRIPTION_2 = "second project"
2223
PROJECT_TYPE_2 = "Vector"
2324
EXCEPTION_MESSAGE = LIMITED_FUNCTIONS[ProjectType.DOCUMENT.value]
25+
EXCEPTION_MESSAGE_2 = INVALID_PROJECT_TYPE_TO_PROCESS
2426
EXCEPTION_MESSAGE_DOCUMENT_VIDEO = DEPRICATED_DOCUMENT_VIDEO_MESSAGE
2527

2628
def setUp(self, *args, **kwargs):
@@ -106,7 +108,7 @@ def test_deprecated_functions(self):
106108
os.path.join(dirname(dirname(__file__)), self.PATH_TO_URLS),
107109
)
108110
except AppException as e:
109-
self.assertIn(self.EXCEPTION_MESSAGE, str(e))
111+
self.assertIn(self.EXCEPTION_MESSAGE_2.format(self.PROJECT_TYPE), str(e))
110112
try:
111113
sa.clone_project(self.PROJECT_NAME_2, self.PROJECT_NAME)
112114
except AppException as e:
@@ -194,7 +196,7 @@ def test_deprecated_functions(self):
194196
os.path.join(dirname(dirname(__file__)), self.PATH_TO_URLS),
195197
)
196198
except AppException as e:
197-
self.assertIn(self.EXCEPTION_MESSAGE, str(e))
199+
self.assertIn(self.EXCEPTION_MESSAGE_2.format(self.PROJECT_TYPE), str(e))
198200
try:
199201
sa.benchmark(self.PROJECT_NAME, "some", ["some folder1"])
200202
except AppException as e:

0 commit comments

Comments
 (0)