-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from grycap/antonio-dev
Added dynamic path to im_client.py
- Loading branch information
Showing
4 changed files
with
65 additions
and
33 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { KernelManager } from '@jupyterlab/services'; | ||
|
||
export async function executeKernelCommand( | ||
command: string, | ||
callback: (output: string) => void | ||
): Promise<void> { | ||
try { | ||
const kernelManager = new KernelManager(); | ||
const kernel = await kernelManager.startNew(); | ||
const future = kernel.requestExecute({ code: command }); | ||
|
||
future.onIOPub = msg => { | ||
const content = msg.content as any; | ||
const outputText = | ||
content.text || (content.data && content.data['text/plain']); | ||
callback(outputText); | ||
}; | ||
} catch (error) { | ||
console.error('Error executing kernel command:', error); | ||
} | ||
} | ||
|
||
export async function getIMClientPath(): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const cmdIMClientPath = '%%bash\n' + 'which im_client.py'; | ||
|
||
executeKernelCommand(cmdIMClientPath, output => { | ||
if (output.trim()) { | ||
resolve(output.trim()); | ||
} else { | ||
reject( | ||
new Error( | ||
'Failed to find im_client.py path. Maybe IM-client is not installed.' | ||
) | ||
); | ||
} | ||
}).catch(reject); | ||
}); | ||
} |