synapse-sdk 1.0.0a24__py3-none-any.whl → 1.0.0a26__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.
- synapse_sdk/plugins/categories/neural_net/base/inference.py +1 -1
- synapse_sdk/types.py +19 -0
- synapse_sdk/utils/file.py +31 -15
- synapse_sdk/utils/network.py +16 -0
- {synapse_sdk-1.0.0a24.dist-info → synapse_sdk-1.0.0a26.dist-info}/METADATA +2 -2
- {synapse_sdk-1.0.0a24.dist-info → synapse_sdk-1.0.0a26.dist-info}/RECORD +10 -8
- {synapse_sdk-1.0.0a24.dist-info → synapse_sdk-1.0.0a26.dist-info}/WHEEL +1 -1
- {synapse_sdk-1.0.0a24.dist-info → synapse_sdk-1.0.0a26.dist-info}/LICENSE +0 -0
- {synapse_sdk-1.0.0a24.dist-info → synapse_sdk-1.0.0a26.dist-info}/entry_points.txt +0 -0
- {synapse_sdk-1.0.0a24.dist-info → synapse_sdk-1.0.0a26.dist-info}/top_level.txt +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import tempfile
|
|
2
2
|
|
|
3
3
|
import jwt
|
|
4
|
-
from synapse_sdk.clients.backend import BackendClient
|
|
5
4
|
from fastapi import FastAPI
|
|
6
5
|
from ray import serve
|
|
7
6
|
|
|
7
|
+
from synapse_sdk.clients.backend import BackendClient
|
|
8
8
|
from synapse_sdk.utils.file import unarchive
|
|
9
9
|
|
|
10
10
|
app = FastAPI()
|
synapse_sdk/types.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from pydantic import HttpUrl
|
|
4
|
+
from pydantic_core import core_schema
|
|
5
|
+
from pydantic_core.core_schema import ValidationInfo
|
|
6
|
+
|
|
7
|
+
from synapse_sdk.utils.file import download_file, get_temp_path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FileField(str):
|
|
11
|
+
@classmethod
|
|
12
|
+
def __get_pydantic_core_schema__(cls, source_type: Any, _handler: callable) -> core_schema.CoreSchema:
|
|
13
|
+
return core_schema.with_info_before_validator_function(cls.validate, core_schema.str_schema())
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def validate(url: HttpUrl, info: ValidationInfo) -> str:
|
|
17
|
+
path_download = get_temp_path('media')
|
|
18
|
+
path_download.mkdir(parents=True, exist_ok=True)
|
|
19
|
+
return str(download_file(url, path_download))
|
synapse_sdk/utils/file.py
CHANGED
|
@@ -5,24 +5,35 @@ import operator
|
|
|
5
5
|
import zipfile
|
|
6
6
|
from functools import reduce
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from urllib.parse import urlparse
|
|
9
8
|
|
|
10
9
|
import aiohttp
|
|
11
10
|
import requests
|
|
12
11
|
import yaml
|
|
13
12
|
|
|
13
|
+
from synapse_sdk.utils.network import clean_url
|
|
14
|
+
from synapse_sdk.utils.string import hash_text
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def download_file(url, path_download, name=None, coerce=None, use_cached=True):
|
|
18
|
+
chunk_size = 1024 * 1024 * 50
|
|
19
|
+
cleaned_url = clean_url(url) # remove query params and fragment
|
|
14
20
|
|
|
15
|
-
def download_file(url, path_download, name=None, coerce=None):
|
|
16
21
|
if name:
|
|
17
|
-
|
|
22
|
+
use_cached = False
|
|
18
23
|
else:
|
|
19
|
-
name =
|
|
24
|
+
name = hash_text(cleaned_url)
|
|
25
|
+
|
|
26
|
+
name += Path(cleaned_url).suffix
|
|
20
27
|
|
|
21
|
-
name = urlparse(name).path
|
|
22
28
|
path = Path(path_download) / name
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
|
|
30
|
+
if not use_cached or not path.is_file():
|
|
31
|
+
response = requests.get(url, allow_redirects=True, stream=True)
|
|
32
|
+
response.raise_for_status()
|
|
33
|
+
|
|
34
|
+
with path.open('wb') as file:
|
|
35
|
+
for chunk in response.iter_content(chunk_size=chunk_size):
|
|
36
|
+
file.write(chunk)
|
|
26
37
|
|
|
27
38
|
if coerce:
|
|
28
39
|
path = coerce(path)
|
|
@@ -62,19 +73,24 @@ def files_url_to_path_from_objs(objs, files_fields, coerce=None, is_list=False,
|
|
|
62
73
|
pass
|
|
63
74
|
|
|
64
75
|
|
|
65
|
-
async def adownload_file(url, path_download, name=None, coerce=None):
|
|
76
|
+
async def adownload_file(url, path_download, name=None, coerce=None, use_cached=True):
|
|
77
|
+
chunk_size = 1024 * 1024 * 50
|
|
78
|
+
cleaned_url = clean_url(url) # remove query params and fragment
|
|
79
|
+
|
|
66
80
|
if name:
|
|
67
|
-
|
|
81
|
+
use_cached = False
|
|
68
82
|
else:
|
|
69
|
-
name =
|
|
83
|
+
name = hash_text(cleaned_url)
|
|
84
|
+
|
|
85
|
+
name += Path(cleaned_url).suffix
|
|
70
86
|
|
|
71
|
-
name = urlparse(name).path
|
|
72
87
|
path = Path(path_download) / name
|
|
73
|
-
|
|
88
|
+
|
|
89
|
+
if not use_cached or not path.is_file():
|
|
74
90
|
async with aiohttp.ClientSession() as session:
|
|
75
91
|
async with session.get(url) as response:
|
|
76
|
-
with open(
|
|
77
|
-
while chunk := await response.content.read(
|
|
92
|
+
with path.open('wb') as file:
|
|
93
|
+
while chunk := await response.content.read(chunk_size):
|
|
78
94
|
file.write(chunk)
|
|
79
95
|
|
|
80
96
|
if coerce:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from urllib.parse import urlparse, urlunparse
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def clean_url(url, remove_query_params=True, remove_fragment=True):
|
|
5
|
+
parsed = urlparse(url)
|
|
6
|
+
query = '' if remove_query_params else parsed.query
|
|
7
|
+
fragment = '' if remove_fragment else parsed.fragment
|
|
8
|
+
|
|
9
|
+
return urlunparse((
|
|
10
|
+
parsed.scheme,
|
|
11
|
+
parsed.netloc,
|
|
12
|
+
parsed.path,
|
|
13
|
+
parsed.params,
|
|
14
|
+
query,
|
|
15
|
+
fragment,
|
|
16
|
+
))
|
|
@@ -5,6 +5,7 @@ locale/ko/LC_MESSAGES/messages.po,sha256=TFii_RbURDH-Du_9ZQf3wNh-2briGk1IqY33-9G
|
|
|
5
5
|
synapse_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
synapse_sdk/i18n.py,sha256=VXMR-Zm_1hTAg9iPk3YZNNq-T1Bhx1J2fEtRT6kyYbg,766
|
|
7
7
|
synapse_sdk/loggers.py,sha256=RsDDOiOeUCih1XOkWQJseYdYCX_wt50AZJRe6aPf96Q,4004
|
|
8
|
+
synapse_sdk/types.py,sha256=khzn8KpgxFdn1SrpbcuX84m_Md1Mz_HIoUoPq8uok40,698
|
|
8
9
|
synapse_sdk/cli/__init__.py,sha256=WmYGW1qZEXXIGJe3SGr8QjOStY4svuZKK1Lp_aPvtPs,140
|
|
9
10
|
synapse_sdk/cli/create_plugin.py,sha256=egbW_92WwxfHz50Gy4znX5Bf5fxDdQj3GFyd0l3Y3SY,228
|
|
10
11
|
synapse_sdk/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -54,7 +55,7 @@ synapse_sdk/plugins/categories/neural_net/actions/inference.py,sha256=0a655ELqNV
|
|
|
54
55
|
synapse_sdk/plugins/categories/neural_net/actions/test.py,sha256=JY25eg-Fo6WbgtMkGoo_qNqoaZkp3AQNEypJmeGzEog,320
|
|
55
56
|
synapse_sdk/plugins/categories/neural_net/actions/train.py,sha256=4zq2ryWjqDa6MyI2BGe3sAofMh2NeY3XAo-1gEFXBs4,5145
|
|
56
57
|
synapse_sdk/plugins/categories/neural_net/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
57
|
-
synapse_sdk/plugins/categories/neural_net/base/inference.py,sha256=
|
|
58
|
+
synapse_sdk/plugins/categories/neural_net/base/inference.py,sha256=R5DASI6-5vzsjDOYxqeGGMBjnav5qHF4hNJT8zNUR3I,1097
|
|
58
59
|
synapse_sdk/plugins/categories/neural_net/templates/config.yaml,sha256=dXKB1hO53hDZB73xnxLVCNQl8Sm7svMmVmuMrOCQmEU,343
|
|
59
60
|
synapse_sdk/plugins/categories/neural_net/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
60
61
|
synapse_sdk/plugins/categories/neural_net/templates/plugin/inference.py,sha256=InfqKWJYi6sqiUnfPKHC5KYGhxckDaWZNQ202u-uVP4,366
|
|
@@ -98,17 +99,18 @@ synapse_sdk/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
|
98
99
|
synapse_sdk/shared/enums.py,sha256=WMZPag9deVF7VCXaQkLk7ly_uX1KwbNzRx9TdvgaeFE,138
|
|
99
100
|
synapse_sdk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
100
101
|
synapse_sdk/utils/debug.py,sha256=F7JlUwYjTFZAMRbBqKm6hxOIz-_IXYA8lBInOS4jbS4,100
|
|
101
|
-
synapse_sdk/utils/file.py,sha256=
|
|
102
|
+
synapse_sdk/utils/file.py,sha256=eF1GDxjPaq2QOiKKCHSzgCkBRYSBSwP4rKOAApAQR3E,5661
|
|
102
103
|
synapse_sdk/utils/module_loading.py,sha256=chHpU-BZjtYaTBD_q0T7LcKWtqKvYBS4L0lPlKkoMQ8,1020
|
|
104
|
+
synapse_sdk/utils/network.py,sha256=wg-oFM0gKK5REqIUO8d-x9yXJfqbnkSbbF0_qyxpwz4,412
|
|
103
105
|
synapse_sdk/utils/storage.py,sha256=a8OVbd38ATr0El4G4kuV07lr_tJZrpIJBSy4GHb0qZ8,2581
|
|
104
106
|
synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,216
|
|
105
107
|
synapse_sdk/utils/pydantic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
106
108
|
synapse_sdk/utils/pydantic/config.py,sha256=1vYOcUI35GslfD1rrqhFkNXXJOXt4IDqOPSx9VWGfNE,123
|
|
107
109
|
synapse_sdk/utils/pydantic/errors.py,sha256=0v0T12eQBr1KrFiEOBu6KMaPK4aPEGEC6etPJGoR5b4,1061
|
|
108
110
|
synapse_sdk/utils/pydantic/validators.py,sha256=G47P8ObPhsePmd_QZDK8EdPnik2CbaYzr_N4Z6En8dc,193
|
|
109
|
-
synapse_sdk-1.0.
|
|
110
|
-
synapse_sdk-1.0.
|
|
111
|
-
synapse_sdk-1.0.
|
|
112
|
-
synapse_sdk-1.0.
|
|
113
|
-
synapse_sdk-1.0.
|
|
114
|
-
synapse_sdk-1.0.
|
|
111
|
+
synapse_sdk-1.0.0a26.dist-info/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
|
|
112
|
+
synapse_sdk-1.0.0a26.dist-info/METADATA,sha256=DnO5NIlrAWVsCnkh8YXP-5ujNpt_NxijYyOeJ_ZQF2M,1070
|
|
113
|
+
synapse_sdk-1.0.0a26.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
114
|
+
synapse_sdk-1.0.0a26.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
|
|
115
|
+
synapse_sdk-1.0.0a26.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
|
|
116
|
+
synapse_sdk-1.0.0a26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|