Skip to content

Commit 0e92247

Browse files
authored
Merge pull request #307 from pathsim/fix/code-preview-engine-imports
Engine-parametric imports in code preview header
2 parents 6ad7ae1 + b8f083e commit 0e92247

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/lib/utils/codePreviewHeader.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { nodeRegistry, type NodeInstance } from '$lib/nodes';
77
import { eventRegistry, type EventInstance } from '$lib/events';
88
import { NODE_TYPES } from '$lib/constants/nodeTypes';
99
import { blockImportPaths } from '$lib/nodes/generated/blocks';
10+
import { ENGINE_MODULE, enginePath } from '$lib/constants/engine';
1011

1112
/**
1213
* Extract Python identifiers from a string (parameter values)
@@ -131,7 +132,7 @@ export function generateBlockCodeHeader(node: NodeInstance, codeContext: string)
131132
// Imports
132133
lines.push('import numpy as np');
133134
if (node.type === NODE_TYPES.SUBSYSTEM) {
134-
lines.push('from pathsim import Subsystem, Interface, Connection');
135+
lines.push(`from ${ENGINE_MODULE} import Subsystem, Interface, Connection`);
135136
const blockClasses = new Set<string>();
136137
collectSubsystemBlockClasses(node, blockClasses);
137138
if (blockClasses.size > 0) {
@@ -142,7 +143,7 @@ export function generateBlockCodeHeader(node: NodeInstance, codeContext: string)
142143
for (const cls of [...blockClasses].sort()) {
143144
const def = nodeRegistry.get(cls);
144145
const importPath =
145-
def?.importPath ?? blockImportPaths[cls] ?? 'pathsim.blocks';
146+
enginePath(def?.importPath ?? blockImportPaths[cls] ?? 'pathsim.blocks');
146147
const group = importGroups.get(importPath) || [];
147148
group.push(cls);
148149
importGroups.set(importPath, group);
@@ -153,7 +154,7 @@ export function generateBlockCodeHeader(node: NodeInstance, codeContext: string)
153154
}
154155
} else {
155156
const importPath =
156-
typeDef.importPath ?? blockImportPaths[typeDef.blockClass] ?? 'pathsim.blocks';
157+
enginePath(typeDef.importPath ?? blockImportPaths[typeDef.blockClass] ?? 'pathsim.blocks');
157158
lines.push(`from ${importPath} import ${typeDef.blockClass}`);
158159
}
159160

@@ -184,7 +185,7 @@ export function generateEventCodeHeader(event: EventInstance, codeContext: strin
184185

185186
// Imports
186187
lines.push('import numpy as np');
187-
lines.push(`from pathsim.events import ${typeDef.eventClass}`);
188+
lines.push(`from ${ENGINE_MODULE}.events import ${typeDef.eventClass}`);
188189

189190
// Extract referenced code context
190191
const paramValues = Object.values(event.params).filter(v => v != null && v !== '').join(' ');

0 commit comments

Comments
 (0)