如何在开发/调试期间自动更新Jupyter Notebook扩展? [英] How to auto-update jupyter notebook extension during development/debugging?
问题描述
我尝试为Jupyter Notebook写一个自定义扩展,如下所述: https://towardsdatascience.com/how-to-write- a-jupyter-notebook-extension-a63f9578a38c
I try to write a custom extension for the Jupyter Notebook, as described here: https://towardsdatascience.com/how-to-write-a-jupyter-notebook-extension-a63f9578a38c
我使用Windows7上的Chrome开发人员工具来检查和编辑自定义扩展程序的Javascript源代码.我希望当按F5键更新页面时,我更改后的源代码将立即应用.
I use the Chrome developer tools on Windows7 to inspect and edit the Javascript source code of my custom extension. I hoped that when pressing F5 to update the page, my altered source code would be immediately applied.
但是,如上所述,我必须运行
However, as stated in the above mentioned article, I have to run
jupyter-contrib-nbextensions.exe install
并重新启动服务器以刷新笔记本扩展名,并查看我的代码更改的影响.
and restart the server to refresh the notebook extension and to see the effects of my code changes.
每次玩转和开发/调试扩展时,这样做都是很烦人的.
Doing so after every little change is quite annoying when playing around and developing/debugging extensions.
=>是否有某种开发选项可以自动更新/重新加载扩展?
=>Is there some sort of development option for automatically updating/reloading the extension?
推荐答案
作为解决方法,我编写了一个扩展名"Workspace module":
As a work around I wrote an extension "Workspace module":
https://github.com/stefaneidelloth/treezjs/tree/master /jupyter_notebook_extension/workspace_module
该扩展名的目的是如果笔记本文件夹中存在文件"workspace.js",则可以导入该文件.我的扩展程序的 main.js 是:
The purpose of that extension is to import a file "workspace.js" if it exists in the notebook folder. The main.js of my extension is:
define([
'require',
'jquery',
'base/js/namespace',
'base/js/events',
'notebook/js/codecell'
], function(
requirejs,
$,
Jupyter,
events,
codecell
) {
var load_ipython_extension = function() {
if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) {
init();
} else {
console.log("[workspace_module] Waiting for notebook availability")
events.on("notebook_loaded.Notebook", function() {
init();
})
}
};
function init(){
console.log("[workspace_module] trying to load workspace.js")
var moduleScript = document.createElement('script');
moduleScript.setAttribute('type','module');
moduleScript.setAttribute('src','workspace.js');
document.body.appendChild(moduleScript);
}
return {
load_ipython_extension: load_ipython_extension
};
});
workspace.js 重定向到我的实际扩展名:
The workspace.js redirects to my actual extension:
import './treezjs/src/treezJupyterNotebook.js';
这样,我可以在开发过程中修改代码,而无需重新执行install命令.
This way, I am able to adapted my code during development without a need to re-execute the install command.
这篇关于如何在开发/调试期间自动更新Jupyter Notebook扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!