Skip to content

Commit a0c14c9

Browse files
authored
Removed initializeHeadlessBlockly from create_python_files. (#202)
Call extendedPythonGenerator.init before each call to extendedPythonGenerator.mrcWorkspaceToCode. Don't rely on isInitialized.
1 parent 73acc9e commit a0c14c9

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

src/storage/create_python_files.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ async function generatePythonForModule(module: Module, storage: Storage): Promis
7373
const generatorContext = new GeneratorContext();
7474
generatorContext.setModule(module);
7575

76-
// Initialize the generator if not already done
77-
if (!extendedPythonGenerator.isInitialized) {
78-
extendedPythonGenerator.init(workspace);
79-
}
76+
// Initialize the generator
77+
extendedPythonGenerator.init(workspace);
8078

8179
// Generate Python code using the same method as the editor
8280
const pythonCode = extendedPythonGenerator.mrcWorkspaceToCode(workspace, generatorContext);
@@ -170,12 +168,8 @@ async function generatePythonFilesMap(project: Project, storage: Storage): Promi
170168
* @returns Promise that resolves to a blob URL for downloading the zip file
171169
*/
172170
export async function producePythonProjectBlob(project: Project, storage: Storage): Promise<string> {
173-
// Initialize the generator first
174-
initializeHeadlessBlockly();
175-
176171
const pythonFilesMap = await generatePythonFilesMap(project, storage);
177172

178-
179173
if (pythonFilesMap.size === 0) {
180174
throw new Error('No Python files were generated successfully');
181175
}
@@ -189,13 +183,3 @@ export async function producePythonProjectBlob(project: Project, storage: Storag
189183
const blobUrl = URL.createObjectURL(content);
190184
return blobUrl;
191185
}
192-
193-
/**
194-
* Initialize Blockly for headless operation
195-
* This should be called once before using the generation functions
196-
*/
197-
function initializeHeadlessBlockly(): void {
198-
// Initialize Blockly for headless operation
199-
// This ensures all necessary generators and blocks are loaded
200-
extendedPythonGenerator.init(new Blockly.Workspace());
201-
}

0 commit comments

Comments
 (0)