setta 0.0.9.dev3__py3-none-any.whl → 0.0.10__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.
- setta/__init__.py +1 -1
- setta/database/db/projects/load.py +1 -3
- setta/database/db/projects/save.py +2 -2
- setta/database/db/projects/utils.py +3 -3
- setta/database/db/sectionVariants/copy.py +3 -11
- setta/database/db/sections/copy.py +1 -1
- setta/database/db/sections/jsonSource.py +45 -114
- setta/database/db/sections/load.py +68 -134
- setta/database/settings_file.py +3 -3
- setta/routers/sections.py +6 -10
- setta/static/constants/defaultValues.json +6 -7
- setta/static/constants/settingsProject.json +71 -72
- setta/static/frontend/assets/{index-0693b9a1.js → index-0304307e.js} +128 -128
- setta/static/frontend/assets/index-030463f6.css +32 -0
- setta/static/frontend/index.html +2 -2
- setta/utils/constants.py +10 -4
- {setta-0.0.9.dev3.dist-info → setta-0.0.10.dist-info}/METADATA +8 -10
- {setta-0.0.9.dev3.dist-info → setta-0.0.10.dist-info}/RECORD +22 -22
- setta/static/frontend/assets/index-cf887608.css +0 -32
- {setta-0.0.9.dev3.dist-info → setta-0.0.10.dist-info}/LICENSE +0 -0
- {setta-0.0.9.dev3.dist-info → setta-0.0.10.dist-info}/WHEEL +0 -0
- {setta-0.0.9.dev3.dist-info → setta-0.0.10.dist-info}/entry_points.txt +0 -0
- {setta-0.0.9.dev3.dist-info → setta-0.0.10.dist-info}/top_level.txt +0 -0
setta/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.0.
|
1
|
+
__version__ = "0.0.10"
|
@@ -128,9 +128,7 @@ def load_project_config(db, project_config_name, do_load_json_sources=True):
|
|
128
128
|
load_ev_refs_into_data_structures(db, sectionVariants, codeInfo)
|
129
129
|
load_template_vars_into_data_structures(db, sectionVariants)
|
130
130
|
if do_load_json_sources:
|
131
|
-
load_json_sources_into_data_structures(
|
132
|
-
sections, codeInfo, codeInfoCols, sectionVariants
|
133
|
-
)
|
131
|
+
load_json_sources_into_data_structures(codeInfo, codeInfoCols, sectionVariants)
|
134
132
|
|
135
133
|
return {
|
136
134
|
"projectConfig": projectConfig,
|
@@ -15,7 +15,7 @@ from setta.utils.generate_memorable_string import generate_memorable_available_s
|
|
15
15
|
from setta.utils.utils import filter_dict
|
16
16
|
|
17
17
|
from ..codeInfo.save import save_code_info, save_code_info_col
|
18
|
-
from ..sections.jsonSource import
|
18
|
+
from ..sections.jsonSource import remove_json_source_values, save_json_source_data
|
19
19
|
from ..sections.save import save_sections
|
20
20
|
from ..sectionVariants.save import save_section_variants
|
21
21
|
from ..uiTypes.save import save_ui_type_cols, save_ui_types
|
@@ -24,7 +24,7 @@ from ..uiTypes.save import save_ui_type_cols, save_ui_types
|
|
24
24
|
def save_project_details(db, p, do_save_json_source_data=True):
|
25
25
|
if do_save_json_source_data:
|
26
26
|
save_json_source_data(p)
|
27
|
-
|
27
|
+
remove_json_source_values(p)
|
28
28
|
save_artifacts(db, p["artifacts"])
|
29
29
|
save_artifact_groups(db, p["artifactGroups"], p["sections"])
|
30
30
|
save_code_info(db, p["codeInfo"])
|
@@ -5,7 +5,7 @@ from setta.database.db.codeInfo.utils import (
|
|
5
5
|
add_defaults_to_code_info,
|
6
6
|
add_defaults_to_code_info_cols,
|
7
7
|
)
|
8
|
-
from setta.database.db.sections.jsonSource import
|
8
|
+
from setta.database.db.sections.jsonSource import remove_json_source_values
|
9
9
|
from setta.database.db.sections.load import load_json_sources_into_data_structures
|
10
10
|
from setta.database.db.sections.utils import add_defaults_to_sections
|
11
11
|
from setta.database.db.sectionVariants.utils import add_defaults_to_section_variants
|
@@ -35,7 +35,7 @@ def add_defaults_to_project(p):
|
|
35
35
|
def add_defaults_to_project_and_load_json_sources(p):
|
36
36
|
add_defaults_to_project(p)
|
37
37
|
load_json_sources_into_data_structures(
|
38
|
-
p["
|
38
|
+
p["codeInfo"], p["codeInfoCols"], p["sectionVariants"]
|
39
39
|
)
|
40
40
|
|
41
41
|
|
@@ -44,7 +44,7 @@ def remove_empty(x):
|
|
44
44
|
|
45
45
|
|
46
46
|
def filter_data_for_json_export(p):
|
47
|
-
|
47
|
+
remove_json_source_values(p)
|
48
48
|
|
49
49
|
p["projectConfig"] = filter_dict(
|
50
50
|
p["projectConfig"],
|
@@ -2,19 +2,11 @@ from setta.database.utils import remap_ids, rename_keys
|
|
2
2
|
from setta.utils.generate_memorable_string import generate_memorable_string
|
3
3
|
|
4
4
|
|
5
|
-
def copy_section_variants(
|
6
|
-
sections, section_variants, code_info_id_map, code_info_col_id_map
|
7
|
-
):
|
5
|
+
def copy_section_variants(section_variants, code_info_id_map, code_info_col_id_map):
|
8
6
|
new_section_variants, section_variant_id_map = remap_ids(section_variants)
|
9
|
-
keep_old_name = set()
|
10
|
-
for s in sections.values():
|
11
|
-
if not s["jsonSource"]:
|
12
|
-
continue
|
13
|
-
for v in s["variantIds"]:
|
14
|
-
keep_old_name.add(section_variant_id_map[v])
|
15
7
|
|
16
|
-
for
|
17
|
-
if
|
8
|
+
for obj in new_section_variants.values():
|
9
|
+
if not obj["isJsonSource"]:
|
18
10
|
obj["name"] = generate_memorable_string()
|
19
11
|
obj["values"] = rename_keys(obj["values"], code_info_id_map)
|
20
12
|
if obj["codeInfoColId"]:
|
@@ -44,7 +44,7 @@ def copy_sections_and_other_info(x):
|
|
44
44
|
x["codeInfoCols"], code_info_id_map
|
45
45
|
)
|
46
46
|
new_section_variants, section_variant_id_map = copy_section_variants(
|
47
|
-
x["
|
47
|
+
x["sectionVariants"], code_info_id_map, code_info_col_id_map
|
48
48
|
)
|
49
49
|
new_ui_types, ui_type_id_map = copy_ui_types(x["uiTypes"])
|
50
50
|
new_ui_type_cols, ui_type_col_id_map = copy_ui_type_cols(
|
@@ -1,77 +1,61 @@
|
|
1
|
-
import json
|
2
1
|
from collections import defaultdict
|
3
2
|
|
4
|
-
from setta.utils.
|
5
|
-
from setta.utils.utils import (
|
6
|
-
recursive_dict_merge,
|
7
|
-
replace_null_keys_with_none,
|
8
|
-
save_json_to_file,
|
9
|
-
try_json,
|
10
|
-
)
|
3
|
+
from setta.utils.utils import replace_null_keys_with_none, save_json_to_file, try_json
|
11
4
|
|
12
5
|
|
13
|
-
def save_json_source_data(p,
|
14
|
-
|
6
|
+
def save_json_source_data(p, variant_ids=None):
|
7
|
+
variants = {
|
15
8
|
k: v
|
16
|
-
for k, v in p["
|
17
|
-
if
|
9
|
+
for k, v in p["sectionVariants"].items()
|
10
|
+
if ((not variant_ids) or k in variant_ids)
|
18
11
|
}
|
19
12
|
|
20
13
|
to_be_saved = defaultdict(dict)
|
21
14
|
|
22
|
-
forking_from_data = {}
|
23
|
-
if forking_from:
|
24
|
-
with open(forking_from, "r") as f:
|
25
|
-
forking_from_data = json.load(f)
|
26
|
-
|
27
15
|
p["codeInfoCols"] = replace_null_keys_with_none(p["codeInfoCols"])
|
28
16
|
|
29
|
-
|
30
|
-
|
31
|
-
for s in sections.values():
|
32
|
-
if not s["jsonSource"] or s["jsonSourceMissing"]:
|
17
|
+
for variant in variants.values():
|
18
|
+
if not variant["isJsonSource"]:
|
33
19
|
continue
|
20
|
+
codeInfoColId = variant["codeInfoColId"]
|
21
|
+
if not codeInfoColId:
|
22
|
+
continue
|
23
|
+
codeInfoCol = p["codeInfoCols"][codeInfoColId]
|
24
|
+
filename = variant["name"]
|
25
|
+
|
26
|
+
ancestor_paths = build_ancestor_paths(p["codeInfo"], codeInfoCol["children"])
|
27
|
+
recursively_add_keys(
|
28
|
+
p,
|
29
|
+
variant,
|
30
|
+
codeInfoCol,
|
31
|
+
to_be_saved[filename],
|
32
|
+
None,
|
33
|
+
variant["jsonSourceKeys"],
|
34
|
+
ancestor_paths,
|
35
|
+
)
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
codeInfoCol = p["codeInfoCols"][codeInfoColId]
|
39
|
-
filename = variant["name"]
|
40
|
-
|
41
|
-
recursively_add_keys(
|
42
|
-
p,
|
43
|
-
variant,
|
44
|
-
codeInfoCol,
|
45
|
-
to_be_saved[filename],
|
46
|
-
None,
|
47
|
-
s["jsonSourceKeys"],
|
48
|
-
ancestor_paths,
|
49
|
-
)
|
50
|
-
|
51
|
-
# Make sure the jsonSourceKeys are present.
|
52
|
-
# (They might not be because they are completely empty)
|
53
|
-
add_key_path_to_dict(to_be_saved[filename], s["jsonSourceKeys"])
|
37
|
+
# Make sure the jsonSourceKeys are present.
|
38
|
+
# (They might not be because they are completely empty)
|
39
|
+
add_key_path_to_dict(to_be_saved[filename], variant["jsonSourceKeys"])
|
54
40
|
|
55
41
|
# Save each file
|
56
42
|
for filename, data in to_be_saved.items():
|
57
|
-
data = recursive_dict_merge(forking_from_data, data)
|
58
43
|
save_json_to_file(filename, data)
|
59
44
|
|
60
45
|
return to_be_saved
|
61
46
|
|
62
47
|
|
63
|
-
def build_ancestor_paths(codeInfo,
|
48
|
+
def build_ancestor_paths(codeInfo, codeInfoColChildren):
|
64
49
|
parent_map = {}
|
65
|
-
for
|
66
|
-
for
|
67
|
-
|
68
|
-
parent_map[(codeInfo[child_id]["jsonSource"], child_id)] = parent_id
|
50
|
+
for parent_id, children in codeInfoColChildren.items():
|
51
|
+
for child_id in children:
|
52
|
+
parent_map[child_id] = parent_id
|
69
53
|
|
70
54
|
ancestor_paths = {}
|
71
|
-
for
|
72
|
-
if
|
55
|
+
for id in parent_map.keys():
|
56
|
+
if id not in ancestor_paths:
|
73
57
|
path = []
|
74
|
-
current_id =
|
58
|
+
current_id = id
|
75
59
|
|
76
60
|
# Traverse up to build the path
|
77
61
|
while current_id is not None:
|
@@ -80,14 +64,12 @@ def build_ancestor_paths(codeInfo, codeInfoCols):
|
|
80
64
|
path.insert(0, name)
|
81
65
|
|
82
66
|
# Get parent using the map
|
83
|
-
parent_id = parent_map.get(
|
84
|
-
(codeInfo[current_id]["jsonSource"], current_id)
|
85
|
-
)
|
67
|
+
parent_id = parent_map.get(current_id)
|
86
68
|
current_id = parent_id
|
87
69
|
else:
|
88
70
|
break
|
89
71
|
|
90
|
-
ancestor_paths[
|
72
|
+
ancestor_paths[id] = path
|
91
73
|
|
92
74
|
return ancestor_paths
|
93
75
|
|
@@ -97,20 +79,16 @@ def recursively_add_keys(
|
|
97
79
|
):
|
98
80
|
for k in codeInfoCol["children"][codeInfoId]:
|
99
81
|
children = codeInfoCol["children"][k]
|
100
|
-
json_source = p["codeInfo"][k].get("jsonSource")
|
101
82
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
83
|
+
# Get pre-computed key path
|
84
|
+
key_path = [*jsonSourceKeys, *ancestor_paths[k]]
|
85
|
+
value = try_getting_value(variant, k, children)
|
86
|
+
current_dict = add_key_path_to_dict(input_dict, key_path[:-1])
|
106
87
|
|
107
|
-
|
88
|
+
# Set the value at the final position
|
89
|
+
if key_path: # Only set if we have a path
|
90
|
+
current_dict[key_path[-1]] = value
|
108
91
|
|
109
|
-
# Set the value at the final position
|
110
|
-
if key_path: # Only set if we have a path
|
111
|
-
current_dict[key_path[-1]] = value
|
112
|
-
|
113
|
-
# Continue recursion regardless of whether this node has a jsonSource
|
114
92
|
recursively_add_keys(
|
115
93
|
p, variant, codeInfoCol, input_dict, k, jsonSourceKeys, ancestor_paths
|
116
94
|
)
|
@@ -133,54 +111,7 @@ def try_getting_value(variant, codeInfoId, codeInfoChildren):
|
|
133
111
|
return {}
|
134
112
|
|
135
113
|
|
136
|
-
def
|
137
|
-
if not codeInfo:
|
138
|
-
return False
|
139
|
-
return not codeInfo["jsonSource"] or codeInfo["id"] in jsonCodeInfoWithUIType
|
140
|
-
|
141
|
-
|
142
|
-
def remove_json_source_data(p):
|
114
|
+
def remove_json_source_values(p):
|
143
115
|
for variant in p["sectionVariants"].values():
|
144
|
-
variant["
|
145
|
-
|
146
|
-
for k, v in variant["values"].items()
|
147
|
-
if not p["codeInfo"][k]["jsonSource"]
|
148
|
-
}
|
149
|
-
|
150
|
-
jsonCodeInfoWithUIType = set()
|
151
|
-
for uiTypeCol in p["uiTypeCols"].values():
|
152
|
-
for paramInfoId, uiTypeInfo in uiTypeCol.items():
|
153
|
-
# we want to know which json source params have an associated uiTypeId
|
154
|
-
# only if it's not the base TEXT type, since that's the default
|
155
|
-
if (
|
156
|
-
p["codeInfo"][paramInfoId]["jsonSource"]
|
157
|
-
and uiTypeInfo["uiTypeId"] != BASE_UI_TYPE_IDS[C.TEXT]
|
158
|
-
):
|
159
|
-
jsonCodeInfoWithUIType.add(paramInfoId)
|
160
|
-
|
161
|
-
p["codeInfo"] = {
|
162
|
-
k: v
|
163
|
-
for k, v in p["codeInfo"].items()
|
164
|
-
if condition_keep_code_info(v, jsonCodeInfoWithUIType)
|
165
|
-
}
|
166
|
-
|
167
|
-
for codeInfoColId in p["codeInfoCols"].keys():
|
168
|
-
codeInfoCol = p["codeInfoCols"][codeInfoColId]
|
169
|
-
codeInfoCol["children"] = {
|
170
|
-
k: v
|
171
|
-
for k, v in codeInfoCol["children"].items()
|
172
|
-
if k is None
|
173
|
-
or condition_keep_code_info(
|
174
|
-
p["codeInfo"].get(k),
|
175
|
-
jsonCodeInfoWithUIType,
|
176
|
-
)
|
177
|
-
}
|
178
|
-
for id, children in codeInfoCol["children"].items():
|
179
|
-
codeInfoCol["children"][id] = [
|
180
|
-
c
|
181
|
-
for c in children
|
182
|
-
if condition_keep_code_info(
|
183
|
-
p["codeInfo"].get(c),
|
184
|
-
jsonCodeInfoWithUIType,
|
185
|
-
)
|
186
|
-
]
|
116
|
+
if variant["isJsonSource"]:
|
117
|
+
variant["values"] = {}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import copy
|
2
|
-
import glob
|
3
2
|
import itertools
|
4
3
|
import json
|
5
4
|
import logging
|
@@ -9,7 +8,7 @@ from setta.database.db.artifacts.load import load_artifact_groups
|
|
9
8
|
from setta.database.db.codeInfo.utils import new_code_info_col, with_code_info_defaults
|
10
9
|
from setta.database.db.sections.jsonSource import build_ancestor_paths
|
11
10
|
from setta.database.db.sections.utils import with_section_defaults
|
12
|
-
from setta.database.db.sectionVariants.utils import new_ev_entry
|
11
|
+
from setta.database.db.sectionVariants.utils import new_ev_entry
|
13
12
|
from setta.database.utils import create_new_id
|
14
13
|
|
15
14
|
from ..sectionVariants.load import load_section_variants
|
@@ -201,148 +200,84 @@ def num_projects_each_section_exists_in(db, section_ids):
|
|
201
200
|
|
202
201
|
|
203
202
|
def load_json_sources_into_data_structures(
|
204
|
-
|
203
|
+
codeInfo, codeInfoCols, sectionVariants, variant_ids=None
|
205
204
|
):
|
206
|
-
|
207
|
-
sections = {
|
205
|
+
sectionVariants = {
|
208
206
|
k: v
|
209
|
-
for k, v in
|
210
|
-
if
|
207
|
+
for k, v in sectionVariants.items()
|
208
|
+
if ((not variant_ids) or k in variant_ids)
|
211
209
|
}
|
212
|
-
for s in sections.values():
|
213
|
-
logger.debug(
|
214
|
-
f'Attempting to read {s["jsonSource"]} with keys {s["jsonSourceKeys"]}'
|
215
|
-
)
|
216
|
-
new_data = load_json_source(s["jsonSource"], s["jsonSourceKeys"])
|
217
|
-
filenames_loaded.update(
|
218
|
-
merge_into_existing(new_data, s, sectionVariants, codeInfo, codeInfoCols)
|
219
|
-
)
|
220
210
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
211
|
+
for variant in sectionVariants.values():
|
212
|
+
if not variant["isJsonSource"]:
|
213
|
+
continue
|
214
|
+
new_data, isMissing = load_json_source(
|
215
|
+
variant["name"], variant["jsonSourceKeys"]
|
216
|
+
)
|
217
|
+
variant["jsonSourcMissing"] = isMissing
|
218
|
+
if not isMissing:
|
219
|
+
if not variant["codeInfoColId"]:
|
220
|
+
variant["codeInfoColId"] = create_new_id()
|
221
|
+
codeInfoCols[variant["codeInfoColId"]] = new_code_info_col()
|
222
|
+
codeInfoCol = codeInfoCols[variant["codeInfoColId"]]
|
223
|
+
merge_into_existing(new_data, variant, codeInfo, codeInfoCol)
|
230
224
|
|
231
|
-
for vid in to_delete:
|
232
|
-
if sectionVariants[vid]["codeInfoColId"]:
|
233
|
-
del codeInfoCols[sectionVariants[vid]["codeInfoColId"]]
|
234
|
-
del sectionVariants[vid]
|
235
225
|
|
236
|
-
|
237
|
-
|
238
|
-
s["variantIds"] = [v for v in s["variantIds"] if v in sectionVariants]
|
239
|
-
if len(s["variantIds"]) == 0:
|
240
|
-
logger.debug("Section has no variantIds. Creating new section variant.")
|
241
|
-
variantId, variant = new_section_variant()
|
242
|
-
sectionVariants[variantId] = variant
|
243
|
-
s["variantId"] = variantId
|
244
|
-
s["variantIds"].append(variantId)
|
245
|
-
s["jsonSourceMissing"] = True
|
246
|
-
elif s["variantId"] not in s["variantIds"]:
|
247
|
-
logger.debug(
|
248
|
-
"Selected variantId is not in list of variantIds. Changing selected variantId"
|
249
|
-
)
|
250
|
-
s["variantId"] = s["variantIds"][0]
|
251
|
-
|
252
|
-
if s["defaultVariantId"] not in s["variantIds"]:
|
253
|
-
logger.debug(
|
254
|
-
"Default variantId is not in list of variantIds. Changing default variantId"
|
255
|
-
)
|
256
|
-
s["defaultVariantId"] = s["variantId"]
|
257
|
-
|
258
|
-
|
259
|
-
def merge_into_existing(new_data, section, sectionVariants, codeInfo, codeInfoCols):
|
260
|
-
filenames_loaded = set()
|
226
|
+
def merge_into_existing(data, sectionVariant, codeInfo, codeInfoCol):
|
227
|
+
filename = sectionVariant["name"]
|
261
228
|
jsonSourceMetadata_to_id = {}
|
262
|
-
ancestor_paths = build_ancestor_paths(codeInfo,
|
263
|
-
for id
|
229
|
+
ancestor_paths = build_ancestor_paths(codeInfo, codeInfoCol["children"])
|
230
|
+
for id in ancestor_paths:
|
264
231
|
jsonSourceMetadata_to_id[
|
265
|
-
createMetadataJsonString(
|
232
|
+
createMetadataJsonString(filename, ancestor_paths[id])
|
266
233
|
] = id
|
267
234
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
235
|
+
replacements = {}
|
236
|
+
new_ancestor_paths = build_ancestor_paths(
|
237
|
+
data["codeInfo"], data["codeInfoColChildren"]
|
238
|
+
)
|
239
|
+
for newId, newInfo in data["codeInfo"].items():
|
240
|
+
existingId = jsonSourceMetadata_to_id.get(
|
241
|
+
createMetadataJsonString(filename, new_ancestor_paths[newId])
|
272
242
|
)
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
variantId = None
|
299
|
-
for vid in section["variantIds"]:
|
300
|
-
if sectionVariants[vid]["name"] == filename:
|
301
|
-
variantId = vid
|
302
|
-
break
|
303
|
-
if not variantId:
|
304
|
-
variantId, section_variant = new_section_variant(
|
305
|
-
name=filename,
|
306
|
-
)
|
307
|
-
section["variantIds"].append(variantId)
|
308
|
-
sectionVariants[variantId] = section_variant
|
309
|
-
|
310
|
-
curr_section_variant = sectionVariants[variantId]
|
311
|
-
curr_section_variant["values"] = data["sectionVariantValues"]
|
312
|
-
codeInfoColId = curr_section_variant["codeInfoColId"]
|
313
|
-
|
314
|
-
if not codeInfoColId:
|
315
|
-
codeInfoColId = create_new_id()
|
316
|
-
curr_section_variant["codeInfoColId"] = codeInfoColId
|
317
|
-
codeInfoCols[codeInfoColId] = new_code_info_col()
|
318
|
-
|
319
|
-
codeInfoCols[codeInfoColId]["children"] = data["codeInfoColChildren"]
|
320
|
-
|
321
|
-
section["configLanguage"] = "json"
|
322
|
-
filenames_loaded.add(filename)
|
323
|
-
|
324
|
-
return filenames_loaded
|
325
|
-
|
326
|
-
|
327
|
-
def load_json_source(filename_glob, jsonSourceKeys):
|
328
|
-
new_data = {}
|
329
|
-
|
330
|
-
filenames = glob.glob(filename_glob)
|
331
|
-
for filename in filenames:
|
332
|
-
try:
|
333
|
-
with open(filename, "r") as f:
|
334
|
-
jsonSourceData = json.load(f)
|
335
|
-
except json.JSONDecodeError:
|
336
|
-
jsonSourceData = {}
|
337
|
-
except FileNotFoundError:
|
338
|
-
logger.debug(f"couldn't find: {filename}")
|
339
|
-
continue
|
243
|
+
if existingId:
|
244
|
+
replacements[newId] = existingId
|
245
|
+
else:
|
246
|
+
codeInfo[newId] = newInfo
|
247
|
+
|
248
|
+
for newId, existingId in replacements.items():
|
249
|
+
del data["codeInfo"][newId]
|
250
|
+
data["codeInfoColChildren"][existingId] = [
|
251
|
+
replacements.get(x, x) for x in data["codeInfoColChildren"][newId]
|
252
|
+
]
|
253
|
+
data["codeInfoColChildren"][None] = [
|
254
|
+
replacements.get(x, x) for x in data["codeInfoColChildren"][None]
|
255
|
+
]
|
256
|
+
del data["codeInfoColChildren"][newId]
|
257
|
+
data["sectionVariantValues"][existingId] = data["sectionVariantValues"][newId]
|
258
|
+
del data["sectionVariantValues"][newId]
|
259
|
+
|
260
|
+
sectionVariant["values"] = data["sectionVariantValues"]
|
261
|
+
codeInfoCol["children"] = data["codeInfoColChildren"]
|
262
|
+
|
263
|
+
|
264
|
+
def load_json_source(filename, jsonSourceKeys):
|
265
|
+
jsonSourceData = {}
|
266
|
+
isMissing = False
|
340
267
|
|
341
|
-
|
342
|
-
|
343
|
-
)
|
268
|
+
try:
|
269
|
+
logger.debug(f"Attempting to read {filename} with keys {jsonSourceKeys}")
|
270
|
+
with open(filename, "r") as f:
|
271
|
+
jsonSourceData = json.load(f)
|
272
|
+
except json.JSONDecodeError:
|
273
|
+
pass
|
274
|
+
except FileNotFoundError:
|
275
|
+
logger.debug(f"couldn't find: {filename}")
|
276
|
+
isMissing = True
|
344
277
|
|
345
|
-
|
278
|
+
new_data = process_json_object(jsonSourceData, filename, jsonSourceKeys)
|
279
|
+
|
280
|
+
return new_data, isMissing
|
346
281
|
|
347
282
|
|
348
283
|
def process_json_object(jsonSourceData, filename, jsonSourceKeys):
|
@@ -381,7 +316,7 @@ def process_json_object_helper(output, obj, filename, current_path, metadataToId
|
|
381
316
|
children_keys = []
|
382
317
|
for k, v in obj.items():
|
383
318
|
path = current_path + [k]
|
384
|
-
paramInfoId, is_dict = create_json_code_info(
|
319
|
+
paramInfoId, is_dict = create_json_code_info(k, v, output)
|
385
320
|
metadataToId[createMetadataJsonString(filename, path)] = paramInfoId
|
386
321
|
children_keys.append(paramInfoId)
|
387
322
|
if is_dict:
|
@@ -399,14 +334,13 @@ def process_json_object_helper(output, obj, filename, current_path, metadataToId
|
|
399
334
|
return parent_id
|
400
335
|
|
401
336
|
|
402
|
-
def create_json_code_info(
|
337
|
+
def create_json_code_info(key, value, output):
|
403
338
|
paramInfoId = create_new_id()
|
404
339
|
# Create code info entry
|
405
340
|
output["codeInfo"][paramInfoId] = with_code_info_defaults(
|
406
341
|
id=paramInfoId,
|
407
342
|
name=key,
|
408
343
|
editable=True,
|
409
|
-
jsonSource=filename,
|
410
344
|
)
|
411
345
|
output["codeInfoColChildren"][paramInfoId] = []
|
412
346
|
|
setta/database/settings_file.py
CHANGED
@@ -77,9 +77,9 @@ class MetaSettingsFile:
|
|
77
77
|
return settings_slice_to_path
|
78
78
|
|
79
79
|
def find_path_for_settings_slice(self, p, slice):
|
80
|
-
for sectionId
|
81
|
-
|
82
|
-
|
80
|
+
for sectionId in p["sections"].keys():
|
81
|
+
variant = get_selected_section_variant(p, sectionId)
|
82
|
+
if variant["jsonSourceKeys"] == [slice]:
|
83
83
|
return variant["name"]
|
84
84
|
return None
|
85
85
|
|
setta/routers/sections.py
CHANGED
@@ -54,17 +54,16 @@ class GlobalParamSweepSectionToYamlRequest(BaseModel):
|
|
54
54
|
|
55
55
|
class LoadSectionJSONSourceRequest(BaseModel):
|
56
56
|
project: dict
|
57
|
-
|
57
|
+
variantIdsToLoad: List[str]
|
58
58
|
|
59
59
|
|
60
60
|
class SaveSectionJSONSourceRequest(BaseModel):
|
61
61
|
project: dict
|
62
|
-
|
63
|
-
forking_from: str
|
62
|
+
variantId: str
|
64
63
|
|
65
64
|
|
66
65
|
class NewJSONVersionNameRequest(BaseModel):
|
67
|
-
|
66
|
+
filename: str
|
68
67
|
|
69
68
|
|
70
69
|
class CreateFileRequest(BaseModel):
|
@@ -134,21 +133,18 @@ def route_global_param_sweep_section_to_yaml(x: GlobalParamSweepSectionToYamlReq
|
|
134
133
|
@router.post(C.ROUTE_LOAD_SECTION_JSON_SOURCE)
|
135
134
|
def route_load_section_json_source(x: LoadSectionJSONSourceRequest):
|
136
135
|
p = x.project
|
137
|
-
for k, v in x.sectionIdToJSONSource.items():
|
138
|
-
p["sections"][k]["jsonSource"] = v
|
139
136
|
load_json_sources_into_data_structures(
|
140
|
-
p["sections"],
|
141
137
|
p["codeInfo"],
|
142
138
|
p["codeInfoCols"],
|
143
139
|
p["sectionVariants"],
|
144
|
-
|
140
|
+
variant_ids=x.variantIdsToLoad,
|
145
141
|
)
|
146
142
|
return {"project": p}
|
147
143
|
|
148
144
|
|
149
145
|
@router.post(C.ROUTE_NEW_JSON_VERSION_NAME)
|
150
146
|
def route_new_json_version_name(x: NewJSONVersionNameRequest):
|
151
|
-
new_filename = generate_new_filename(x.
|
147
|
+
new_filename = generate_new_filename(x.filename)
|
152
148
|
Path(new_filename).parent.mkdir(parents=True, exist_ok=True)
|
153
149
|
Path(new_filename).touch()
|
154
150
|
return new_filename
|
@@ -162,7 +158,7 @@ def route_create_file(x: CreateFileRequest):
|
|
162
158
|
|
163
159
|
@router.post(C.ROUTE_SAVE_SECTION_JSON_SOURCE)
|
164
160
|
def route_save_section_json_source(x: SaveSectionJSONSourceRequest):
|
165
|
-
save_json_source_data(x.project, [x.
|
161
|
+
save_json_source_data(x.project, [x.variantId])
|
166
162
|
|
167
163
|
|
168
164
|
@router.post(C.ROUTE_GET_JSON_SOURCE_PATH_TO_BE_DELETED)
|