setta 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- setta/__init__.py +1 -1
- setta/cli/__init__.py +1 -0
- setta/cli/connect.py +43 -0
- setta/cli/logger.py +225 -0
- setta/code_gen/__init__.py +0 -0
- setta/code_gen/create_runnable_scripts.py +466 -0
- setta/code_gen/export_selected.py +776 -0
- setta/code_gen/find_placeholders.py +13 -0
- setta/code_gen/python/__init__.py +0 -0
- setta/code_gen/python/ast_utils.py +183 -0
- setta/code_gen/python/check_scope.py +187 -0
- setta/code_gen/python/generate_code.py +280 -0
- setta/code_gen/python/make_parseable.py +97 -0
- setta/code_gen/python/position_line_col.py +33 -0
- setta/code_gen/python/validate_imports.py +87 -0
- setta/code_gen/utils.py +120 -0
- setta/code_gen/yaml/__init__.py +0 -0
- setta/code_gen/yaml/generate_yaml.py +23 -0
- setta/code_gen/yaml/section_dict.py +93 -0
- setta/database/__init__.py +0 -0
- setta/database/backup.py +80 -0
- setta/database/db/__init__.py +0 -0
- setta/database/db/artifacts/__init__.py +0 -0
- setta/database/db/artifacts/load.py +93 -0
- setta/database/db/artifacts/save.py +85 -0
- setta/database/db/artifacts/save_or_create.py +68 -0
- setta/database/db/artifacts/utils.py +13 -0
- setta/database/db/codeInfo/__init__.py +0 -0
- setta/database/db/codeInfo/copy.py +26 -0
- setta/database/db/codeInfo/load.py +65 -0
- setta/database/db/codeInfo/save.py +75 -0
- setta/database/db/codeInfo/utils.py +33 -0
- setta/database/db/evRefs/__init__.py +0 -0
- setta/database/db/evRefs/load.py +45 -0
- setta/database/db/evRefs/save.py +95 -0
- setta/database/db/projects/__init__.py +0 -0
- setta/database/db/projects/copy.py +36 -0
- setta/database/db/projects/delete.py +7 -0
- setta/database/db/projects/load.py +184 -0
- setta/database/db/projects/save.py +267 -0
- setta/database/db/projects/saveAs.py +40 -0
- setta/database/db/projects/utils.py +135 -0
- setta/database/db/sectionVariants/__init__.py +0 -0
- setta/database/db/sectionVariants/copy.py +28 -0
- setta/database/db/sectionVariants/load.py +139 -0
- setta/database/db/sectionVariants/save.py +140 -0
- setta/database/db/sectionVariants/utils.py +44 -0
- setta/database/db/sections/__init__.py +0 -0
- setta/database/db/sections/copy.py +70 -0
- setta/database/db/sections/jsonSource.py +119 -0
- setta/database/db/sections/load.py +350 -0
- setta/database/db/sections/save.py +204 -0
- setta/database/db/sections/utils.py +13 -0
- setta/database/db/uiTypes/__init__.py +0 -0
- setta/database/db/uiTypes/copy.py +33 -0
- setta/database/db/uiTypes/load.py +51 -0
- setta/database/db/uiTypes/save.py +99 -0
- setta/database/db/uiTypes/utils.py +27 -0
- setta/database/db_init.py +36 -0
- setta/database/db_objs.py +102 -0
- setta/database/db_path.py +8 -0
- setta/database/export_db/__init__.py +0 -0
- setta/database/export_db/export_db.py +43 -0
- setta/database/export_db/export_raw.py +53 -0
- setta/database/export_db/export_readable.py +242 -0
- setta/database/export_db/utils.py +16 -0
- setta/database/import_db.py +28 -0
- setta/database/seed.py +41 -0
- setta/database/settings_file.py +118 -0
- setta/database/utils.py +32 -0
- setta/lsp/__init__.py +0 -0
- setta/lsp/file_watcher.py +113 -0
- setta/lsp/reader.py +184 -0
- setta/lsp/reader_fns/__init__.py +0 -0
- setta/lsp/reader_fns/completion.py +84 -0
- setta/lsp/reader_fns/definition.py +2 -0
- setta/lsp/reader_fns/diagnostics.py +99 -0
- setta/lsp/reader_fns/documentHighlight.py +25 -0
- setta/lsp/reader_fns/references.py +34 -0
- setta/lsp/reader_fns/signatureHelp.py +99 -0
- setta/lsp/server.py +150 -0
- setta/lsp/utils.py +60 -0
- setta/lsp/writer.py +306 -0
- setta/routers/__init__.py +11 -0
- setta/routers/artifact.py +105 -0
- setta/routers/code_info.py +32 -0
- setta/routers/dependencies.py +49 -0
- setta/routers/in_memory_fn_stdout_websocket.py +21 -0
- setta/routers/interactive.py +119 -0
- setta/routers/lsp.py +14 -0
- setta/routers/projects.py +188 -0
- setta/routers/reference_renaming.py +111 -0
- setta/routers/sections.py +174 -0
- setta/routers/settings.py +40 -0
- setta/routers/terminals.py +83 -0
- setta/routers/websocket.py +36 -0
- setta/server.py +141 -0
- setta/start.py +112 -0
- setta/static/constants/BaseUITypes.json +153 -0
- setta/static/constants/Settings.json +113 -0
- setta/static/constants/constants.json +117 -0
- setta/static/constants/db_init.sql +249 -0
- setta/static/constants/defaultValues.json +125 -0
- setta/static/constants/settingsProject.json +276 -0
- setta/static/frontend/android-chrome-192x192.png +0 -0
- setta/static/frontend/android-chrome-512x512.png +0 -0
- setta/static/frontend/apple-touch-icon.png +0 -0
- setta/static/frontend/assets/KaTeX_AMS-Regular-0cdd387c.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_AMS-Regular-30da91e8.woff +0 -0
- setta/static/frontend/assets/KaTeX_AMS-Regular-68534840.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Bold-07d8e303.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Bold-1ae6bd74.woff +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Bold-de7701e4.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Regular-3398dd02.woff +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Regular-5d53e70a.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Regular-ed0b7437.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Bold-74444efd.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Bold-9163df9c.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Bold-9be7ceb8.woff +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Regular-1e6f9579.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Regular-51814d27.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Regular-5e28753b.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Bold-0f60d1b8.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-Bold-138ac28d.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Main-Bold-c76c5d69.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-BoldItalic-70ee1f64.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Main-BoldItalic-99cd42a3.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-BoldItalic-a6f7ec0d.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Italic-0d85ae7c.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Main-Italic-97479ca6.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-Italic-f1d6ef86.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Regular-c2342cd8.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-Regular-c6368d87.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Regular-d0332f52.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Math-BoldItalic-850c0af5.woff +0 -0
- setta/static/frontend/assets/KaTeX_Math-BoldItalic-dc47344d.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Math-BoldItalic-f9377ab0.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Math-Italic-08ce98e5.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Math-Italic-7af58c5e.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Math-Italic-8a8d2445.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Bold-1ece03f7.ttf +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Bold-e99ae511.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Bold-ece03cfd.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Italic-00b26ac8.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Italic-3931dd81.ttf +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Italic-91ee6750.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Regular-11e4dc8a.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Regular-68e8c73e.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Regular-f36ea897.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Script-Regular-036d4e95.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Script-Regular-1c67f068.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Script-Regular-d96cdf2b.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size1-Regular-6b47c401.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Size1-Regular-95b6d2f1.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Size1-Regular-c943cc98.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size2-Regular-2014c523.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size2-Regular-a6b2099f.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Size2-Regular-d04c5421.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Size3-Regular-500e04d5.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Size3-Regular-6ab6b62e.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size4-Regular-99f9c675.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size4-Regular-a4af7d41.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Size4-Regular-c647367d.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Typewriter-Regular-71d517d6.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Typewriter-Regular-e14fed02.woff +0 -0
- setta/static/frontend/assets/KaTeX_Typewriter-Regular-f01f3e87.ttf +0 -0
- setta/static/frontend/assets/cormorant-garamond-all-700-italic-c9b58582.woff +0 -0
- setta/static/frontend/assets/cormorant-garamond-cyrillic-700-italic-9101ad5f.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-cyrillic-ext-700-italic-950de0d6.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-latin-700-italic-0bc53e12.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-latin-ext-700-italic-525738e0.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-vietnamese-700-italic-99563037.woff2 +0 -0
- setta/static/frontend/assets/erase-5e0448ea.svg +15 -0
- setta/static/frontend/assets/index-1d4b4ecf.css +32 -0
- setta/static/frontend/assets/index-ee99dc72.js +678 -0
- setta/static/frontend/assets/inter-all-400-normal-054f12d0.woff +0 -0
- setta/static/frontend/assets/inter-all-600-normal-c03769e5.woff +0 -0
- setta/static/frontend/assets/inter-all-800-normal-15dc6e4b.woff +0 -0
- setta/static/frontend/assets/inter-cyrillic-400-normal-a4eee61a.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-600-normal-8b14f703.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-800-normal-e706eaaa.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-ext-400-normal-70047a3b.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-ext-600-normal-d4ab9bc4.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-ext-800-normal-eae7515a.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-400-normal-381ea30d.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-600-normal-601f93a2.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-800-normal-7af4fb64.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-ext-400-normal-27027b17.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-ext-600-normal-f2ddf9de.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-ext-800-normal-4cb6189e.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-400-normal-d56fec21.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-600-normal-ff769fa6.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-800-normal-5eea1309.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-ext-400-normal-bb698d85.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-ext-600-normal-ca4808f9.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-ext-800-normal-ebdacc0f.woff2 +0 -0
- setta/static/frontend/assets/logo/logo.svg +8 -0
- setta/static/frontend/assets/pen-455d7d8a.svg +19 -0
- setta/static/frontend/assets/source-code-pro-all-500-normal-6bdaa03b.woff +0 -0
- setta/static/frontend/assets/source-code-pro-cyrillic-500-normal-288a0d68.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-cyrillic-ext-500-normal-b110a13b.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-greek-500-normal-04328acb.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-latin-500-normal-06edef1e.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-latin-ext-500-normal-6dc60d5e.woff2 +0 -0
- setta/static/frontend/assets/web-vitals-44a8e082.js +1 -0
- setta/static/frontend/assets/work-sans-all-400-normal-38034a3c.woff +0 -0
- setta/static/frontend/assets/work-sans-all-500-normal-550d64e5.woff +0 -0
- setta/static/frontend/assets/work-sans-all-600-normal-ccf14060.woff +0 -0
- setta/static/frontend/assets/work-sans-all-700-normal-494c2971.woff +0 -0
- setta/static/frontend/assets/work-sans-latin-400-normal-36735bc1.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-500-normal-3790bfda.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-600-normal-5fba494e.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-700-normal-a5033d0a.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-400-normal-c20f571a.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-500-normal-0f5ac96c.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-600-normal-97a237d1.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-700-normal-103e112c.woff2 +0 -0
- setta/static/frontend/browserconfig.xml +9 -0
- setta/static/frontend/favicon-16x16.png +0 -0
- setta/static/frontend/favicon-32x32.png +0 -0
- setta/static/frontend/favicon.ico +0 -0
- setta/static/frontend/index.html +30 -0
- setta/static/frontend/manifest.json +25 -0
- setta/static/frontend/mstile-144x144.png +0 -0
- setta/static/frontend/mstile-150x150.png +0 -0
- setta/static/frontend/mstile-310x150.png +0 -0
- setta/static/frontend/mstile-310x310.png +0 -0
- setta/static/frontend/mstile-70x70.png +0 -0
- setta/static/frontend/robots.txt +3 -0
- setta/static/frontend/safari-pinned-tab.svg +18 -0
- setta/static/frontend/site.webmanifest +19 -0
- setta/static/seed/.DS_Store +0 -0
- setta/static/seed/examples/.DS_Store +0 -0
- setta/tasks/__init__.py +0 -0
- setta/tasks/fns/__init__.py +9 -0
- setta/tasks/fns/codeAreaAutocomplete.py +209 -0
- setta/tasks/fns/codeAreaFindTemplateVars.py +128 -0
- setta/tasks/fns/codeAreaInitializeCode.py +98 -0
- setta/tasks/fns/findEVRefs.py +236 -0
- setta/tasks/fns/parametersRequest.py +71 -0
- setta/tasks/fns/textFieldAutocomplete.py +210 -0
- setta/tasks/fns/textFieldInitializeCode.py +99 -0
- setta/tasks/fns/typeCheck.py +40 -0
- setta/tasks/fns/utils.py +134 -0
- setta/tasks/task_runner.py +29 -0
- setta/tasks/tasks.py +152 -0
- setta/tasks/utils.py +178 -0
- setta/terminals/__init__.py +0 -0
- setta/terminals/terminals.py +242 -0
- setta/terminals/utils.py +37 -0
- setta/utils/__init__.py +0 -0
- setta/utils/constants.py +148 -0
- setta/utils/generate_memorable_string.py +431 -0
- setta/utils/generate_new_filename.py +80 -0
- setta/utils/section_contents.py +133 -0
- setta/utils/utils.py +271 -0
- setta/utils/websocket_manager.py +91 -0
- setta-0.0.2.dist-info/LICENSE +201 -0
- setta-0.0.2.dist-info/METADATA +24 -0
- setta-0.0.2.dist-info/RECORD +263 -0
- {setta-0.0.1.dist-info → setta-0.0.2.dist-info}/WHEEL +1 -1
- setta-0.0.2.dist-info/entry_points.txt +2 -0
- setta-0.0.1.dist-info/METADATA +0 -18
- setta-0.0.1.dist-info/RECORD +0 -5
- {setta-0.0.1.dist-info → setta-0.0.2.dist-info}/top_level.txt +0 -0
setta/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__="0.0.
|
1
|
+
__version__ = "0.0.2"
|
setta/cli/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
from .logger import Setta
|
setta/cli/connect.py
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
import subprocess
|
4
|
+
|
5
|
+
import websockets
|
6
|
+
|
7
|
+
from setta.code_gen.create_runnable_scripts import runCode
|
8
|
+
|
9
|
+
from ..utils.constants import C
|
10
|
+
|
11
|
+
logger = logging.getLogger(__name__)
|
12
|
+
|
13
|
+
|
14
|
+
async def connect(websocket_id):
|
15
|
+
try:
|
16
|
+
extra_headers = {"isCLI": True}
|
17
|
+
if websocket_id:
|
18
|
+
extra_headers["websocketId"] = websocket_id
|
19
|
+
async with websockets.connect(
|
20
|
+
C.WEBSOCKET,
|
21
|
+
extra_headers=extra_headers,
|
22
|
+
) as websocket:
|
23
|
+
await consumer_handler(websocket)
|
24
|
+
except websockets.ConnectionClosedError:
|
25
|
+
logger.debug("Connection closed unexpectedly")
|
26
|
+
except ConnectionRefusedError:
|
27
|
+
logger.debug("Connection refused")
|
28
|
+
|
29
|
+
|
30
|
+
async def consumer_handler(websocket):
|
31
|
+
async for message in websocket:
|
32
|
+
message = json.loads(message)
|
33
|
+
if message["messageType"] == C.WS_RUN_CODE:
|
34
|
+
# TODO: now that runCode requires lsp_writers
|
35
|
+
# this will have to be changed, probably needs to communicate
|
36
|
+
# with host setta process via websocket instead of calling
|
37
|
+
# runCode
|
38
|
+
command = await runCode(message)
|
39
|
+
run_code_as_subprocess(command)
|
40
|
+
|
41
|
+
|
42
|
+
def run_code_as_subprocess(command):
|
43
|
+
subprocess.run(command, shell=True)
|
setta/cli/logger.py
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
import base64
|
2
|
+
import os
|
3
|
+
from abc import ABC, abstractmethod
|
4
|
+
from io import BytesIO
|
5
|
+
from pathlib import Path
|
6
|
+
|
7
|
+
import requests
|
8
|
+
|
9
|
+
from setta.utils.constants import (
|
10
|
+
CODE_FOLDER_ENV_VARIABLE,
|
11
|
+
HOST_ENV_VARIABLE,
|
12
|
+
PORT_ENV_VARIABLE,
|
13
|
+
C,
|
14
|
+
load_constants,
|
15
|
+
set_constants,
|
16
|
+
)
|
17
|
+
|
18
|
+
|
19
|
+
class Setta:
|
20
|
+
def __init__(self, root_path=None, host=None, port=None):
|
21
|
+
load_constants()
|
22
|
+
set_constants(
|
23
|
+
host=host or os.environ.get(HOST_ENV_VARIABLE, C.DEFAULT_HOST),
|
24
|
+
port=port or os.environ.get(PORT_ENV_VARIABLE, C.DEFAULT_PORT),
|
25
|
+
)
|
26
|
+
if root_path:
|
27
|
+
self.root_path = Path(root_path)
|
28
|
+
else:
|
29
|
+
self.root_path = Path(
|
30
|
+
os.environ.get(CODE_FOLDER_ENV_VARIABLE, os.path.relpath(os.getcwd()))
|
31
|
+
)
|
32
|
+
|
33
|
+
self.name_path_type_to_id = {}
|
34
|
+
|
35
|
+
def log(self, obj, save_to="db"):
|
36
|
+
data_to_send = []
|
37
|
+
for name, data in obj.items():
|
38
|
+
artifact_path = ""
|
39
|
+
|
40
|
+
if save_to == "disk":
|
41
|
+
full_path = self.root_path / name
|
42
|
+
full_path = data.path_with_extension(full_path)
|
43
|
+
directory = full_path.parent
|
44
|
+
directory.mkdir(parents=True, exist_ok=True)
|
45
|
+
data.save(full_path)
|
46
|
+
artifact_path = str(full_path)
|
47
|
+
|
48
|
+
serialized = data.serialize()
|
49
|
+
curr_data = {
|
50
|
+
"name": name,
|
51
|
+
"path": artifact_path,
|
52
|
+
"value": serialized["value"],
|
53
|
+
"type": serialized["type"],
|
54
|
+
}
|
55
|
+
curr_data["id"] = self.maybe_get_artifact_id(curr_data)
|
56
|
+
data_to_send.append(curr_data)
|
57
|
+
|
58
|
+
res = requests.post(
|
59
|
+
f"{C.BACKEND}{C.ROUTE_PREFIX}{C.ROUTE_SEND_ARTIFACT}",
|
60
|
+
json={
|
61
|
+
"data": data_to_send,
|
62
|
+
"saveTo": save_to,
|
63
|
+
"messageType": C.WS_ARTIFACT,
|
64
|
+
},
|
65
|
+
headers={"Content-Type": "application/json"},
|
66
|
+
)
|
67
|
+
|
68
|
+
if res.status_code == 200:
|
69
|
+
artifact_ids = res.json()
|
70
|
+
for idx, id in enumerate(artifact_ids):
|
71
|
+
sent_data = data_to_send[idx]
|
72
|
+
self.name_path_type_to_id[self.get_name_path_type_key(sent_data)] = id
|
73
|
+
|
74
|
+
def maybe_get_artifact_id(self, data_to_send):
|
75
|
+
return self.name_path_type_to_id.get(self.get_name_path_type_key(data_to_send))
|
76
|
+
|
77
|
+
def get_name_path_type_key(self, data_to_send):
|
78
|
+
return data_to_send["name"], data_to_send["path"], data_to_send["type"]
|
79
|
+
|
80
|
+
|
81
|
+
class SettaDataWrapper(ABC):
|
82
|
+
@abstractmethod
|
83
|
+
def path_with_extension(self, path):
|
84
|
+
pass
|
85
|
+
|
86
|
+
@abstractmethod
|
87
|
+
def save(self, path):
|
88
|
+
pass
|
89
|
+
|
90
|
+
@abstractmethod
|
91
|
+
def serialize(self):
|
92
|
+
pass
|
93
|
+
|
94
|
+
@abstractmethod
|
95
|
+
def load(self, path_with_extension):
|
96
|
+
pass
|
97
|
+
|
98
|
+
|
99
|
+
class SettaList(SettaDataWrapper):
|
100
|
+
def __init__(self, data=None):
|
101
|
+
self.data = data
|
102
|
+
|
103
|
+
def path_with_extension(self, path):
|
104
|
+
return path.with_suffix(".csv")
|
105
|
+
|
106
|
+
def save(self, path):
|
107
|
+
if not self.data:
|
108
|
+
return
|
109
|
+
|
110
|
+
headers = list(self.data.keys())
|
111
|
+
num_rows = len(next(iter(self.data.values()))) # Get length from first column
|
112
|
+
|
113
|
+
with open(path, "w") as f:
|
114
|
+
# Write headers
|
115
|
+
f.write(",".join(headers) + "\n")
|
116
|
+
|
117
|
+
# Write rows
|
118
|
+
for i in range(num_rows):
|
119
|
+
row_vals = []
|
120
|
+
for header in headers:
|
121
|
+
val = self.data[header][i] if i < len(self.data[header]) else None
|
122
|
+
row_vals.append("" if val is None else str(val))
|
123
|
+
f.write(",".join(row_vals) + "\n")
|
124
|
+
|
125
|
+
def serialize(self):
|
126
|
+
return {"value": self.data, "type": "list"}
|
127
|
+
|
128
|
+
def load(self, path):
|
129
|
+
self.data = load_from_csv_file(path)
|
130
|
+
|
131
|
+
|
132
|
+
class SettaImg(SettaDataWrapper):
|
133
|
+
def __init__(self, img=None, format="png"):
|
134
|
+
self.img = img
|
135
|
+
self.format = format
|
136
|
+
|
137
|
+
def path_with_extension(self, path):
|
138
|
+
return path.with_suffix(f".{self.format}")
|
139
|
+
|
140
|
+
def save(self, path):
|
141
|
+
with open(path, "wb") as f:
|
142
|
+
f.write(self.img)
|
143
|
+
|
144
|
+
def serialize(self):
|
145
|
+
if self.img is None:
|
146
|
+
raise ValueError("No image data to serialize")
|
147
|
+
b64_str = base64.b64encode(self.img).decode("utf-8")
|
148
|
+
return {"value": b64_str, "type": "img"}
|
149
|
+
|
150
|
+
def load(self, path_with_extension):
|
151
|
+
with open(path_with_extension, "rb") as f:
|
152
|
+
self.img = f.read()
|
153
|
+
|
154
|
+
|
155
|
+
def get_wrapper_for_loading(data_type):
|
156
|
+
if data_type == "list":
|
157
|
+
return SettaList()
|
158
|
+
if data_type == "img":
|
159
|
+
return SettaImg()
|
160
|
+
|
161
|
+
|
162
|
+
def default_section_type(data_type):
|
163
|
+
if data_type == "list":
|
164
|
+
return C.CHART
|
165
|
+
if data_type == "img":
|
166
|
+
return C.IMAGE
|
167
|
+
|
168
|
+
|
169
|
+
def save_base64_to_png(base64_string, output_file):
|
170
|
+
image_data = base64.b64decode(base64_string)
|
171
|
+
|
172
|
+
# Write the binary data to a file
|
173
|
+
with open(output_file, "wb") as f:
|
174
|
+
f.write(image_data)
|
175
|
+
|
176
|
+
|
177
|
+
def pil_to_setta_img(pil_image, format="png"):
|
178
|
+
buffer = BytesIO()
|
179
|
+
pil_image.save(buffer, format=format.upper())
|
180
|
+
raw_data = buffer.getvalue()
|
181
|
+
return SettaImg(img=raw_data, format=format)
|
182
|
+
|
183
|
+
|
184
|
+
def parse_csv_row(values):
|
185
|
+
row = []
|
186
|
+
for x in values:
|
187
|
+
if x.strip() == "":
|
188
|
+
row.append(None)
|
189
|
+
else:
|
190
|
+
try:
|
191
|
+
row.append(float(x))
|
192
|
+
except ValueError:
|
193
|
+
row.append(x)
|
194
|
+
return row
|
195
|
+
|
196
|
+
|
197
|
+
def parse_csv_content(content):
|
198
|
+
lines = content.strip().split("\n")
|
199
|
+
if not lines:
|
200
|
+
return {}
|
201
|
+
|
202
|
+
headers = [h.strip() for h in lines[0].split(",")]
|
203
|
+
result = {header: [] for header in headers}
|
204
|
+
|
205
|
+
if not lines[1:]:
|
206
|
+
return result
|
207
|
+
|
208
|
+
# Parse rows and populate lists
|
209
|
+
for line in lines[1:]:
|
210
|
+
values = parse_csv_row(line.strip().split(","))
|
211
|
+
for header, value in zip(headers, values):
|
212
|
+
result[header].append(value)
|
213
|
+
|
214
|
+
return result
|
215
|
+
|
216
|
+
|
217
|
+
def load_from_csv_file(path):
|
218
|
+
with open(path, "r") as f:
|
219
|
+
content = f.read()
|
220
|
+
return parse_csv_content(content)
|
221
|
+
|
222
|
+
|
223
|
+
def load_from_csv_base64(base64_string):
|
224
|
+
content = base64.b64decode(base64_string).decode("utf-8")
|
225
|
+
return parse_csv_content(content)
|
File without changes
|