Skip to content

Commit 84d6db0

Browse files
authored
Merge pull request #268 from pathsim/fix/toolbox-import-paths
Fix code export import paths for toolbox blocks
2 parents 220b84d + 27ec26d commit 84d6db0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/lib/utils/codePreviewHeader.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { nodeRegistry, type NodeInstance } from '$lib/nodes';
77
import { eventRegistry, type EventInstance } from '$lib/events';
88
import { NODE_TYPES } from '$lib/constants/nodeTypes';
9+
import { blockImportPaths } from '$lib/nodes/generated/blocks';
910

1011
/**
1112
* Extract Python identifiers from a string (parameter values)
@@ -134,10 +135,21 @@ export function generateBlockCodeHeader(node: NodeInstance, codeContext: string)
134135
const blockClasses = new Set<string>();
135136
collectSubsystemBlockClasses(node, blockClasses);
136137
if (blockClasses.size > 0) {
137-
lines.push(`from pathsim.blocks import ${[...blockClasses].sort().join(', ')}`);
138+
// Group block classes by import path
139+
const importGroups = new Map<string, string[]>();
140+
for (const cls of [...blockClasses].sort()) {
141+
const importPath = blockImportPaths[cls] || 'pathsim.blocks';
142+
const group = importGroups.get(importPath) || [];
143+
group.push(cls);
144+
importGroups.set(importPath, group);
145+
}
146+
for (const [importPath, classes] of importGroups) {
147+
lines.push(`from ${importPath} import ${classes.join(', ')}`);
148+
}
138149
}
139150
} else {
140-
lines.push(`from pathsim.blocks import ${typeDef.blockClass}`);
151+
const importPath = blockImportPaths[typeDef.blockClass] || 'pathsim.blocks';
152+
lines.push(`from ${importPath} import ${typeDef.blockClass}`);
141153
}
142154

143155
// Extract referenced code context

0 commit comments

Comments
 (0)