22import os
33import threading
44
5- import git_utils
6- import plain_file
7- import plain_spec
85from event_bus import EventBus
96from memory_management import MemoryManager
10- from partial_rendering import PartialRenderChoice
7+ from partial_rendering import RenderChoice
118from plain2code_console import console
129from plain2code_events import RenderCompleted , RenderFailed
13- from plain2code_exceptions import MissingPreviousFunctionalitiesError
1410from plain2code_state import RunState
1511from plain_modules import PlainModule
1612from render_machine .code_renderer import CodeRenderer
@@ -24,7 +20,7 @@ def __init__(
2420 self ,
2521 codeplainAPI ,
2622 plain_module : PlainModule ,
27- partial_render_choice : PartialRenderChoice | None ,
23+ render_choice : RenderChoice | None ,
2824 render_range : list [str ] | None ,
2925 args : argparse .Namespace ,
3026 run_state : RunState ,
@@ -34,126 +30,14 @@ def __init__(
3430 ):
3531 self .codeplainAPI = codeplainAPI
3632 self .plain_module = plain_module
37- self .partial_render_choice = partial_render_choice
33+ self .render_choice = render_choice
3834 self .render_range = render_range
3935 self .args = args
4036 self .run_state = run_state
4137 self .event_bus = event_bus
4238 self .stop_event = stop_event
4339 self .enter_pause_event = enter_pause_event
4440
45- def _ensure_module_folders_exist (self , module_name : str , first_render_frid : str ) -> tuple [str , str ]:
46- """
47- Ensure that build and conformance test folders exist for the module.
48-
49- Args:
50- module_name: Name of the module being rendered
51- first_render_frid: The first FRID in the render range
52-
53- Returns:
54- tuple[str, str]: (build_folder_path, conformance_tests_path)
55-
56- Raises:
57- MissingPreviousFridCommitsError: If any required folders are missing
58- """
59- build_folder_path = os .path .join (self .args .build_folder , module_name )
60- conformance_tests_path = os .path .join (self .args .conformance_tests_folder , module_name )
61-
62- if not os .path .exists (build_folder_path ):
63- raise MissingPreviousFunctionalitiesError (
64- "Error rendering plain code: "
65- f"Cannot start rendering from functionality { first_render_frid } for module '{ module_name } ' because the source code folder does not exist.\n \n "
66- f"To fix this, please render the module from the beginning by running:\n "
67- f" codeplain { module_name } { plain_file .PLAIN_SOURCE_FILE_EXTENSION } \n "
68- )
69-
70- if not os .path .exists (conformance_tests_path ) and self .args .render_conformance_tests :
71- raise MissingPreviousFunctionalitiesError (
72- "Error rendering plain code: "
73- f"Cannot start rendering from functionality { first_render_frid } for module '{ module_name } ' because the conformance tests folder does not exist.\n \n "
74- f"To fix this, please render the module from the beginning by running:\n "
75- f" codeplain { module_name } { plain_file .PLAIN_SOURCE_FILE_EXTENSION } \n "
76- )
77-
78- return build_folder_path , conformance_tests_path
79-
80- def _ensure_frid_commit_exists (
81- self ,
82- frid : str ,
83- module_name : str ,
84- build_folder_path : str ,
85- conformance_tests_path : str ,
86- first_render_frid : str ,
87- ) -> None :
88- """
89- Ensure commit exists for a single FRID in both repositories.
90-
91- Args:
92- frid: The FRID to check
93- module_name: Name of the module
94- build_folder_path: Path to the build folder
95- conformance_tests_path: Path to the conformance tests folder
96- first_render_frid: The first FRID in the render range (for error messages)
97-
98- Raises:
99- MissingPreviousFridCommitsError: If the commit is missing
100- """
101- # Check in build folder
102- if not git_utils .has_commit_for_frid (build_folder_path , frid , module_name ):
103- raise MissingPreviousFunctionalitiesError (
104- "Error rendering plain code: "
105- f"Cannot start rendering from functionality { first_render_frid } for module '{ module_name } ' because the implementation of the previous functionality ({ frid } ) hasn't been completed yet.\n \n "
106- f"To fix this, please render the missing functionality ({ frid } ) first by running:\n "
107- f" codeplain { module_name } { plain_file .PLAIN_SOURCE_FILE_EXTENSION } --render-from { frid } \n "
108- )
109-
110- # Check in conformance tests folder (only if conformance tests are enabled)
111- if self .args .render_conformance_tests :
112- if not git_utils .has_commit_for_frid (conformance_tests_path , frid , module_name ):
113- raise MissingPreviousFunctionalitiesError (
114- "Error rendering plain code: "
115- f"Cannot start rendering from functionality { first_render_frid } for module '{ module_name } ' because the conformance tests for the previous functionality ({ frid } ) haven't been completed yet.\n \n "
116- f"To fix this, please render the missing functionality ({ frid } ) first by running:\n "
117- f" codeplain { module_name } { plain_file .PLAIN_SOURCE_FILE_EXTENSION } --render-from { frid } \n "
118- )
119-
120- def _ensure_previous_frid_commits_exist (
121- self , module_name : str , plain_source : dict , render_range : list [str ]
122- ) -> None :
123- """
124- Ensure that all FRID commits before the render_range exist.
125-
126- This is a precondition check that must pass before rendering can proceed.
127- Raises an exception if any previous FRID commits are missing.
128-
129- Args:
130- module_name: Name of the module being rendered
131- plain_source: The plain source tree
132- render_range: List of FRIDs to render
133-
134- Raises:
135- MissingPreviousFridCommitsError: If any previous FRID commits are missing
136- """
137- first_render_frid = render_range [0 ]
138-
139- # Get all FRIDs that should have been rendered before this one
140- previous_frids = plain_spec .get_frids_before (plain_source , first_render_frid )
141- if not previous_frids :
142- return
143-
144- # Ensure the module folders exist
145- build_folder_path , conformance_tests_path = self ._ensure_module_folders_exist (module_name , first_render_frid )
146-
147- # Verify commits exist for all previous FRIDs
148- for prev_frid in previous_frids :
149- self ._ensure_frid_commit_exists (
150- prev_frid ,
151- module_name ,
152- build_folder_path ,
153- conformance_tests_path ,
154- first_render_frid ,
155- )
156-
15741 def _build_render_context_for_module (
15842 self ,
15943 plain_module : PlainModule ,
@@ -192,20 +76,20 @@ def _render_module(
19276 Returns:
19377 tuple[bool, bool]: (Whether the module was rendered and whether the rendering failed)
19478 """
195- is_partial_render_choice_module = (
196- self .partial_render_choice is not None
197- and self .partial_render_choice .module is not None
198- and self .partial_render_choice .module .module_name == plain_module .module_name
79+ is_render_choice_module = (
80+ self .render_choice is not None
81+ and self .render_choice .module is not None
82+ and self .render_choice .module .module_name == plain_module .module_name
19983 )
20084
201- if is_partial_render_choice_module :
202- render_range = self .partial_render_choice .render_range
85+ if is_render_choice_module :
86+ render_range = self .render_choice .render_range
20387
20488 if render_range is not None :
20589 plain_module .ensure_previous_frid_commits_exist (render_range , self .args .render_conformance_tests )
20690
20791 has_any_required_module_changed = False
208- if not self .args .render_machine_graph and plain_module .required_modules and not is_partial_render_choice_module :
92+ if not self .args .render_machine_graph and plain_module .required_modules and not is_render_choice_module :
20993 console .debug (f"Analyzing required modules of module { plain_module .module_name } ..." )
21094 for required_module in plain_module .required_modules :
21195 has_module_changed , rendering_failed = self ._render_module (
@@ -226,7 +110,7 @@ def _render_module(
226110 and not has_any_required_module_changed
227111 and not plain_module .has_plain_spec_changed ()
228112 and not plain_module .has_required_modules_code_changed ()
229- and not is_partial_render_choice_module
113+ and not is_render_choice_module
230114 ):
231115 return False , False
232116
@@ -264,11 +148,11 @@ def _render_module(
264148 return True , False
265149
266150 def render_module (self ) -> None :
267- if self .partial_render_choice is not None and self .partial_render_choice .wipe_later_modules :
151+ if self .render_choice is not None and self .render_choice .wipe_later_modules :
268152 later_module = False
269153 all_modules = self .plain_module .all_required_modules + [self .plain_module ]
270154 for module in all_modules :
271- if module .module_name == self .partial_render_choice .module .module_name :
155+ if module .module_name == self .render_choice .module .module_name :
272156 later_module = True
273157 continue
274158
0 commit comments