synapse-sdk 1.0.0a14__py3-none-any.whl → 1.0.0a16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of synapse-sdk might be problematic. Click here for more details.

@@ -62,7 +62,7 @@ class BaseClient:
62
62
  response = self._request('get', path, **kwargs)
63
63
  if url_conversion:
64
64
  if url_conversion['is_list']:
65
- files_url_to_path_from_objs(response['results'], **url_conversion)
65
+ files_url_to_path_from_objs(response['results'], **url_conversion, is_async=True)
66
66
  else:
67
67
  files_url_to_path_from_objs(response, **url_conversion)
68
68
  return response
@@ -80,14 +80,14 @@ class BaseClient:
80
80
  return self._request('delete', path, **kwargs)
81
81
 
82
82
  def _list(self, path, url_conversion=None, list_all=False, **kwargs):
83
- response = self._get(path, url_conversion, **kwargs)
83
+ response = self._get(path, **kwargs)
84
84
  if list_all:
85
85
  return self._list_all(path, url_conversion, **kwargs), response['count']
86
86
  else:
87
87
  return response
88
88
 
89
- def _list_all(self, path, url_conversion=None, **kwargs):
90
- response = self._get(path, url_conversion, **kwargs)
89
+ def _list_all(self, path, url_conversion=None, params=None, **kwargs):
90
+ response = self._get(path, url_conversion, params=params, **kwargs)
91
91
  yield from response['results']
92
92
  if response['next']:
93
93
  yield from self._list_all(response['next'], url_conversion, **kwargs)
@@ -92,13 +92,15 @@ class Action:
92
92
  @property
93
93
  def debug_modules(self):
94
94
  debug_modules = []
95
- for module_path in self.envs.get('SYNAPSE_DEBUG_MODULES', '').split(','):
96
- if module_path.startswith('https://'): # TODO ray에서 지원하는 remote uri 형식 (https, s3, gs) 모두 지원
97
- module_url = module_path
98
- else:
99
- module_url = build_and_upload(module_path, self.plugin_storage_url)
100
- debug_modules.append(module_url)
101
- self.envs['SYNAPSE_DEBUG_MODULES'] = ','.join(debug_modules)
95
+ if self.envs.get('SYNAPSE_DEBUG_MODULES'):
96
+ for module_path in self.envs['SYNAPSE_DEBUG_MODULES'].split(','):
97
+ # TODO ray에서 지원하는 remote uri 형식 (https, s3, gs) 모두 지원
98
+ if module_path.startswith('https://'):
99
+ module_url = module_path
100
+ else:
101
+ module_url = build_and_upload(module_path, self.plugin_storage_url)
102
+ debug_modules.append(module_url)
103
+ self.envs['SYNAPSE_DEBUG_MODULES'] = ','.join(debug_modules)
102
104
  return debug_modules
103
105
 
104
106
  def get_run(self):
@@ -26,7 +26,8 @@ def publish(ctx, host, user_token, tenant, debug_modules):
26
26
 
27
27
  data = {'plugin': plugin_release.plugin, 'file': str(archive_path), 'debug': debug}
28
28
  if debug:
29
- data['debug_meta'] = json.dumps({'modules': debug_modules.split(',')})
29
+ if debug_modules:
30
+ data['debug_meta'] = json.dumps({'modules': debug_modules.split(',')})
30
31
 
31
32
  client = BackendClient(host, user_token, tenant=tenant)
32
33
  client.create_plugin_release(data)
@@ -86,28 +86,26 @@ class Run:
86
86
  logger = None
87
87
  job_id = None
88
88
  context = None
89
+ client = None
89
90
 
90
91
  def __init__(self, job_id, context):
91
92
  self.job_id = job_id
92
93
  self.context = context
94
+ self.client = BackendClient(
95
+ self.context['envs']['SYNAPSE_PLUGIN_RUN_HOST'],
96
+ self.context['envs']['SYNAPSE_PLUGIN_RUN_USER_TOKEN'],
97
+ self.context['envs']['SYNAPSE_PLUGIN_RUN_TENANT'],
98
+ )
93
99
  self.set_logger()
94
100
 
95
101
  def set_logger(self):
96
102
  kwargs = {'progress_categories': self.context['progress_categories']}
103
+
97
104
  if self.job_id:
98
- client = BackendClient(
99
- self.context['envs']['SYNAPSE_PLUGIN_RUN_HOST'],
100
- self.context['envs']['SYNAPSE_PLUGIN_RUN_USER_TOKEN'],
101
- self.context['envs']['SYNAPSE_PLUGIN_RUN_TENANT'],
102
- )
103
- self.logger = BackendLogger(client, self.job_id, **kwargs)
105
+ self.logger = BackendLogger(self.client, self.job_id, **kwargs)
104
106
  else:
105
107
  self.logger = ConsoleLogger(**kwargs)
106
108
 
107
- @property
108
- def client(self):
109
- return getattr(self.logger, 'client', None)
110
-
111
109
  def set_progress(self, current, total, category=''):
112
110
  self.logger.set_progress(current, total, category)
113
111
 
synapse_sdk/utils/file.py CHANGED
@@ -1,3 +1,4 @@
1
+ import asyncio
1
2
  import hashlib
2
3
  import json
3
4
  import operator
@@ -6,6 +7,7 @@ from functools import reduce
6
7
  from pathlib import Path
7
8
  from urllib.parse import urlparse
8
9
 
10
+ import aiohttp
9
11
  import requests
10
12
  import yaml
11
13
 
@@ -38,18 +40,69 @@ def files_url_to_path(files, coerce=None):
38
40
  files[file_name]['path'] = download_file(files[file_name].pop('url'), path_download, coerce=coerce)
39
41
 
40
42
 
41
- def files_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False):
43
+ def files_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False, is_async=False):
44
+ if is_async:
45
+ asyncio.run(afiles_url_to_path_from_objs(objs, files_fields, coerce=coerce, is_list=is_list))
46
+ else:
47
+ if not is_list:
48
+ objs = [objs]
49
+
50
+ for obj in objs:
51
+ for files_field in files_fields:
52
+ try:
53
+ files = reduce(operator.getitem, files_field.split('.'), obj)
54
+ files_url_to_path(files, coerce=coerce)
55
+ except KeyError:
56
+ pass
57
+
58
+
59
+ async def adownload_file(url, path_download, name=None, coerce=None):
60
+ if name:
61
+ name += Path(url).suffix
62
+ else:
63
+ name = Path(url).name
64
+
65
+ name = urlparse(name).path
66
+ path = Path(path_download) / name
67
+ if not path.is_file():
68
+ async with aiohttp.ClientSession() as session:
69
+ async with session.get(url) as response:
70
+ with open(str(path), 'wb') as file:
71
+ while chunk := await response.content.read(1024 * 64):
72
+ file.write(chunk)
73
+
74
+ if coerce:
75
+ path = coerce(path)
76
+
77
+ return path
78
+
79
+
80
+ async def afiles_url_to_path(files, coerce=None):
81
+ path_download = Path('/tmp/datamaker') / 'media'
82
+ path_download.mkdir(parents=True, exist_ok=True)
83
+ for file_name in files:
84
+ if isinstance(files[file_name], str):
85
+ files[file_name] = await adownload_file(files[file_name], path_download, coerce=coerce)
86
+ else:
87
+ files[file_name]['path'] = await adownload_file(files[file_name].pop('url'), path_download, coerce=coerce)
88
+
89
+
90
+ async def afiles_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False):
42
91
  if not is_list:
43
92
  objs = [objs]
44
93
 
94
+ tasks = []
95
+
45
96
  for obj in objs:
46
97
  for files_field in files_fields:
47
98
  try:
48
99
  files = reduce(operator.getitem, files_field.split('.'), obj)
49
- files_url_to_path(files, coerce=coerce)
100
+ tasks.append(afiles_url_to_path(files, coerce=coerce))
50
101
  except KeyError:
51
102
  pass
52
103
 
104
+ await asyncio.gather(*tasks)
105
+
53
106
 
54
107
  def get_dict_from_file(file_path):
55
108
  if isinstance(file_path, str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a14
3
+ Version: 1.0.0a16
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -8,7 +8,7 @@ synapse_sdk/loggers.py,sha256=RsDDOiOeUCih1XOkWQJseYdYCX_wt50AZJRe6aPf96Q,4004
8
8
  synapse_sdk/cli/__init__.py,sha256=WmYGW1qZEXXIGJe3SGr8QjOStY4svuZKK1Lp_aPvtPs,140
9
9
  synapse_sdk/cli/create_plugin.py,sha256=egbW_92WwxfHz50Gy4znX5Bf5fxDdQj3GFyd0l3Y3SY,228
10
10
  synapse_sdk/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- synapse_sdk/clients/base.py,sha256=b34uGFZyV13NVWPfycDK3FNz3W9gT5r4-oLQ_mVrDPQ,3327
11
+ synapse_sdk/clients/base.py,sha256=un2vseaQ7YY6rVQqd5fIyzclg7VYLAEx2TwUkZof3ik,3354
12
12
  synapse_sdk/clients/exceptions.py,sha256=ylv7x10eOp4aA3a48jwonnvqvkiYwzJYXjkVkRTAjwk,220
13
13
  synapse_sdk/clients/utils.py,sha256=8pPJTdzHiRPSbZMoQYHAgR2BAMO6u_R_jMV6a2p34iQ,392
14
14
  synapse_sdk/clients/agent/__init__.py,sha256=Pz8_iTbIbnb7ywGJ3feqoZVmO2I3mEbwpWsISIxh0BU,1968
@@ -26,11 +26,11 @@ synapse_sdk/clients/ray/serve.py,sha256=rbCpXZYWf0oP8XJ9faa9QFNPYU7h8dltIG8xn9Zc
26
26
  synapse_sdk/plugins/__init__.py,sha256=9vsbYhxah4_ofTaG0x0qLFID_raHNkO57Y8A31Ws-lU,222
27
27
  synapse_sdk/plugins/enums.py,sha256=s59P6Oz2WAK9IX-kLVhNOvNKYJifKlWBhPpZbc9-ttE,486
28
28
  synapse_sdk/plugins/exceptions.py,sha256=Qs7qODp_RRLO9y2otU2T4ryj5LFwIZODvSIXkAh91u0,691
29
- synapse_sdk/plugins/models.py,sha256=LTD5fUk1Y2i2kNx5MaCYVFvXEyzyheY6cEHpNC248ls,3621
29
+ synapse_sdk/plugins/models.py,sha256=T3ZuTw7BZwMKpz2QGaErnEPetKRD9d4z3qceJkV363o,3541
30
30
  synapse_sdk/plugins/upload.py,sha256=VJOotYMayylOH0lNoAGeGHRkLdhP7jnC_A0rFQMvQpQ,3228
31
31
  synapse_sdk/plugins/utils.py,sha256=UYkwxkmrs0-mRgQB63SkTGD1HpIQEIiHndzTcpdNaF4,2936
32
32
  synapse_sdk/plugins/categories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
- synapse_sdk/plugins/categories/base.py,sha256=Q14bnUTdPLeNeFodcOBMr9Z0d8LM1VRIq-pl8vTKgTc,8093
33
+ synapse_sdk/plugins/categories/base.py,sha256=5BrOWXbLiwZw4I1sfElQ5CF12kLDXY97b8MSvpdNIb0,8179
34
34
  synapse_sdk/plugins/categories/decorators.py,sha256=Gw6T-UHwpCKrSt596X-g2sZbY_Z1zbbogowClj7Pr5Q,518
35
35
  synapse_sdk/plugins/categories/registry.py,sha256=KdQR8SUlLT-3kgYzDNWawS1uJnAhrcw2j4zFaTpilRs,636
36
36
  synapse_sdk/plugins/categories/templates.py,sha256=FF5FerhkZMeW1YcKLY5cylC0SkWSYdJODA_Qcm4OGYQ,887
@@ -76,7 +76,7 @@ synapse_sdk/plugins/categories/smart_tool/templates/config.yaml,sha256=3jxW8daip
76
76
  synapse_sdk/plugins/categories/smart_tool/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  synapse_sdk/plugins/categories/smart_tool/templates/plugin/auto_label.py,sha256=eevNg0nOcYFR4z_L_R-sCvVOYoLWSAH1jwDkAf3YCjY,320
78
78
  synapse_sdk/plugins/cli/__init__.py,sha256=LPtUO0jqkhKq6xR1grpse7da2R6OoT_BeDyCNyUY0T4,380
79
- synapse_sdk/plugins/cli/publish.py,sha256=aJ7eWdw_c0stIoBY4jWRpeGP0h5qUJWTFUHD6jNs6aM,1200
79
+ synapse_sdk/plugins/cli/publish.py,sha256=rhUtJsKhYyeDTQlul8mQthfMeNuQCou64faHyaP9y1c,1230
80
80
  synapse_sdk/plugins/cli/run.py,sha256=lw1KbsL-xTGllF4NtD2cq-Rh6HMbhi-sO862_Ds-sUo,2330
81
81
  synapse_sdk/plugins/templates/cookiecutter.json,sha256=NxOWk9A_v1pO0Ny4IYT9Cj5iiJ16--cIQrGC67QdR0I,396
82
82
  synapse_sdk/plugins/templates/hooks/post_gen_project.py,sha256=jqlYkY1O2TxIR-Vh3gnwILYy8k-D39Xx66d2KNQVMCs,147
@@ -95,7 +95,7 @@ synapse_sdk/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
95
95
  synapse_sdk/shared/enums.py,sha256=WMZPag9deVF7VCXaQkLk7ly_uX1KwbNzRx9TdvgaeFE,138
96
96
  synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
97
  synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
98
- synapse_sdk/utils/file.py,sha256=OYch8D5Ub8oaGIIcpO6_R6-McpR3QJk7xlkaffhgd_c,2547
98
+ synapse_sdk/utils/file.py,sha256=y1POYiVg1r7DDcB4HAhnB0GdrjjIPDD6qNfzYupgUjM,4277
99
99
  synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
100
100
  synapse_sdk/utils/storage.py,sha256=a8OVbd38ATr0El4G4kuV07lr_tJZrpIJBSy4GHb0qZ8,2581
101
101
  synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
@@ -103,9 +103,9 @@ synapse_sdk/utils/pydantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
103
103
  synapse_sdk/utils/pydantic/config.py,sha256=1vYOcUI35GslfD1rrqhFkNXXJOXt4IDqOPSx9VWGfNE,123
104
104
  synapse_sdk/utils/pydantic/errors.py,sha256=0v0T12eQBr1KrFiEOBu6KMaPK4aPEGEC6etPJGoR5b4,1061
105
105
  synapse_sdk/utils/pydantic/validators.py,sha256=G47P8ObPhsePmd_QZDK8EdPnik2CbaYzr_N4Z6En8dc,193
106
- synapse_sdk-1.0.0a14.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
107
- synapse_sdk-1.0.0a14.dist-info/METADATA,sha256=wQSUzLHaBl0ihU9g9q19Mrh0X4B69hldpDnylJijZ2I,1049
108
- synapse_sdk-1.0.0a14.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
109
- synapse_sdk-1.0.0a14.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
110
- synapse_sdk-1.0.0a14.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
111
- synapse_sdk-1.0.0a14.dist-info/RECORD,,
106
+ synapse_sdk-1.0.0a16.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
107
+ synapse_sdk-1.0.0a16.dist-info/METADATA,sha256=Xied9eLdg3w-l21B9xpFvP-GUULIMIg2YEWOH4_9kZA,1049
108
+ synapse_sdk-1.0.0a16.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
109
+ synapse_sdk-1.0.0a16.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
110
+ synapse_sdk-1.0.0a16.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
111
+ synapse_sdk-1.0.0a16.dist-info/RECORD,,