Skip to content

Commit 9ef0260

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Added http session
1 parent cbf536b commit 9ef0260

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/superannotate/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import os
12
import logging.config
23

4+
from version import __version__
35
from superannotate.lib.app.analytics.class_analytics import attribute_distribution
46
from superannotate.lib.app.analytics.class_analytics import class_distribution
57
from superannotate.lib.app.annotation_helpers import add_annotation_bbox_to_json
@@ -156,6 +158,7 @@
156158

157159

158160
__all__ = [
161+
"__version__",
159162
# Utils
160163
"AppException",
161164
#
@@ -287,7 +290,7 @@
287290
]
288291

289292
__author__ = "Superannotate"
290-
import os
293+
291294

292295
file_dir = os.path.split(os.path.realpath(__file__))[0]
293296

src/superannotate/lib/core/usecases.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,7 @@ def execute(self):
129129
if not projects:
130130
self._response.errors = AppException("Project not found.")
131131
else:
132-
for project in projects:
133-
if project.name == self._name:
134-
self._response.data = project
135-
break
132+
self._response.data = next(project for project in projects if project.name == self._name)
136133
return self._response
137134

138135

@@ -1972,6 +1969,8 @@ def execute(self):
19721969

19731970
if self._include_contributors:
19741971
data["contributors"] = project.users
1972+
else:
1973+
project.users = []
19751974

19761975
self._response.data = data
19771976
return self._response

src/superannotate/lib/infrastructure/services.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88

99
import lib.core as constance
1010
import requests.packages.urllib3
11+
import requests.adapters
1112
from lib.core.exceptions import AppException
1213
from lib.core.serviceproviders import SuerannotateServiceProvider
1314
from requests.exceptions import HTTPError
15+
from lib.infrastructure.helpers import timed_lru_cache
1416

1517
requests.packages.urllib3.disable_warnings()
1618

1719

1820
class BaseBackendService(SuerannotateServiceProvider):
1921
AUTH_TYPE = "sdk"
2022
PAGINATE_BY = 100
23+
MAX_RETRY = 3
2124

2225
"""
2326
Base service class
@@ -31,8 +34,8 @@ def __init__(self, api_url: str, auth_token: str, logger, paginate_by=None):
3134
self.team_id = auth_token.split("=")[-1]
3235
self._session = None
3336

34-
@property
35-
def session(self):
37+
@timed_lru_cache(seconds=360)
38+
def get_session(self):
3639
if not self._session:
3740
self._session = requests.Session()
3841
self._session.headers.update(self.default_headers)
@@ -77,8 +80,9 @@ def _request(
7780
) -> requests.Response:
7881
kwargs = {"json": data} if data else {}
7982
headers_dict = self.default_headers.copy()
80-
self.session.headers.update(headers if headers else {})
81-
method = getattr(self.session, method)
83+
session = self.get_session()
84+
session.headers.update(headers if headers else {})
85+
method = getattr(session, method)
8286
with self.safe_api():
8387
response = method(
8488
url, **kwargs, headers=headers_dict, params=params, timeout=60,

tests/integration/test_interface.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ def test_delete_folder(self):
4545
print(sa.search_folders(self.PROJECT_NAME))
4646
with self.assertRaises(AppException):
4747
sa.delete_folders(self.PROJECT_NAME, ["non-existing folder"])
48+
49+
def test_get_project_metadata(self):
50+
metadata = sa.get_project_metadata(self.PROJECT_NAME)
51+
self.assertIsNotNone(metadata["id"])
52+
self.assertListEqual(metadata.get("contributors", []), [])
53+
metadata_with_users = sa.get_project_metadata(self.PROJECT_NAME, include_contributors=True)
54+
self.assertIsNotNone(metadata_with_users.get("contributors"))

tests/profiling/profiling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import time
44

55

6-
76
stat = time.time()
87
sa.search_annotation_classes("Vector Project")
98
end = time.time()

0 commit comments

Comments
 (0)