Skip to content

Commit

Permalink
Merge pull request #372 from XpressAI/fahreza/run-on-terminal
Browse files Browse the repository at this point in the history
✨ Add Run Xircuits Workflow on Terminal Option
  • Loading branch information
MFA-X-AI authored Feb 3, 2025
2 parents f178c27 + b75e976 commit 99d83ec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/commands/CommandIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const commandIDs = {
nextNode: "Xircuit-editor:next-node",
outputMsg: "Xircuit-log:logOutputMessage",
executeToOutputPanel: "Xircuit-output-panel:execute",
executeToTerminal: "Xircuit-terminal:execute",
createNewComponentLibrary: "Xircuit-editor:new-component-library",
refreshComponentList: "xircuits-sidebar:refresh-component-list",
toggleDisplayNodesInLibrary: "xircuits-sidebar:toggle-display-nodes-in-library",
Expand Down
27 changes: 19 additions & 8 deletions src/components/XircuitsBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,30 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
if (runType == 'run') {
result = await handleLocalRunDialog();
if (result.status === 'ok') {
code += "%run " + model_path + result.args;
code += "%run " + model_path + result.args;
commands.execute(commandIDs.executeToOutputPanel, { code });
}
else if (result.status === 'cancelled') {
console.log("Run operation cancelled by user.");
}
} else if (runType == 'remote-run') {
}

else if (runType == 'remote-run') {
result = await handleRemoteRunDialog();
if (result.status === 'ok') {
code += buildRemoteRunCommand(model_path, result.args);
code += buildRemoteRunCommand(model_path, result.args);
commands.execute(commandIDs.executeToOutputPanel, { code });
}
}

if (result.status === 'ok') {
commands.execute(commandIDs.executeToOutputPanel, { code });
} else if (result.status === 'cancelled') {
console.log("Run operation cancelled by user.");

else if (runType === 'terminal-run') {
commands.execute(commandIDs.executeToTerminal, {
python_path: model_path
});
}

else {
console.log("Unknown runType or user cancelled.");
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/runner/RunSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class RunSwitcher extends ReactWidget {
<option value="run" >Local Run</option>
<option value="run-dont-compile">Local Run w/o Compile</option>
<option value="remote-run">Remote Run</option>
<option value="terminal-run">Terminal Run</option>
</HTMLSelect>
);
}
Expand All @@ -54,8 +55,9 @@ export class RunSwitcher extends ReactWidget {
title={'Select the run type'}
>
<option value="run" >Local Run</option>
<option value="run-dont-compile">Run w/o Compile</option>
<option value="run-dont-compile">Local Run w/o Compile</option>
<option value="remote-run">Remote Run</option>
<option value="terminal-run">Terminal Run</option>
</HTMLSelect>
);
}}
Expand Down
17 changes: 16 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ const xircuits: JupyterFrontEndPlugin<void> = {
},
});

app.commands.addCommand(commandIDs.executeToTerminal, {
label: 'Run in Terminal',
execute: async args => {

const python_path = (args['python_path'] as string);
const terminalWidget = await app.commands.execute('terminal:create-new');
app.shell.add(terminalWidget, 'main', { mode: 'split-bottom' });
const terminalSession = terminalWidget.content.session;

terminalSession.send({ type: 'stdin', content: [`cd $JUPYTER_SERVER_ROOT\n`] });
terminalSession.send({ type: 'stdin', content: [`export PYTHONPATH=$JUPYTER_SERVER_ROOT:$PYTHONPATH\n`] });
terminalSession.send({ type: 'stdin', content: ['python ' + python_path + '\n'] });
}
});

// Add a command for compiling a xircuits file from the file browser context menu.
app.commands.addCommand(commandIDs.compileWorkflowFromFileBrowser, {
label: 'Compile Xircuits',
Expand Down Expand Up @@ -523,4 +538,4 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
logPlugin
];

export default plugins;
export default plugins;

0 comments on commit 99d83ec

Please sign in to comment.