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
@@ -0,0 +1,466 @@
|
|
1
|
+
import copy
|
2
|
+
import os
|
3
|
+
from datetime import datetime
|
4
|
+
from pathlib import Path
|
5
|
+
|
6
|
+
from setta.code_gen.export_selected import (
|
7
|
+
export_selected,
|
8
|
+
get_gen_code_template_var,
|
9
|
+
get_section_type,
|
10
|
+
get_selected_section_variant,
|
11
|
+
)
|
12
|
+
from setta.code_gen.find_placeholders import remove_tp, tp
|
13
|
+
from setta.code_gen.python.generate_code import (
|
14
|
+
convert_var_names_to_readable_form,
|
15
|
+
generate_code,
|
16
|
+
generate_imports,
|
17
|
+
get_chars_in_line_before_position,
|
18
|
+
)
|
19
|
+
from setta.code_gen.python.validate_imports import (
|
20
|
+
maybe_validate_imports_and_update_code,
|
21
|
+
)
|
22
|
+
from setta.code_gen.utils import process_refs
|
23
|
+
from setta.utils.constants import (
|
24
|
+
CODE_FOLDER,
|
25
|
+
CODE_FOLDER_ENV_VARIABLE,
|
26
|
+
USER_SETTINGS,
|
27
|
+
C,
|
28
|
+
)
|
29
|
+
from setta.utils.utils import prune_dict
|
30
|
+
|
31
|
+
|
32
|
+
async def runCode(message, lsp_writers):
|
33
|
+
p = message["content"]
|
34
|
+
exporter_obj = export_selected(
|
35
|
+
p, always_export_args_objs=False, force_include_template_var=True
|
36
|
+
)
|
37
|
+
folder_path = create_timestamped_folder(CODE_FOLDER)
|
38
|
+
|
39
|
+
code_dict = await generate_final_code_for_sections(
|
40
|
+
p,
|
41
|
+
exporter_obj,
|
42
|
+
lsp_writers,
|
43
|
+
folder_path,
|
44
|
+
do_prepend_with_setup_code=True,
|
45
|
+
do_convert_var_names_to_readable_form=True,
|
46
|
+
)
|
47
|
+
|
48
|
+
if p["runCodeBlocks"] is None:
|
49
|
+
p["runCodeBlocks"] = [
|
50
|
+
exporter_obj.code_gen_template_var_section_details["section"]["id"]
|
51
|
+
]
|
52
|
+
|
53
|
+
to_write, section_dependencies = prune_and_topological_sort(
|
54
|
+
code_dict, p["runCodeBlocks"]
|
55
|
+
)
|
56
|
+
id_to_relpath = {}
|
57
|
+
for sid in to_write:
|
58
|
+
curr_code = code_dict[sid]
|
59
|
+
rel_path = write_code_to_file(
|
60
|
+
folder_path,
|
61
|
+
curr_code["sanitized_full_name"],
|
62
|
+
curr_code["code"],
|
63
|
+
curr_code["codeLanguage"],
|
64
|
+
)
|
65
|
+
id_to_relpath[sid] = rel_path
|
66
|
+
|
67
|
+
# Only run code that isn't referenced by other code
|
68
|
+
run_order = [
|
69
|
+
x for x in to_write if all(x not in y for y in section_dependencies.values())
|
70
|
+
]
|
71
|
+
|
72
|
+
# create a wrapper script if there are multiple files to run
|
73
|
+
if len(run_order) > 1:
|
74
|
+
rel_path = create_wrapper_bash_script(folder_path, run_order, code_dict)
|
75
|
+
command = codeCallStr(rel_path, "bash")
|
76
|
+
else:
|
77
|
+
sid = run_order[0]
|
78
|
+
command = codeCallStr(id_to_relpath[sid], code_dict[sid]["codeLanguage"])
|
79
|
+
|
80
|
+
return command
|
81
|
+
|
82
|
+
|
83
|
+
async def generate_final_code_for_sections(
|
84
|
+
p,
|
85
|
+
exporter_obj,
|
86
|
+
lsp_writers,
|
87
|
+
folder_path,
|
88
|
+
do_prepend_with_setup_code=False,
|
89
|
+
do_convert_var_names_to_readable_form=False,
|
90
|
+
push_var_name=None,
|
91
|
+
template_var_replacement_values=None,
|
92
|
+
):
|
93
|
+
code_sections = {
|
94
|
+
k: v for k, v in p["sections"].items() if get_section_type(p, k) == C.CODE
|
95
|
+
}
|
96
|
+
|
97
|
+
code_gen_template_var_section_details = (
|
98
|
+
exporter_obj.code_gen_template_var_section_details
|
99
|
+
)
|
100
|
+
|
101
|
+
if (
|
102
|
+
exporter_obj.force_include_template_var
|
103
|
+
and code_gen_template_var_section_details["section"]["id"] is None
|
104
|
+
):
|
105
|
+
code_sections[None] = code_gen_template_var_section_details["section"]
|
106
|
+
p["sectionPathFullNames"][None] = code_sections[None]["name"]
|
107
|
+
|
108
|
+
code_dict = {}
|
109
|
+
for s in code_sections.values():
|
110
|
+
if s["id"] is None:
|
111
|
+
section_variant = code_gen_template_var_section_details["sectionVariant"]
|
112
|
+
else:
|
113
|
+
section_variant = get_selected_section_variant(p, s["id"])
|
114
|
+
|
115
|
+
(
|
116
|
+
curr_code,
|
117
|
+
curr_section_dependencies,
|
118
|
+
curr_var_name_to_decl_rel_position_dict,
|
119
|
+
curr_ref_template_var_positions,
|
120
|
+
) = await generate_final_code_for_section(
|
121
|
+
sectionId=s["id"],
|
122
|
+
code=section_variant["code"],
|
123
|
+
codeLanguage=s["codeLanguage"],
|
124
|
+
evRefs=section_variant["evRefs"],
|
125
|
+
templateVars=section_variant["templateVars"],
|
126
|
+
exporter_obj=exporter_obj,
|
127
|
+
lsp_writers=lsp_writers,
|
128
|
+
folder_path=folder_path,
|
129
|
+
projectConfigName=p["projectConfig"]["name"],
|
130
|
+
do_prepend_with_setup_code=do_prepend_with_setup_code,
|
131
|
+
do_convert_var_names_to_readable_form=do_convert_var_names_to_readable_form,
|
132
|
+
template_var_replacement_values=template_var_replacement_values,
|
133
|
+
push_var_name=push_var_name,
|
134
|
+
)
|
135
|
+
|
136
|
+
sanitized_full_name = sanitize_section_path_full_name(
|
137
|
+
p["sectionPathFullNames"][s["id"]]
|
138
|
+
)
|
139
|
+
code_dict[s["id"]] = {
|
140
|
+
"name": s["name"],
|
141
|
+
"sanitized_full_name": sanitized_full_name,
|
142
|
+
"code": curr_code,
|
143
|
+
"codeLanguage": s["codeLanguage"],
|
144
|
+
"var_name_to_decl_rel_position_dict": curr_var_name_to_decl_rel_position_dict,
|
145
|
+
"ref_template_var_positions": curr_ref_template_var_positions,
|
146
|
+
"section_dependencies": curr_section_dependencies,
|
147
|
+
}
|
148
|
+
|
149
|
+
return code_dict
|
150
|
+
|
151
|
+
|
152
|
+
async def generate_final_code_for_section(
|
153
|
+
sectionId,
|
154
|
+
code,
|
155
|
+
codeLanguage,
|
156
|
+
evRefs,
|
157
|
+
templateVars,
|
158
|
+
exporter_obj,
|
159
|
+
lsp_writers,
|
160
|
+
folder_path,
|
161
|
+
projectConfigName=None,
|
162
|
+
do_prepend_with_setup_code=False,
|
163
|
+
do_convert_var_names_to_readable_form=False,
|
164
|
+
cursor_position=None,
|
165
|
+
template_var_replacement_values=None,
|
166
|
+
var_name_to_decl_rel_position_dict=None,
|
167
|
+
push_var_name=None,
|
168
|
+
):
|
169
|
+
setup_code = ""
|
170
|
+
section_dependencies = []
|
171
|
+
if var_name_to_decl_rel_position_dict is None:
|
172
|
+
var_name_to_decl_rel_position_dict = {}
|
173
|
+
if template_var_replacement_values is None:
|
174
|
+
template_var_replacement_values = {}
|
175
|
+
|
176
|
+
code, evRefs, templateVars, cursor_position = preprocess_template_vars(
|
177
|
+
code, evRefs, templateVars, cursor_position
|
178
|
+
)
|
179
|
+
|
180
|
+
(code, ref_template_var_positions) = process_refs(
|
181
|
+
code,
|
182
|
+
evRefs,
|
183
|
+
exporter_obj.get_ref_var_name,
|
184
|
+
cursor_position=cursor_position,
|
185
|
+
templateVars=templateVars,
|
186
|
+
get_template_var_replacement_value=get_template_var_replacement_value_fn(
|
187
|
+
exporter_obj,
|
188
|
+
folder_path,
|
189
|
+
codeLanguage,
|
190
|
+
section_dependencies,
|
191
|
+
var_name_to_decl_rel_position_dict,
|
192
|
+
template_var_replacement_values,
|
193
|
+
push_var_name,
|
194
|
+
),
|
195
|
+
)
|
196
|
+
|
197
|
+
if USER_SETTINGS["backend"]["inferImports"]:
|
198
|
+
(
|
199
|
+
code,
|
200
|
+
ref_template_var_positions["templateVars"],
|
201
|
+
) = await maybe_validate_imports_and_update_code(
|
202
|
+
sectionId, code, ref_template_var_positions, lsp_writers
|
203
|
+
)
|
204
|
+
|
205
|
+
if codeLanguage == "python":
|
206
|
+
if do_prepend_with_setup_code:
|
207
|
+
code, setup_code = prepend_with_setup_code(
|
208
|
+
code,
|
209
|
+
codeLanguage,
|
210
|
+
folder_path,
|
211
|
+
projectConfigName,
|
212
|
+
)
|
213
|
+
|
214
|
+
if do_convert_var_names_to_readable_form:
|
215
|
+
code = convert_var_names_to_readable_form(
|
216
|
+
code,
|
217
|
+
var_name_to_decl_rel_position_dict.get(
|
218
|
+
tp(C.SETTA_GENERATED_PYTHON), {}
|
219
|
+
),
|
220
|
+
exporter_obj,
|
221
|
+
ref_template_var_positions,
|
222
|
+
setup_code,
|
223
|
+
)
|
224
|
+
|
225
|
+
return (
|
226
|
+
code,
|
227
|
+
section_dependencies,
|
228
|
+
var_name_to_decl_rel_position_dict,
|
229
|
+
ref_template_var_positions,
|
230
|
+
)
|
231
|
+
|
232
|
+
|
233
|
+
def get_template_var_replacement_value_fn(
|
234
|
+
exporter_obj,
|
235
|
+
folder_path,
|
236
|
+
codeLanguage,
|
237
|
+
section_dependencies,
|
238
|
+
var_name_to_decl_rel_position_dict,
|
239
|
+
template_var_replacement_values,
|
240
|
+
push_var_name,
|
241
|
+
):
|
242
|
+
def get_template_var_replacement_value(
|
243
|
+
code, template_var, ref_template_var_positions
|
244
|
+
):
|
245
|
+
keyword = template_var["keyword"]
|
246
|
+
if keyword in template_var_replacement_values:
|
247
|
+
if template_var["sectionId"]:
|
248
|
+
section_dependencies.append(template_var["sectionId"])
|
249
|
+
return template_var_replacement_values[keyword]
|
250
|
+
if codeLanguage == "python":
|
251
|
+
if keyword == tp(C.SETTA_GENERATED_PYTHON):
|
252
|
+
chars_before_template_var = get_chars_in_line_before_position(
|
253
|
+
code, template_var["startPos"]
|
254
|
+
)
|
255
|
+
|
256
|
+
code, var_name_to_decl_rel_position_dict[keyword] = generate_code(
|
257
|
+
exporter_obj.output,
|
258
|
+
chars_before_template_var,
|
259
|
+
push_var_name,
|
260
|
+
)
|
261
|
+
return code
|
262
|
+
elif keyword == tp(C.SETTA_GENERATED_PYTHON_IMPORTS):
|
263
|
+
chars_before_template_var = get_chars_in_line_before_position(
|
264
|
+
code, template_var["startPos"]
|
265
|
+
)
|
266
|
+
gen_code_template_var = get_gen_code_template_var(
|
267
|
+
ref_template_var_positions["templateVars"]
|
268
|
+
)
|
269
|
+
var_name_to_decl_position = (
|
270
|
+
get_absolute_decl_position_from_rel_position(
|
271
|
+
gen_code_template_var,
|
272
|
+
var_name_to_decl_rel_position_dict,
|
273
|
+
)
|
274
|
+
)
|
275
|
+
return generate_imports(
|
276
|
+
code,
|
277
|
+
push_var_name,
|
278
|
+
var_name_to_decl_position,
|
279
|
+
template_var,
|
280
|
+
chars_before_template_var,
|
281
|
+
)
|
282
|
+
else:
|
283
|
+
section_dependencies.append(template_var["sectionId"])
|
284
|
+
keyword = remove_tp(keyword)
|
285
|
+
return construct_module_path(folder_path, keyword)
|
286
|
+
elif codeLanguage == "bash":
|
287
|
+
section_dependencies.append(template_var["sectionId"])
|
288
|
+
keyword = sanitize_section_path_full_name(remove_tp(keyword))
|
289
|
+
return codePathStr(Path(os.path.relpath(folder_path)), keyword, "python")
|
290
|
+
|
291
|
+
return get_template_var_replacement_value
|
292
|
+
|
293
|
+
|
294
|
+
def get_absolute_decl_position_from_rel_position(
|
295
|
+
template_var, var_name_to_decl_rel_position_dict
|
296
|
+
):
|
297
|
+
return {
|
298
|
+
k: (v[0] + template_var["startPos"], v[1], v[2])
|
299
|
+
for k, v in var_name_to_decl_rel_position_dict[template_var["keyword"]].items()
|
300
|
+
}
|
301
|
+
|
302
|
+
|
303
|
+
def preprocess_template_vars(code, evRefs, templateVars, cursor_position):
|
304
|
+
has_gen_code = None
|
305
|
+
has_gen_code_import = False
|
306
|
+
for t in templateVars:
|
307
|
+
if t["keyword"] == tp(C.SETTA_GENERATED_PYTHON):
|
308
|
+
has_gen_code = True
|
309
|
+
elif t["keyword"] == tp(C.SETTA_GENERATED_PYTHON_IMPORTS):
|
310
|
+
t["processLast"] = True
|
311
|
+
has_gen_code_import = True
|
312
|
+
|
313
|
+
if (
|
314
|
+
has_gen_code
|
315
|
+
and not has_gen_code_import
|
316
|
+
and USER_SETTINGS["backend"]["inferImports"]
|
317
|
+
):
|
318
|
+
evRefs = copy.deepcopy(evRefs)
|
319
|
+
templateVars = copy.deepcopy(templateVars)
|
320
|
+
keyword = tp(C.SETTA_GENERATED_PYTHON_IMPORTS)
|
321
|
+
keyword_new_line = f"{keyword}\n"
|
322
|
+
code = f"{keyword_new_line}{code}"
|
323
|
+
shiftAmount = len(keyword_new_line)
|
324
|
+
for x in evRefs:
|
325
|
+
x["startPos"] += shiftAmount
|
326
|
+
for x in templateVars:
|
327
|
+
x["startPos"] += shiftAmount
|
328
|
+
|
329
|
+
if cursor_position is not None:
|
330
|
+
cursor_position += shiftAmount
|
331
|
+
|
332
|
+
templateVars.append(
|
333
|
+
{"startPos": 0, "keyword": keyword, "sectionId": None, "processLast": True}
|
334
|
+
)
|
335
|
+
|
336
|
+
return code, evRefs, templateVars, cursor_position
|
337
|
+
|
338
|
+
|
339
|
+
def convert_folder_path_to_module_path(folder_path):
|
340
|
+
return os.path.relpath(folder_path).replace("/", ".").replace("\\", ".")
|
341
|
+
|
342
|
+
|
343
|
+
def languageToExtension(x):
|
344
|
+
return {"python": ".py", "bash": ".sh", "yaml": ".yaml"}[x]
|
345
|
+
|
346
|
+
|
347
|
+
def languageToCall(x):
|
348
|
+
return {"python": "python", "bash": "bash"}[x]
|
349
|
+
|
350
|
+
|
351
|
+
def codePathStr(folder_path, filename, codeLanguage):
|
352
|
+
extension = languageToExtension(codeLanguage)
|
353
|
+
output = folder_path / f"{filename}{extension}"
|
354
|
+
return os.path.relpath(output).replace(os.sep, "/")
|
355
|
+
|
356
|
+
|
357
|
+
def codeCallStr(filepath, codeLanguage):
|
358
|
+
return f"{languageToCall(codeLanguage)} {filepath}"
|
359
|
+
|
360
|
+
|
361
|
+
def create_wrapper_bash_script(folder_path, run_order, code_dict):
|
362
|
+
bash_script = ""
|
363
|
+
for sid in run_order:
|
364
|
+
curr_code = code_dict[sid]
|
365
|
+
codePath = codePathStr(
|
366
|
+
folder_path, curr_code["name"], curr_code["codeLanguage"]
|
367
|
+
)
|
368
|
+
bash_script += f'{codeCallStr(codePath, curr_code["codeLanguage"])}\n'
|
369
|
+
return write_code_to_file(
|
370
|
+
folder_path, C.DEFAULT_BASH_SCRIPT_NAME, bash_script, "bash"
|
371
|
+
)
|
372
|
+
|
373
|
+
|
374
|
+
def prune_and_topological_sort(code_dict, to_keep):
|
375
|
+
section_dependencies = {k: v["section_dependencies"] for k, v in code_dict.items()}
|
376
|
+
section_dependencies = prune_dict(section_dependencies, to_keep)
|
377
|
+
return topological_sort(section_dependencies), section_dependencies
|
378
|
+
|
379
|
+
|
380
|
+
def topological_sort(objects):
|
381
|
+
graph = {id: refs for id, refs in objects.items()}
|
382
|
+
visiting, visited = set(), set()
|
383
|
+
order = []
|
384
|
+
|
385
|
+
def dfs(node):
|
386
|
+
if node in visiting:
|
387
|
+
raise ValueError("Circular reference detected")
|
388
|
+
if node not in visited:
|
389
|
+
visiting.add(node)
|
390
|
+
for neighbour in graph[node]:
|
391
|
+
dfs(neighbour)
|
392
|
+
visiting.remove(node)
|
393
|
+
visited.add(node)
|
394
|
+
order.append(node)
|
395
|
+
|
396
|
+
for id in objects.keys():
|
397
|
+
if id not in visited:
|
398
|
+
dfs(id)
|
399
|
+
|
400
|
+
return order[::-1]
|
401
|
+
|
402
|
+
|
403
|
+
def create_timestamped_folder(base_dir, prefix=""):
|
404
|
+
# Format the current timestamp with subsecond precision
|
405
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")
|
406
|
+
# Create folder name with optional prefix and subsecond precision
|
407
|
+
folder_name = f"_{prefix}{timestamp}"
|
408
|
+
# Full path for the new folder
|
409
|
+
folder_path = Path(base_dir) / folder_name
|
410
|
+
|
411
|
+
if not os.path.exists(folder_path):
|
412
|
+
try:
|
413
|
+
os.makedirs(folder_path)
|
414
|
+
except FileExistsError:
|
415
|
+
pass
|
416
|
+
|
417
|
+
return folder_path
|
418
|
+
|
419
|
+
|
420
|
+
def write_code_to_file(folder_path, filename, code, codeLanguage):
|
421
|
+
extension = languageToExtension(codeLanguage)
|
422
|
+
filepath = write_string_to_file(folder_path, f"{filename}{extension}", code)
|
423
|
+
return os.path.relpath(filepath).replace(os.sep, "/")
|
424
|
+
|
425
|
+
|
426
|
+
def write_string_to_file(folder, filename, content):
|
427
|
+
# Full path to the file
|
428
|
+
file_path = os.path.join(folder, filename)
|
429
|
+
# Write the content to the file
|
430
|
+
with open(file_path, "w") as file:
|
431
|
+
file.write(content)
|
432
|
+
return file_path
|
433
|
+
|
434
|
+
|
435
|
+
def prepend_with_setup_code(code, codeLanguage, folder_path, project_config_name):
|
436
|
+
setup_code = ""
|
437
|
+
if codeLanguage == "python":
|
438
|
+
setup_code = (
|
439
|
+
"import sys\n"
|
440
|
+
"import os\n"
|
441
|
+
"sys.path.append(os.getcwd())\n"
|
442
|
+
f"os.environ['{CODE_FOLDER_ENV_VARIABLE}'] = '{folder_path}'\n"
|
443
|
+
)
|
444
|
+
code = setup_code + code
|
445
|
+
return code, setup_code
|
446
|
+
|
447
|
+
|
448
|
+
def construct_module_path(folder_path, section_path_full_name):
|
449
|
+
module_path = convert_folder_path_to_module_path(folder_path)
|
450
|
+
filename = sanitize_section_path_full_name(section_path_full_name)
|
451
|
+
return f"{module_path}.{filename}"
|
452
|
+
|
453
|
+
|
454
|
+
def sanitize_section_path_full_name(name):
|
455
|
+
# Replace brackets, quotes and other invalid chars with underscores
|
456
|
+
invalid_chars = "[]\"' "
|
457
|
+
name = "".join("_" if c in invalid_chars else c for c in name)
|
458
|
+
|
459
|
+
# Remove consecutive underscores
|
460
|
+
while "__" in name:
|
461
|
+
name = name.replace("__", "_")
|
462
|
+
|
463
|
+
# Remove leading/trailing underscores
|
464
|
+
name = name.strip("_")
|
465
|
+
|
466
|
+
return name
|