codeplain 0.3.13.dev47__py3-none-any.whl → 0.3.13.dev49__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: codeplain
3
- Version: 0.3.13.dev47
3
+ Version: 0.3.13.dev49
4
4
  Summary: Transform plain language specifications into working code
5
5
  License-File: LICENSE
6
6
  Classifier: Environment :: Console
@@ -10,7 +10,7 @@ Classifier: Topic :: Software Development :: Code Generators
10
10
  Requires-Python: ==3.11.*
11
11
  Requires-Dist: gitpython==3.2.1
12
12
  Requires-Dist: mistletoe==1.6.0
13
- Requires-Dist: networkx==3.6.1
13
+ Requires-Dist: plain-parser==0.1.4
14
14
  Requires-Dist: python-frontmatter==1.3.0
15
15
  Requires-Dist: python-liquid2==0.4.0
16
16
  Requires-Dist: pyyaml==6.0.3
@@ -1,10 +1,10 @@
1
1
  change_detection.py,sha256=CazORZrezeZSw2I6VBvieN-c2SEjieZPo6pNrKwmMVA,6915
2
2
  codeplain_REST_api.py,sha256=KJeFKBeVqbTr3RlINqiL5Q4roooJ1ISYlix1_KxqF9w,25262
3
- concept_utils.py,sha256=TpyiQ4DfMtO231j-lPj65i0suRTPr8t9j3QNf9KiM4A,8080
3
+ concept_utils.py,sha256=vzwC0_0HOZtPerDs7qPmjtyPleQNiuQ4CcmCKoIy7EM,141
4
4
  conformance_fix_journal.py,sha256=7wL3UOc3BWaUo5MCmiFbb3kIwOQ6iEpdQSyEmedo8Vk,9488
5
5
  diff_utils.py,sha256=AjiQlqo5pRos_8hVXZo5yBurl5BzSrTMGrQv4dCtRCg,1198
6
6
  event_bus.py,sha256=g5XLwRfjrvTIcB6urjREuCJzZj5TA93hy8lKXLGXuCE,650
7
- file_utils.py,sha256=uSgNzrQ3rXYnTEwdyFrsOvwvnEZ2bGfaBDOQpEDV0g8,12955
7
+ file_utils.py,sha256=d46BFIKM97nPTwkiYFoEfTmxAngEajkSKxJbX3orErY,8885
8
8
  git_preflight.py,sha256=vB2A8GyYz_iWr8jOE4POFLBHr3qihmedWuidspGdsrw,1509
9
9
  git_utils.py,sha256=gCUA6_9zg19f6k_0aVcRnIVlAJSBD0Vt6takx-0pKME,16547
10
10
  memory_management.py,sha256=CwIOQqF7Xo1sNfvP69zQRK_CpjinQD9dbolhRPl6lTk,2446
@@ -12,20 +12,20 @@ metadata_utils.py,sha256=YO17o7IAma5TT1ZN0pTwrLVr_KxFQ8APv02KqKPpI5k,1641
12
12
  module_renderer.py,sha256=OvIgAorSxGwrdTZcKy4hdmNgkdJGh6z6-VzzqrTlRHs,6966
13
13
  partial_rendering.py,sha256=uzZc2j4d3pAXzfiHw_y1TK4yLRsLOb1Mm21570AGxJ8,13837
14
14
  path_resolution.py,sha256=0tMqU0a1g4DYhTOp7QjLVSEkv_cgasb4NI1mK809dUM,2233
15
- plain2code.py,sha256=vQ5qjPZ1KXbl4s-QZtyrVrqnE_tu7GrzhjjDM_hI4bU,21305
15
+ plain2code.py,sha256=M4Z2qIHjk9fEYlxINyeKrpCbbv6NpZ5kmTDbGvDLXtc,22840
16
16
  plain2code_arguments.py,sha256=7TS2P351jmmyi-l8QKCHG732O3TtQ0kh4qbh14_4oLw,18634
17
17
  plain2code_console.py,sha256=YGBONkQtwZUkrjxTKhqcBoRzW0EmSfYHPH8P4_FM60I,6040
18
18
  plain2code_events.py,sha256=rgDF5PDtNr_lEPvJmd1tIQXZrzwgzZW5b-_pykugqe4,1587
19
- plain2code_exceptions.py,sha256=rtFEQbs1ruzSlGXIGJZoZry9sjYzmhPKHiUQIECcbL0,2567
19
+ plain2code_exceptions.py,sha256=zlszHIhaPWPN4fvYQibMIDM7f1xsW5J8sEWTOosIUGc,2068
20
20
  plain2code_logger.py,sha256=YQ-ENYBHKXROVv6Q52xh7eXrFkj_3Lex__N9zfxlw9Y,5729
21
- plain2code_nodes.py,sha256=IwjQqJxRSJKgP6eEnkYGy3VQHIyoazgkFxAEkxkjfJ8,4426
21
+ plain2code_nodes.py,sha256=QCC9RYBBfHycahvYovcN414sRlGL-dqRV3Baeu7KPkw,140
22
22
  plain2code_read_config.py,sha256=D5CxnmTRjddupecWvstcUm0kIJWWzq5-Zmk6sU0wbIg,2235
23
23
  plain2code_state.py,sha256=jIo4knKI99C1xkX1E_OaD3pdS9pczI2h9wofDjifMvE,3348
24
24
  plain2code_telemetry.py,sha256=e4UCAoFklJMDWGQsL50i7nTLiOBy8gs86A0XO4WLgPo,4597
25
- plain2code_utils.py,sha256=unOxuqSQRpwG8YF6uoQhnZ3ZSTJRIUCPLdJ-1lRZR5M,1534
26
- plain_file.py,sha256=yzdHYBZye1UjI6K-vcod5u9hPqQ_zBQS050yypdmB3M,37614
25
+ plain2code_utils.py,sha256=-MOISy5nwu9szDasckFYe6wOTkEeEAkLaq6deprRg78,1095
26
+ plain_file.py,sha256=50CevjRihjddXbc3WzKKJF_kaVcMHUJ1FH2HJUZawT8,138
27
27
  plain_modules.py,sha256=nXlmw0J2rKkuU1Y3A68LVtZ1Ffdc-D5iMjxaXSaSHTQ,25963
28
- plain_spec.py,sha256=7nb5lLJKHZ3uu9THkSXyJ5brIKkbGW0ooVfRclLdlzA,16062
28
+ plain_spec.py,sha256=AhDbw4GSQ95wC8fkFSPG66MsCu-37Kcz8Skcj66fQhA,1262
29
29
  system_config.py,sha256=sA8wiPmBMtRsLwSQ40U5pVdLazAafbV-1Z19Yp0HiSQ,5314
30
30
  usage_summary.py,sha256=MA4WcVaAwz6IWCN4k_rgxVcwO4I157wN7BZlFi3h0R4,1282
31
31
  cli_output/__init__.py,sha256=MBKl0YbVpWE-tBa3V5_aVbB7vbaqlIK2NsHTjRUZqis,284
@@ -79,14 +79,13 @@ tests/test_conformance_fix_journal.py,sha256=olTeAuxXgFwQ8LSQyt0FqtBy9_XY_gK-Ei_
79
79
  tests/test_console_log_styles.py,sha256=sxlhynMAP-kmqhBn1-pKvZXdCnlKSyCGJqwYKrh6sQ0,6468
80
80
  tests/test_distill_conformance_test_memory.py,sha256=Tftw9l-gLVwIU6QttY03h2VedvuFxpIsCmZIzvWfxMA,5481
81
81
  tests/test_dry_run_link_validation.py,sha256=ivvYXQPqUkQ8glbFyUrdCninCxF2mg-rAsDcfjcB7MM,2140
82
- tests/test_file_utils.py,sha256=a8OOuLdEyduaoOw7pFy5XtAtXIVUJkgdzRoFNHBezMg,7437
82
+ tests/test_file_utils.py,sha256=RPab1wBsbE7XAPGync56WveFVnRvafFVRia1a2mMQhk,4490
83
83
  tests/test_fix_unit_tests_action.py,sha256=0xY94BFbYa528LBXmO7_gfVNbQEqdzXsDHPjQV5qfy0,11410
84
84
  tests/test_fix_unit_tests_conformance_context.py,sha256=G6-_YMhN5BY1sJ7cAx3BDnf_McgFcRpyP0iP6mwJ1eA,13154
85
85
  tests/test_folder_path_resolution.py,sha256=K9v684xkPE0HOAsovg8uDixpZmaIk7ho-Wd3rTjKLF0,6560
86
86
  tests/test_git_preflight.py,sha256=6aQqInDzpk03pS-6UfkGQWjErrIXTEdHs5oeq3ZYzTw,3186
87
87
  tests/test_git_utils.py,sha256=h3rWhhs4XVRYqzVzdmj51siF_AYD-GkbZiefK2iGfWo,15614
88
88
  tests/test_headless_logging.py,sha256=soNESeotKQaU-SQyxtjpq35l-dLVsauZ_lJ-wk9i2mI,6419
89
- tests/test_imports.py,sha256=1ncbqQhtQW237kIjyV-Ufl7-R-PuduvoYFj2iS-DXW4,2608
90
89
  tests/test_log_file_name_resolution.py,sha256=99g9NgPF-BZ98CvNyqDcltBAx4sLBE8gpQPAAieKiPc,3619
91
90
  tests/test_logging_config_path_resolution.py,sha256=avz_ehRd18INwIXvAy1AwVzNNUz0vS8eu1nRe0bra8g,2650
92
91
  tests/test_partial_rendering.py,sha256=r0RUUd1pI4-2ZkRrM1j8_kUqv-70hrOGjuKBhZoRmH0,22758
@@ -95,13 +94,10 @@ tests/test_plain2code.py,sha256=lyb7iYK8XHu1dmTFh9Q31YgX0faNlCHiyI5M35VQwOg,3780
95
94
  tests/test_plain2code_state.py,sha256=O-sDt4F_lF6XtanWKWfh5IsNmDdfuJP_JoGagujzdfM,1440
96
95
  tests/test_plain2code_utils.py,sha256=-W8a7FquMJQ_pTdBoBF1XprzNL2G555QhdtXCy6BDyQ,1237
97
96
  tests/test_plain_modules.py,sha256=Fn3FeH-M4exnyFJDZzc9YWaLEfBmiqPH5TpiBT9jgAs,33033
98
- tests/test_plainfile.py,sha256=wZ_PN4GULPWIpl_AK_r_6jkgtX0Ch8EHmN5IhX7huOE,11027
99
- tests/test_plainfileparser.py,sha256=OY7dCilaUEeM4vAOShQYsZXKQzzUOi7nGYBaROu8Te8,26606
100
- tests/test_plainspec.py,sha256=ng55E8ajrH2-gPC1p_QDIe_zXplPvoqHJ-d57UWKFTw,3577
101
97
  tests/test_prepare_repositories_layout.py,sha256=PhJQLnHfjfjo6CTWoicyEKgL0_GtjwB2OKYAWSBVHtk,14638
102
98
  tests/test_render_finished_report.py,sha256=1OaL6S4LSRJ0JwDFu8HFEM02o4ZEn6oPtDpXPasNEVo,7670
99
+ tests/test_render_range.py,sha256=G6gsJfVQ12N487X2VxVmvSOhtWvfYXCKrP2CAKYzgzU,1496
103
100
  tests/test_render_stop_reason.py,sha256=13oRRGrZKNyJFD2iDxDrD7VFvmobbtfAFcnKKdiCJT8,8550
104
- tests/test_requires.py,sha256=6tnHYaKudxN-RiQjSFoi9nHe_x0ze3QF-f-j67zAE74,1250
105
101
  tests/test_resolve_config_file.py,sha256=b87tDOvyzbsnE-QRWbZ97ou7NuyaAgskv-dbYBum31c,2830
106
102
  tests/test_script_path_resolution.py,sha256=tiEqMevQRXr9YpfHN0xldOOQpLAUgnSqTzeZWkKHaUY,4156
107
103
  tests/test_system_config.py,sha256=gH5qs9q4lh5CljAdz28HUrJzuKqCvkZherFuv7enMak,2787
@@ -110,6 +106,7 @@ tests/test_terminal_attachment.py,sha256=mAJIKr0rXFytytZZm1XENV0T9kPYblhwkRTTtT4
110
106
  tests/test_tui_components.py,sha256=O_PB6z_Xt7YWebsD21b99PVgFtqq5c03lVtYytIT5Ps,6200
111
107
  tests/test_tui_usage.py,sha256=sfiAGTpRrT3MRr0-8DH3qjuECSxjODVgwzrK_K3iPXs,7959
112
108
  tests/test_usage_summary.py,sha256=Ps0kVzvmdZYeXrBR-cqkn3szTV5neYKs1PmmURngeIc,1079
109
+ tests/test_user_error_message.py,sha256=zQu9SK6oRUyW4p8NPwKnCdHWjx7Sh8iwI_QoFrPFynA,1332
113
110
  tests/e2e/conftest.py,sha256=5Dm67UTOE-M6hMb-mqZvwa6Ek_wmZgsR7fUv9ZEqCwY,4164
114
111
  tests/e2e/test_hello_world_python.py,sha256=2Cgs3-79dtQh5gVab257tFDHXTznefZeYqbTjlM4Nng,1632
115
112
  tests/e2e/test_hello_world_python_windows.py,sha256=ggynH_Wm4011M500zoPNNgvD-s4vZ3hvlorf1yARgQQ,2019
@@ -122,8 +119,8 @@ tui/spinner.py,sha256=Ro6Gd9Przf-whuHqPRY6HwI0T57yJjyNPbhDbigZKZE,2471
122
119
  tui/state_handlers.py,sha256=zbUS_D9eU8qIwVpaxPEp9zL9bpg8gXsWNoUaqg9TLrQ,16664
123
120
  tui/styles.css,sha256=kiC7Og_2G1E7owoiZgV95-3_dSeQnsNj3qzaY04xkDg,6727
124
121
  tui/widget_helpers.py,sha256=jitm2WHiKj-NVFL-hULxWzckPreRbUTl9OIZLN31-ek,6997
125
- codeplain-0.3.13.dev47.dist-info/METADATA,sha256=-Nkssjf-eNdmYgy2-dwpAgZiQHPJtRCijnTGWDiitSE,7257
126
- codeplain-0.3.13.dev47.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
127
- codeplain-0.3.13.dev47.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
128
- codeplain-0.3.13.dev47.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
129
- codeplain-0.3.13.dev47.dist-info/RECORD,,
122
+ codeplain-0.3.13.dev49.dist-info/METADATA,sha256=WiKH7j2pw7w-h32y2GZ_PtX0hJr27CplNT2ZuhYJh6Y,7261
123
+ codeplain-0.3.13.dev49.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
124
+ codeplain-0.3.13.dev49.dist-info/entry_points.txt,sha256=oDZkBqu9WhtZApb_K6ia8-fn9aojwmAsgnKELceX5T4,46
125
+ codeplain-0.3.13.dev49.dist-info/licenses/LICENSE,sha256=pCeKgQ1mXE5OmNUuKOfOZh1T1vqkeCUxghE7N8qgnzc,11345
126
+ codeplain-0.3.13.dev49.dist-info/RECORD,,
concept_utils.py CHANGED
@@ -1,221 +1,3 @@
1
- import re
2
- from copy import deepcopy
3
- from typing import Optional
1
+ """Compatibility shim: the parser now lives in the ``plain-parser`` package."""
4
2
 
5
- import mistletoe.block_token
6
- import networkx as nx
7
-
8
- import plain_spec
9
- from plain2code_exceptions import PlainSyntaxError
10
-
11
- # These are reserved concept names that are pre-defined and must not be redefined in the definitions section.
12
- DEFAULT_CONCEPTS = {
13
- ":ConformanceTests:",
14
- ":UnitTests:",
15
- ":AcceptanceTest:",
16
- ":AcceptanceTests:",
17
- ":Implementation:",
18
- ":plainDefinitions:",
19
- ":plainImplementationReqs:",
20
- ":plainFunctionality:",
21
- ":plainTestReqs:",
22
- ":plainImplementationCode:",
23
- }
24
-
25
-
26
- def extract_concepts_from_definition(text: str) -> tuple[list[str], list[str]]:
27
- pattern = r"-\s(:[^\:]+:)(?:,\s*:[^\:]+:)*"
28
- match = re.search(pattern, text)
29
-
30
- if not match:
31
- return list(), [
32
- f"Syntax error: Invalid definition specification text: {text}. Should start with `- :<concept>:` (where <concept> is any string that does not contain `:`)."
33
- ]
34
-
35
- concept_candidates = re.findall(r":[^\:]+:", match.group())
36
- valid_concepts = list[str]()
37
- concept_re = r":[+\-\.0-9A-Z_a-z]+:"
38
- errors = list[str]()
39
- for candidate in concept_candidates:
40
- if re.match(concept_re, candidate):
41
- valid_concepts.append(candidate)
42
- else:
43
- errors.append(
44
- f"Syntax error: Invalid concept: {candidate}. Should contain only letters, numbers, hyphens and dots."
45
- )
46
-
47
- return valid_concepts, errors
48
-
49
-
50
- def extract_concepts_from_spec_text(text: str) -> str:
51
- return re.findall(r":[+\-\.0-9A-Z_a-z]+:", text)
52
-
53
-
54
- def collect_concepts(plain_source) -> tuple[set[str], list[str]]:
55
- if plain_spec.DEFINITIONS not in plain_source:
56
- return set(), list()
57
-
58
- concepts = list[str]()
59
- errors = list[str]()
60
- for definition in plain_source[plain_spec.DEFINITIONS]:
61
- spec_text = definition["markdown"]
62
- new_concepts, new_errors = extract_concepts_from_definition(spec_text)
63
- errors.extend(new_errors)
64
- concepts.extend(new_concepts)
65
-
66
- return concepts, errors
67
-
68
-
69
- def validate_concepts_in_spec(spec: dict, concepts: set[str], spec_group: str) -> list[str]:
70
- spec_text = spec["markdown"]
71
- used_concepts = extract_concepts_from_spec_text(spec_text)
72
- errors = []
73
- for used_concept in used_concepts:
74
- if used_concept not in concepts and used_concept not in DEFAULT_CONCEPTS:
75
- errors.append(
76
- f"Syntax error: Concept {used_concept} is not defined in the definitions. {spec_group}: {spec_text}"
77
- )
78
-
79
- return errors
80
-
81
-
82
- def validate_concepts_in_spec_group(spec_group, plain_source, concepts: set[str]) -> list[str]:
83
- if spec_group not in plain_source:
84
- return []
85
-
86
- errors = []
87
- for spec in plain_source[spec_group]:
88
- errors.extend(validate_concepts_in_spec(spec, concepts, spec_group))
89
-
90
- return errors
91
-
92
-
93
- def validate_concepts(marshalled_plain_source) -> list[str]:
94
- errors = list[str]()
95
- concepts = deepcopy(DEFAULT_CONCEPTS)
96
- tree_based_concepts = deepcopy(DEFAULT_CONCEPTS)
97
-
98
- new_concepts, new_errors = collect_concepts(marshalled_plain_source)
99
- errors.extend(new_errors)
100
-
101
- unique_new_concepts = set(new_concepts)
102
- intersection = unique_new_concepts.intersection(concepts)
103
-
104
- if len(unique_new_concepts) < len(new_concepts) or (len(intersection) > 0):
105
- misused_concepts = {concept for concept in new_concepts if new_concepts.count(concept) > 1}
106
- misused_concepts.update(intersection)
107
- errors.append(f"Syntax error: Concepts were defined multiple times: {', '.join(misused_concepts)} .")
108
-
109
- concepts.update(unique_new_concepts)
110
- tmp_tree_based_concepts = tree_based_concepts.union(unique_new_concepts)
111
-
112
- for spec_group in [
113
- plain_spec.NON_FUNCTIONAL_REQUIREMENTS,
114
- plain_spec.TEST_REQUIREMENTS,
115
- plain_spec.FUNCTIONAL_REQUIREMENTS,
116
- plain_spec.DEFINITIONS,
117
- ]:
118
- errors.extend(validate_concepts_in_spec_group(spec_group, marshalled_plain_source, tmp_tree_based_concepts))
119
-
120
- if plain_spec.FUNCTIONAL_REQUIREMENTS in marshalled_plain_source:
121
- for func_spec in marshalled_plain_source[plain_spec.FUNCTIONAL_REQUIREMENTS]:
122
- if "acceptance_tests" not in func_spec:
123
- continue
124
-
125
- acceptance_tests = func_spec["acceptance_tests"]
126
- for spec in acceptance_tests:
127
- errors.extend(validate_concepts_in_spec(spec, tmp_tree_based_concepts, plain_spec.ACCEPTANCE_TESTS))
128
-
129
- return errors
130
-
131
-
132
- def find_concept_definitions_in_plain_source(
133
- concept: str,
134
- plain_source: dict,
135
- renderer,
136
- ) -> list[mistletoe.block_token.token]:
137
- definitions = list[mistletoe.block_token.token]()
138
- if plain_source[plain_spec.DEFINITIONS] is None:
139
- return definitions
140
-
141
- for definition in plain_source[plain_spec.DEFINITIONS].children:
142
- rendered_definition = renderer.render(definition)
143
- defined_concepts, _ = extract_concepts_from_definition(rendered_definition)
144
- if concept in defined_concepts:
145
- definitions.append(definition)
146
- used_concepts = [
147
- used_concept
148
- for used_concept in extract_concepts_from_spec_text(rendered_definition)
149
- if used_concept != concept and used_concept not in DEFAULT_CONCEPTS
150
- ]
151
- for used_concept in used_concepts:
152
- definitions.extend(find_concept_definitions_in_plain_source(used_concept, plain_source, renderer))
153
-
154
- return definitions
155
-
156
-
157
- def build_adjacency_list(definitions: Optional[list[dict]]) -> tuple[dict, dict]:
158
- adjacency_list = dict[str, list[str]]()
159
- concept_definitions = dict[str, dict]()
160
- if definitions is None or len(definitions) == 0:
161
- return adjacency_list, concept_definitions
162
-
163
- for definition in definitions:
164
- def_text = definition["markdown"]
165
- new_concepts, _ = extract_concepts_from_definition(def_text)
166
- used_concepts = [
167
- used_concept
168
- for used_concept in extract_concepts_from_spec_text(def_text)
169
- if used_concept not in new_concepts and used_concept not in DEFAULT_CONCEPTS
170
- ]
171
- used_concepts = set(used_concepts)
172
-
173
- for new_concept in new_concepts:
174
- if new_concept not in adjacency_list:
175
- adjacency_list[new_concept] = []
176
-
177
- for used_concept in used_concepts:
178
- if used_concept not in adjacency_list:
179
- adjacency_list[used_concept] = []
180
-
181
- adjacency_list[used_concept].extend(new_concepts)
182
-
183
- for new_concept in new_concepts:
184
- concept_definitions[new_concept] = definition
185
-
186
- return adjacency_list, concept_definitions
187
-
188
-
189
- def sort_definitions(definitions: list[dict]) -> list[dict]:
190
- if len(definitions) <= 1:
191
- return
192
-
193
- adjacency_list, concept_definitions = build_adjacency_list(definitions)
194
-
195
- concept_graph = nx.DiGraph()
196
- for node, neighbors in adjacency_list.items():
197
- for neighbour in neighbors:
198
- concept_graph.add_edge(node, neighbour)
199
- if not neighbors:
200
- concept_graph.add_node(node)
201
-
202
- if not nx.is_directed_acyclic_graph(concept_graph):
203
- msg = "Found cycles in the concept graph. Cycles are not allowed."
204
- all_cycles = list(nx.simple_cycles(concept_graph))
205
-
206
- for cycle in all_cycles:
207
- cyclic_definitions = []
208
- cyclic_definitions.append(concept_definitions[cycle[0]]["markdown"])
209
- cyclic_definitions.append(concept_definitions[cycle[1]]["markdown"])
210
- msg += "Cyclic definitons:\n"
211
- msg += "\n".join(cyclic_definitions)
212
- msg += "\n"
213
-
214
- raise PlainSyntaxError(f"Plain syntax error: {msg}")
215
-
216
- order = list(nx.topological_sort(concept_graph))
217
- if len(order) > 0:
218
- definition_to_order_idx = {
219
- plain_spec.hash_text(str(concept_definitions[concept])): idx for idx, concept in enumerate(order)
220
- }
221
- definitions.sort(key=lambda definition: definition_to_order_idx[plain_spec.hash_text(str(definition))])
3
+ from plain_parser.concept_utils import * # noqa: F401,F403
file_utils.py CHANGED
@@ -3,14 +3,14 @@ import shutil
3
3
  import stat
4
4
  from pathlib import Path
5
5
 
6
- from liquid2 import Environment, FileSystemLoader, StrictUndefined
7
- from liquid2.exceptions import UndefinedError
6
+ from plain_parser.loaders import ( # noqa: F401
7
+ TrackingFileSystemLoader,
8
+ get_loaded_templates,
9
+ load_linked_resources,
10
+ open_from,
11
+ )
8
12
 
9
- import plain_spec
10
13
  from plain2code_console import console
11
- from plain2code_exceptions import UnsupportedBase64Content, UnsupportedResourceType
12
- from plain2code_nodes import Plain2CodeIncludeTag, Plain2CodeLoaderMixin
13
- from plain2code_utils import find_large_base64_blob
14
14
  from plain_modules import CODEPLAIN_MEMORY_SUBFOLDER, CODEPLAIN_METADATA_FOLDER
15
15
 
16
16
  BINARY_FILE_EXTENSIONS = [".pyc"]
@@ -183,106 +183,6 @@ def store_response_files(target_folder, response_files, existing_files):
183
183
  return existing_files
184
184
 
185
185
 
186
- def open_from(dirs, file_name):
187
- for dir in dirs:
188
- full_file_name = os.path.join(dir, file_name)
189
- if not os.path.isfile(full_file_name):
190
- continue
191
-
192
- with open(full_file_name, "rb") as f:
193
- content = f.read()
194
- return content.decode("utf-8")
195
-
196
- return None
197
-
198
-
199
- def resolve_linked_resource(dirs, file_name):
200
- """Return the first existing path for file_name across dirs, or None if not found.
201
-
202
- Mirrors the search order used by open_from so that validating a linked resource and
203
- loading it can never disagree.
204
- """
205
- for dir in dirs:
206
- full_file_name = os.path.join(dir, file_name)
207
- if os.path.exists(full_file_name):
208
- return full_file_name
209
-
210
- return None
211
-
212
-
213
- def load_linked_resources(template_dirs: list[str], resources_list, module_name: str):
214
- linked_resources = {}
215
-
216
- for resource in resources_list:
217
- file_name = resource["target"]
218
- if file_name in linked_resources:
219
- continue
220
-
221
- try:
222
- content = open_from(template_dirs, file_name)
223
- except UnicodeDecodeError:
224
- raise UnsupportedResourceType(
225
- f"Referenced resource '{file_name}' in module '{module_name}' is a binary file. "
226
- f"Only text files (e.g. .md, .txt, .json, .yaml) can be referenced from a .plain file."
227
- )
228
-
229
- if content is None:
230
- raise FileNotFoundError(f"""
231
- Resource file {file_name} not found. Resource files are searched in the following order (highest to lowest precedence):
232
-
233
- 1. The directory containing your .plain file
234
- 2. The directory specified by --template-dir (if provided)
235
- 3. The built-in 'standard_template_library' directory
236
-
237
- Please ensure that the resource exists in one of these locations, or specify the correct --template-dir if using custom templates.
238
- """)
239
-
240
- blob = find_large_base64_blob(content)
241
- if blob is not None:
242
- raise UnsupportedBase64Content(
243
- f"Referenced resource '{file_name}' in module '{module_name}' contains a large "
244
- f"base64-encoded blob ({len(blob)} characters), such as an embedded image. Inline "
245
- "base64 data is not supported. Remove the data from the resource. "
246
- "If the data should be used by the end software, "
247
- "save the data to a separate file and include the file path in the specification without it being a reference file."
248
- )
249
-
250
- linked_resources[file_name] = content
251
-
252
- return linked_resources
253
-
254
-
255
- class TrackingFileSystemLoader(Plain2CodeLoaderMixin, FileSystemLoader):
256
- def __init__(self, *args, **kwargs):
257
- super().__init__(*args, **kwargs)
258
- self.loaded_templates = {}
259
-
260
- def get_source(self, environment, template_name, **kwargs):
261
- source = super().get_source(environment, template_name, **kwargs)
262
- self.loaded_templates[template_name] = source.source
263
- return source
264
-
265
-
266
- def get_loaded_templates(source_path, plain_source):
267
- # Render the plain source with Liquid templating engine
268
- # to identify the templates that are being loaded
269
-
270
- liquid_loader = TrackingFileSystemLoader(source_path)
271
- liquid_env = Environment(loader=liquid_loader, undefined=StrictUndefined)
272
- liquid_env.tags["include"] = Plain2CodeIncludeTag(liquid_env)
273
-
274
- liquid_env.filters["code_variable"] = plain_spec.code_variable_liquid_filter
275
- liquid_env.filters["prohibited_chars"] = plain_spec.prohibited_chars_liquid_filter
276
-
277
- plain_source_template = liquid_env.from_string(plain_source)
278
- try:
279
- plain_source = plain_source_template.render()
280
- except UndefinedError as e:
281
- raise Exception(f"Undefined liquid variable: {str(e)}")
282
-
283
- return plain_source, liquid_loader.loaded_templates
284
-
285
-
286
186
  def update_build_folder_with_rendered_files(build_folder, existing_files, response_files):
287
187
  changed_files = set()
288
188
  changed_files.update(response_files.keys())
plain2code.py CHANGED
@@ -59,6 +59,39 @@ from tui.plain2code_tui import Plain2CodeTUI
59
59
  from tui.plain_module_render_choice_tui import PlainModuleRenderChoiceTUI
60
60
 
61
61
  DEFAULT_TEMPLATE_DIRS = "standard_template_library"
62
+
63
+ # Search-order guidance appended to lookup failures raised by the parser, which only
64
+ # reports the missing file. The wording is the CLI's: it knows what the template
65
+ # directories are and how the user changes them.
66
+ TEMPLATE_NOT_FOUND_HINT = f"""
67
+ The required template could not be found. Templates are searched in the following order (highest to lowest precedence):
68
+
69
+ 1. The directory containing your .plain file
70
+ 2. The directory specified by --template-dir (if provided)
71
+ 3. The built-in '{DEFAULT_TEMPLATE_DIRS}' directory
72
+
73
+ Please ensure that the missing template exists in one of these locations, or specify the correct --template-dir if using custom templates.
74
+ """
75
+
76
+ RESOURCE_NOT_FOUND_HINT = f""" Resource files are searched in the following order (highest to lowest precedence):
77
+
78
+ 1. The directory containing your .plain file
79
+ 2. The directory specified by --template-dir (if provided)
80
+ 3. The built-in '{DEFAULT_TEMPLATE_DIRS}' directory
81
+
82
+ Please ensure that the resource exists in one of these locations, or specify the correct --template-dir if using custom templates."""
83
+
84
+
85
+ def user_error_message(e: BaseException) -> str:
86
+ """Format an exception for the user, appending search-order guidance to lookup failures."""
87
+ message = str(e) if str(e) else repr(e)
88
+ if isinstance(e, TemplateNotFoundError):
89
+ return message + TEMPLATE_NOT_FOUND_HINT
90
+ if isinstance(e, FileNotFoundError):
91
+ return message + RESOURCE_NOT_FOUND_HINT
92
+ return message
93
+
94
+
62
95
  RENDER_THREAD_SHUTDOWN_TIMEOUT = 0.7
63
96
 
64
97
  # The terminal states a render can reach, as the API names them.
@@ -371,7 +404,7 @@ def render( # noqa: C901
371
404
  except Exception as e:
372
405
  run_state.set_render_succeeded(False)
373
406
  render_error.append(e)
374
- event_bus.publish(RenderFailed(error_message=str(e)))
407
+ event_bus.publish(RenderFailed(error_message=user_error_message(e)))
375
408
 
376
409
  if args.headless:
377
410
  console.info(f"Render started. Render ID: {run_state.render_id}")
@@ -446,7 +479,7 @@ def main(): # noqa: C901
446
479
  console.info("Full plain text:\n")
447
480
  console.info(full_plain_source)
448
481
  except Exception as e:
449
- console.error(f"Error: {str(e)}")
482
+ console.error(f"Error: {user_error_message(e)}")
450
483
  return
451
484
 
452
485
  # Parse the plain file (and its required modules) once; reused by dry-run and rendering.
@@ -457,14 +490,14 @@ def main(): # noqa: C901
457
490
  template_dirs,
458
491
  )
459
492
  except Exception as e:
460
- console.error(f"Error: {str(e)}")
493
+ console.error(f"Error: {user_error_message(e)}")
461
494
  return
462
495
 
463
496
  if args.dry_run:
464
497
  try:
465
498
  validate_linked_resources(plain_module)
466
499
  except Exception as e:
467
- console.error(f"Error: {str(e)}")
500
+ console.error(f"Error: {user_error_message(e)}")
468
501
  return
469
502
 
470
503
  console.info("Printing dry run output...\n")
@@ -517,7 +550,7 @@ def main(): # noqa: C901
517
550
  error_message = "Keyboard interrupt"
518
551
  interrupted = True
519
552
  else:
520
- error_message = str(e) if str(e) else repr(e)
553
+ error_message = user_error_message(e)
521
554
 
522
555
  if not isinstance(e, EXPECTED_EXCEPTIONS):
523
556
  exc_info = sys.exc_info()
plain2code_exceptions.py CHANGED
@@ -1,3 +1,15 @@
1
+ from plain_parser.exceptions import ( # noqa: F401
2
+ ImportedModuleWithFunctionalitiesError,
3
+ InvalidFridArgument,
4
+ InvalidLiquidVariableName,
5
+ MissingFunctionalitiesError,
6
+ ModuleDoesNotExistError,
7
+ PlainSyntaxError,
8
+ UnsupportedBase64Content,
9
+ UnsupportedResourceType,
10
+ )
11
+
12
+
1
13
  class FunctionalRequirementTooComplex(Exception):
2
14
  def __init__(self, message, proposed_breakdown=None):
3
15
  self.message = message
@@ -21,19 +33,6 @@ class MissingResource(Exception):
21
33
  pass
22
34
 
23
35
 
24
- class UnsupportedResourceType(Exception):
25
- pass
26
-
27
-
28
- class PlainSyntaxError(Exception):
29
- pass
30
-
31
-
32
- class UnsupportedBase64Content(Exception):
33
-
34
- pass
35
-
36
-
37
36
  class InternalClientError(Exception):
38
37
  pass
39
38
 
@@ -50,24 +49,12 @@ class OutdatedClientVersion(Exception):
50
49
  pass
51
50
 
52
51
 
53
- class InvalidFridArgument(Exception):
54
- pass
55
-
56
-
57
52
  class InvalidGitRepositoryError(Exception):
58
53
  """Raised when the git repository is in an invalid state."""
59
54
 
60
55
  pass
61
56
 
62
57
 
63
- class InvalidLiquidVariableName(Exception):
64
- pass
65
-
66
-
67
- class ModuleDoesNotExistError(Exception):
68
- pass
69
-
70
-
71
58
  class InternalServerError(Exception):
72
59
  pass
73
60
 
@@ -78,23 +65,6 @@ class MissingPreviousFunctionalitiesError(Exception):
78
65
  pass
79
66
 
80
67
 
81
- class MissingFunctionalitiesError(Exception):
82
- """Raised when a module to be rendered has no functionalities specified at all."""
83
-
84
- pass
85
-
86
-
87
- class ImportedModuleWithFunctionalitiesError(Exception):
88
- """Raised when a module brought in via ``import`` contains functional specs.
89
-
90
- This is a usage error, not a syntax error: the module is syntactically valid
91
- and would be fine as a render target, but functionalities are not allowed in
92
- the import role.
93
- """
94
-
95
- pass
96
-
97
-
98
68
  class NetworkConnectionError(Exception):
99
69
  """Raised when there is a network connectivity issue with the API server."""
100
70