扩展迁移指南#
JupyterLab 4.3 到 4.4#
图标#
@jupyterlab/debugger 的图标被移动到 @jupyterlab/ui-components。
正在使用的图标位于 ui-components/style/icons/debugger 文件夹中,而 未使用的图标在 @jupyterlab/debugger 包中位于 ui-components/style/unused/ 文件夹中。
之前 |
之后 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JupyterLab 4.2 到 4.3#
CSS样式#
以前JupyterLab会全局泄漏CSS规则。从4.3版本开始,这种情况不再发生。对扩展的副作用是:
附加在应用程序外壳之外的DOM元素可能会有样式损坏。要修复这个问题,你应该将类
jp-ThemedContainer添加到应用程序外壳之外添加的DOM元素中。DOM元素
code,kbd,pre,samp和tt的样式可能会出现问题。要修复这个问题,可以在你的规则前加上类.jp-ThemedContainer;例如,.jp-Inspector-content pre变为.jp-ThemedContainer .jp-Inspector-content pre
jp-Inspector-default-content 类已重命名为 jp-Inspector-placeholderContent。这个上下文帮助类的名称现在与等效的目录和属性检查器类保持一致。
JupyterLab 4.3 更新了其对 @lumino/widget 的依赖到 2.5.0 版本,该版本移除了以下小部件的全局样式:
.lm-Widget {
overflow: hidden;
}
如果您注意到扩展的样式存在一些不一致,您可能需要将此通用规则添加回扩展的CSS中,或者(更可取的是)将其限定为相关的小部件。
使用Galata进行测试#
Playwright 已更新至版本 1.46.1(或更高)。版本 1.46.0 的变更日志提到,在定义对象数组的 fixture 值时可能存在破坏性更改。
查看Playwright 1.46.0 发布说明以获取更多信息。
JupyterLab 4.1 到 4.2#
API更新#
CodeEditor.ICoordinate接口已修正,不再包含toJSON()、x、y、width和height;这些属性从未被返回ICoordinate的方法设置, 也从未被接受它的方法使用。CodeEditor.getCoordinateForPosition的返回类型已更正,以明确它可以返回null;之前尽管返回类型表明它总是返回一个非空的ICoordinate值,但实际上可能会返回null。命令
workspace-ui:save和workspace-ui:save-as已从@jupyterlab/apputils-extension:workspaces插件移至一个新的专用@jupyterlab/workspaces-extension包中,并且可以通过请求IWorkspaceCommands令牌来显式要求。此令牌默认由新的@jupyterlab/workspaces-extension:commands插件提供。@jupyterlab/apputils-extension:workspaces插件现在仅定义了用于打开带有.jupyterlab-workspace扩展名的文件作为 JupyterLab 工作区的 MIME 类型渲染器。单元格工具栏节点已从单元格节点移动到单元格输入节点。 因此,单元格工具栏的父节点已更改,不能再直接用于检索相应的单元格节点。
快捷方式扩展重做#
@jupyterlab/shortcuts-extension 包被重新设计以修复多个错误并增加类型安全性。
虽然这个包没有暴露任何编程API,并且主题更改很少,
但包的版本号被提升到5.0以反映更改的范围。
扩展作者不需要采取任何行动(除非您使用了/lib中的非公开组件), 但是,鼓励基于JupyterLab组件构建的应用程序的作者升级到这个新版本,因为它可以显著改善用户体验。
JupyterLab 4.0 到 4.1#
插件管理器和扩展锁定#
在JupyterLab 4.1之前,没有以下机制: - 供用户禁用/启用单个插件(而不是整个扩展) - 供管理员完全阻止用户启用/禁用某些扩展
这个版本的JupyterLab通过添加插件管理器来实现这两者。
如果您的安装中有任何插件被禁用,这些插件将在首次启动时自动锁定,以确保用户暴露的功能没有变化。插件管理器本身可以使用jupyter labextension命令禁用和锁定,但我们建议根据需要锁定单个插件。
如果您的扩展程序之前包含自定义的启用/禁用设置,您可能可以将其替换为指向用户使用插件管理器的说明。但是,请考虑您的扩展程序是否可能在不包含插件管理器或已禁用的发行版中使用。
在StaticNotebook的超类WindowedList中更改CSS类名#
类
.jp-WindowedPanel-window已更名为.jp-WindowedPanel-viewport。笔记本滚动容器现在是
.jp-WindowedPanel-outer而不是.jp-NotebookGalata 笔记本助手 getCell 和 getCellCount 已相应更新
笔记本焦点处理的变化影响命令模式快捷键选择器#
以前,在切换到命令模式时,笔记本中的焦点会返回到笔记本的HTML节点,这阻止了在单元格之间使用Tab键进行导航,特别是影响了有辅助功能需求的用户。在JupyterLab 4.1+中,切换到命令模式时焦点保持在活动单元格上;这要求所有快捷键选择器按如下方式调整:
.jp-Notebook:focus.jp-mod-commandMode,.jp-Notebook:focus, 和[data-jp-traversable]:focus应该被替换为: -.jp-Notebook.jp-mod-commandMode :focus:not(:read-write)适用于 JupyterLab 4.1.0+ -.jp-Notebook.jp-mod-commandMode:not(.jp-mod-readWrite) :focus适用于 JupyterLab 4.1.1+[data-jp-kernel-user]:focus应替换为: -[data-jp-kernel-user] :focus:not(:read-write)适用于 JupyterLab 4.1.0+ -[data-jp-kernel-user]:not(.jp-mod-readWrite) :focus:not(:read-write)适用于 JupyterLab 4.1.1+
请注意,:not(:read-write)片段在文本字段(如单元格编辑器)获得焦点时禁用快捷方式,以避免拦截用户输入到文本字段中的字符,但如果您的快捷方式不对应任何键/印刷字符(例如大多数带有Ctrl修饰符的快捷方式),如果您希望快捷方式在文本字段中保持活动状态,您可能更愿意删除此片段。
此外,JupyterLab 4.1.1 引入了指示器类 .jp-mod-readWrite,当活动元素接受键盘输入时,该类会应用于笔记本节点,如 :read-write 选择器所定义。此指示器类用于检测嵌套在开放影子 DOM 中的 :read-write 元素(例如 Panel 框架小部件)。
如果你的框架使用了封闭的影子DOM,或者期望在浏览器启发式:read-write选择器不识别为可编辑的元素上进行键盘交互,你需要在外部宿主元素上设置一个数据属性lm-suppress-shortcuts来抑制快捷键。
为了防止破坏用户体验,这些更改在后台透明地进行,但会发出警告,扩展开发者应在下一个主要JupyterLab版本发布之前在源代码中进行更改。
在高倍放大下StatusBar元素的可见性#
状态栏项目现在在高放大率/低分辨率下默认隐藏,以防止在高放大率下使用应用程序时发生重叠。
在
IStatusBar.registerStatusItem方法的选项中添加了一个额外的priority属性,以允许状态栏项目保持可见; 预期用途是用于那些在高缩放时特别有用或否则无法访问的小状态栏项目。
JupyterLab 3.x 到 4.x#
由于从JupyterLab 3.x到4.x的重大类型变化,我们建议发布一个新的主要版本的扩展以与每个主要版本的JupyterLab兼容。有关使用不同主要版本的Lab 3和Lab 4的扩展示例,请参见jupyterlab-vim和jupyter-ai。
使用升级脚本升级扩展#
JupyterLab 4.x 提供了一个脚本来升级现有扩展,以使用新的扩展系统和打包方式。
注意
备份您的扩展 - 最好使用像git这样的版本控制,并在新分支上工作。
首先,确保更新到 JupyterLab 4 并安装 copier 和一些依赖项。使用 pip:
pip install -U jupyterlab[upgrade-extension]
或者使用 conda:
conda install -c conda-forge jupyterlab=4 "copier=9" jinja2-time
然后在扩展的根文件夹中运行:
python -m jupyterlab.upgrade_extension .
升级脚本为将JupyterLab扩展打包为Python包创建必要的文件。
脚本会询问你是否要覆盖所有文件。默认情况下,配置文件将被新版本覆盖。特别是,如果你使用的是Python setuptools(即setup.py
和/或setup.cfg),你可能需要更新pyproject.toml文件(参见
PEP示例)。
升级脚本还将package.json中的依赖项更新为^4.0.0包。
有关扩展的新文件结构和打包的更多详细信息,请查看扩展教程:扩展教程
注意
如果您的扩展受到以下提到的API更改的影响,您将需要修改扩展的代码。
jlpm#
实用工具 jlpm 使用 Yarn 3(之前是 Yarn 1)。这将需要更新您的包配置。
创建一个文件
.yarnrc.yml包含以下内容:
enableImmutableInstalls: false
nodeLinker: node-modules
添加到
.gitignore
.yarn/
运行
jlpm install这将重置您的yarn.lock内容,因为其格式已更改。
注意
你可以在Yarn文档中找到更多关于从Yarn版本1升级到版本3的信息。
如果你遇到了同一个包的多个版本(如@lumino/widgets),TypeScript可能会抱怨类型不匹配。一个可能的解决方案是强制使用包去重:
jlpm dlx yarn-berry-deduplicate
API重大变更#
注意
随着JupyterLab 4.x的发布,npm包的版本策略发生了变化,不再与Python包的主要版本同步更新,除非为了简化扩展兼容性而需要这样做。
以下是遇到API更改并因此增加了主要版本(遵循semver约定)的JupyterLab npm包列表。我们特别想指出的是@jupyterlab/documentsearch和@jupyterlab/toc API,它们已经完全重新设计。
@jupyterlab/application从 3.x 到 4.x主要版本升级,以允许在
JupyterFrontEnd中使用替代的ServiceManager实现。 具体来说,这允许使用模拟管理器。 这也使得JupyterLab.IOptions更加宽松,当提供选项时不需要 shell,并允许符合ILabShell接口的 shell。 因此,所有其他@jupyterlab/包的主要版本也进行了升级。 更多详情请参见 jupyterlab/jupyterlab#11537。将令牌
@jupyterlab/apputils:IConnectionLost重命名为@jupyterlab/application:IConnectionLost。
@jupyterlab/apputils从 3.x 到 4.x将
IToolbarWidgetRegistry.registerFactory重命名为IToolbarWidgetRegistry.addFactoryISanitizer和ISanitizer.IOptions已被弃用,推荐使用@jupyterlab/rendermime-interfaces中的IRenderMime.ISanitizer和IRenderMime.ISanitizerOptions。全局的
sessionContextDialogs已被移除;你应该请求ISessionContextDialogs的 token(来自@jupyterlab/apputils)。
@jupyterlab/attachments从 3.x 到 4.x从
IAttachmentsModel.IOptions中移除了modelDB。
@jupyterlab/buildutils从 3.x 到 4.xcreate-theme脚本已被移除。如果你想创建一个新的主题扩展,你应该使用 TypeScript 扩展模板 (选择theme作为kind)来代替。add-sibling脚本已被移除。请查看 源扩展的开发工作流程 来代替。exitOnUuncaughtException工具函数已更名为exitOnUncaughtException(拼写错误修复)。
@jupyterlab/cellsfrom 3.x to 4.xMarkdownCell.toggleCollapsedSignalrenamedMarkdownCell.headingCollapsedChangedTo support notebook windowing, cell widget children (e.g. the editor or the output area) are not instantiated when the cell is attached to the notebook. You can test forisPlaceholder()to see if the cell has been fully instantiated or wait for the promisereadyto be resolved. Additionally an attributeinViewportand a signalinViewportChangedare available to test if the cell is attached to the DOM. If you instantiate standalone cells outside of a notebook, you will probably need to set the constructor optionplaceholdertofalseto ensure direct rendering of the cell.InputArea.defaultContentFactoryandCell.defaultContentFactoryhave been removed. If you need it, you can request the tokenIEditorServicesfrom@jupyterlab/codeeditor. Then you can usenew Cell.ContentFactory({ editorFactory: token.factoryService.newInlineEditor });.
@jupyterlab/celltags从 3.x 到 4.0@jupyterlab/celltags包已被移除,并由@jupyterlab/celltags-extension中的一个小部件替代。 这个小部件现在使用@jupyterlab/metadataform进行渲染。@jupyterlab/codeeditorfrom 3.x to 4.0CodeEditor.IEditorhas changed:resizeToFit()is removedaddKeydownHandler()is removed - you should add a CodeMirror extensionEditorView.domEventHandlerswithPrec.high(to ensure it is not captured by keyboard shortcuts).
injectExtension()added as experimental to inject a CodeMirror extension - you should prefer registeringnew extensions with
IEditorExtensionRegistry.
CodeEditor.IOptionshas two new optional attributes:extensions?: Extensions[]to provide custom extensions at editor instantiationinline?: booleanwhether the editor is a subpart of a document (like the notebook) or not.
CodeEditorWrapper.IOptionshas changed to{ factory, model, editorOptions }.CodeViewerWidget.IOptionshas changed to{ factory, model, editorOptions }.
@jupyterlab/codemirrorfrom 3.x to 4.0- Configuration parameters changes:
fontFamily,fontSizeandlineHeight: grouped in a subdictionnarycustomStyles.insertSpaces: changed forindentUnitthat can take a value within [‘Tab’, ‘1’, ‘2’, ‘4’, ‘8’]lineWrap: changed - it is now a boolean.showTrailingSpace: renamedhighlightTrailingWhitespacecoverGutterNextToScrollbar: removedelectricChars: removedextraKeys: removed - you should register new keymap using the CodeMirror extensionkeymap.of(KeyBinding[])handlePaste: removedkeymap: removedlineSeparator: removed - Line separator are normalized to\nlineWiseCopyCut: removed - this is the default behaviorscrollbarStyle: removedstyleSelectedText: removedselectionPointer: removedwordWrapColumn: removed
Modehas been removed. You can instead request the tokenIEditorLanguageHandler. That provides similar API: -Mode.registerModeInfo->IEditorLanguageHandler.addLanguage-Mode.ensure()->IEditorLanguageHandler.getLanguage()-Mode.modeList->IEditorLanguageHandler.getLanguages()-Mode.run()->IEditorLanguageHandler.highlight()-Mode.findBest()->IEditorLanguageHandler.findBest()-Mode.findByName()->IEditorLanguageHandler.findByName()-Mode.findByMIME()->IEditorLanguageHandler.findByMIME()-Mode.findByExtension()->IEditorLanguageHandler.findByExtension()EditorSyntaxStatusmoved to@jupyterlab/fileeditor
@jupyterlab/codemirror-extensionfrom 3.x to 4.0Moved commands: -
codemirror:change-theme->fileeditor:change-theme(moved to@juptyerlab/fileeditor-extension) -codemirror:change-mode->fileeditor:change-language(moved to@juptyerlab/fileeditor-extension) -codemirror:find->fileeditor:find(moved to@juptyerlab/fileeditor-extension) -codemirror:go-to-line->fileeditor:go-to-line(moved to@juptyerlab/fileeditor-extension)Removed command:
codemirror:change-keymapMoved plugins: -
@jupyterlab/codemirror-extension:commandsintegrated within@jupyterlab/fileeditor-extension:plugin-@jupyterlab/codemirror-extension:editor-syntax-status->@jupyterlab/fileeditor-extension:editor-syntax-status-@jupyterlab/codemirror-extension:editor-syntax-status->@jupyterlab/fileeditor-extension:editor-syntax-status
@jupyterlab/completerfrom 3.x to 4.xMajor version was bumped following major refactor aimed at performance improvements and enabling easier third-party integration.
- Adding custom completion suggestions (items):
In 3.x and earlier adding custom completion items required re-registering the completer connector for each file/cell using
registermethod of old manager provided byICompletionManagertoken; in 4.x this token and associatedICompletableAttributesinterface was removed and a proper method of registering a custom source of completions (a provider of completions) was added. To create a completer provider for JupyterLab, users need to implement theICompletionProviderinterface and then register this provider withICompletionProviderManagertoken.In 3.x merging completions from different sources had to be performed by creating a connector internally merging results from other connectors. in 4.x
IProviderReconciliatoris used to merge completions from multiple providers, and can be customised in constructor for custom completion handlers (CompletionHandler); customizing reconciliator in JupyterLab-managed completers is not yet possible.
- Rendering with
Completer.IRenderer: In 3.x it was not possible to easily swap the renderer of JupyterLab-managed completers. In 4.x the renderer from the completion provider with highest rank is now used for all JupyterLab-managed completers. This behaviour is subject to revision in the future (please leave feedback).
Completer box is now using delayed rendering for off-screen content to improve time to first paint for top suggestions. To position the completer without rendering all items we search for the widest item using heuristic which can be adjusted in custom renderers (
itemWidthHeuristic).The documentation panel now implements a loading indicator (a progress bar) customizable via optional
createLoadingDocsIndicatorrenderer method.createItemNodewas removed in favour ofcreateCompletionItemNodewhich is now required.createCompletionItemNodeis no longer responsible for sanitization of labels which is now a responsibility of the model (see below).
- Rendering with
- Model:
In 3.x it was not possible to easily swap the model of JupyterLab-managed completers. In 4.x the model factory from the completion provider with highest rank is now used for JupyterLab-managed completers. This behaviour is subject to revision in the future (please leave feedback).
Old methods for updating and accessing the completion items:
setOptions,options, anditemswere removed in favour ofcompletionItemsandsetCompletionItemswhich are now required members ofCompleter.IModel.New signal
queryChangedwas added and has to be emitted by models.Model is now responsible for sanitization of labels and preserving original label on
insertTextattribute (if not already defined); this change was required to properly handle escaping of HTML tags.
@jupyterlab/codeeditor从 3.x 到 4.x移除
ISelectionStyle(以及defaultSelectionStyle和IEditor.selectionStyle)。这是为实时协作设计的。但在最终实现中并未使用。
@jupyterlab/console从 3.x 到 4.xIConsoleHistory.sessionContext的类型已更新为ISessionContext | null,而不是ISessionContext。 这可能会破坏从ConsoleHistory访问sessionContext的插件的编译,特别是那些启用了严格空值检查的插件。
@jupyterlab/coreutils从 3.x 到 4.xTime命名空间不再使用moment库来管理日期。相反,它现在使用现代网络浏览器中可用的IntlAPI。Time.format函数仍然可用,但不再接受timeFormat参数。
@jupyterlab/debugger从 3.x 到 4.x命令
debugger:pause的命令 ID 已重命名为debugger:pause-on-exceptions,以避免与暂停当前运行线程的命令产生歧义。
@jupyterlab/docmanager从 3.x 到 4.xrenameDialog现在接收DocumentRegistry.Context而不是路径。接口
DocumentManager.IWidgetOpener现在改为IDocumentWidgetOpener,并且由一个新的插件@jupyterlab/docmanager-extension:opener提供。IDocumentWidgetOpener接口现在还定义了一个`opened`信号,当一个小部件被打开时发出。从接口
DocumentManager.IOptions中移除了属性docProviderFactory。
@jupyterlab/docregister从 3.x 到 4.xTextModelFactory.preferredLanguage(path: string)将始终返回''。编辑器语言无法全局提供。 如果需要,您可以通过从@jupyterlab/codemirror请求令牌IEditorLanguageHandler来恢复此功能。然后您可以使用token.findByFileName(widget.context.path)?.name ?? ''。
@jupyterlab/docprovider从 3.x 到 4.x此包在 JupyterLab 中不再存在。有关实时协作的文档,请查看 RTC 的文档
@jupyterlab/docregistry从 3.x 到 4.x从接口
Context.IOptions中移除了属性docProviderFactory。类
DocumentModel的构造函数接收一个参数DocumentModel.IOptions。方法
IModelFactory.createNew接收一个参数DocumentRegistry.IModelOptions。方法
TextModelFactory.createNew接收一个参数DocumentModel.IOptions。
@jupyterlab/documentsearch从 3.x 到 4.x@jupyterlab/documentsearch:plugin已重命名为@jupyterlab/documentsearch-extension:plugin@jupyterlab/documentsearch:labShellWidgetListener已重命名为@jupyterlab/documentsearch-extension:labShellWidgetListener
这可能会影响应用程序配置(例如,如果插件被禁用)。 搜索提供者 API 已经完全重新设计。但逻辑是相似的,对于新类型的文档, 您需要向
ISearchProviderRegistry注册一个ISearchProviderFactory。 该工厂将为文档小部件构建一个ISearchProvider。
@jupyterlab/extensionmanager从 3.x 到 4.x前端 API 已大幅减少,以从后端获取所有信息。现在建议您根据需求实现自定义的
ExtensionManager类,而不是覆盖前端插件。 请参阅jupyterlab/extensions/pypi.py以获取使用 PyPI.org 和 pip 的示例。然后,您可以通过在 Python 包中定义一个入口点来注册您的管理器;请参阅pyproject.toml::project.entry-points."jupyterlab.extension_manager_v1"。
@jupyterlab/fileeditor从 3.x 到 4.x移除类
FileEditorCodeWrapper,相反,你可以使用来自@jupyterlab/codeeditor的CodeEditorWrapper。
@jupyterlab/filebrowser从 3.x 到 4.x从接口
IFileBrowserFactory中移除属性defaultBrowser。默认浏览器现在由其自己的插件通过要求令牌IDefaultFileBrowser提供。从
FileBrowser类中移除useFuzzyFilter设置器。
@jupyterlab/filebrowser-extension从 3.x 到 4.x移除命令
filebrowser:create-main-launcher。你可以用launcher:create替换(行为相同) 所有的启动器创建操作都已移至@jupyterlab/launcher-extension。
@jupyterlab/imageviewer-extension从 3.x 到 4.x从公共 API 中移除了
addCommands
@jupyterlab/mainmenu从 3.x 到 4.xIMainMenu.addMenu的签名从addMenu(menu: Menu, options?: IMainMenu.IAddOptions): void更改为addMenu(menu: Menu, update?: boolean, options?: IMainMenu.IAddOptions): void从公共 API 中移除了
createEditMenu,createFileMenu,createKernelMenu,createViewMenu,createRunMenu,createTabsMenu,createHelpMenu。
@jupyterlab/notebookfrom 3.x to 4.xNotebookWidgetFactory.IOptionshas nosessionDialogsoption any more.The
NotebookPanel._onSavemethod is nowprivate.NotebookActions.collapseAllmethod renamed toNotebookActions.collapseAllHeadings.Command
Collapsible_Headings:Toggle_Collapserenamed tonotebook:toggle-heading-collapse.Command
Collapsible_Headings:Collapse_Allrenamed tonotebook:collapse-all-headings.Command
Collapsible_Headings:Expand_Allrenamed tonotebook:expand-all-headings.To support windowing, a new method
scrollToItem(index, behavior)is available to scroll to any cell that may or may not be in the DOM. And newcellInViewportChangedsignal is available to listen for cells entering or leaving the viewport (in windowing mode). AndscrollToCell(cell)is now returning aPromise<void>calling internallyscrollToItem.fullyRendered,placeholderCellRenderedandremainingCellToRenderCounthave been removed. The defer rendering mode still exists. It will render some cells during spare CPU Idle time.Settings
numberCellsToRenderDirectly,remainingTimeBeforeRescheduling,renderCellOnIdle,observedTopMarginandobservedBottomMarginhave been removed. Instead awindowingModewith value of defer, full or none andoverscanCounthave been added to manage the rendering mode.Added the property
sharedModelto the interfaceNotebookModel.IOptions.The method
NotebookModelFactory.createNewreceives a parameterNotebookModelFactory.IModelOptions.The default Notebook toolbar’s
restart-and-runbutton now refers to the commandnotebook:restart-run-allinstead ofrunmenu:restart-and-run-all.StaticNotebook.defaultContentFactoryhas been removed. If you need it, you can request the tokenIEditorServicesfrom@jupyterlab/codeeditor. You can obtain it by requestednew NotebookPanel.ContentFactory({ editorFactory: token.factoryService.newInlineEditor });notebooktoolsmodule does not provides anymore theActiveCellTool, theNotebookMetadataEditorTooland theCellMetadataEditorTool. All these widget are replaced by widgets in@jupyterlab/notebook-extension, and are rendered using@jupyterlab/metadataform. TheKeySelectorhas also been removed as not used anymore, replaced by the use of@jupyterlab/metadataformto provides selection for metadata keys.
@jupyterlab/rendermime从 3.x 到 4.xMarkdown 解析器已被提取到其自己的插件
@jupyterlab/markedparser-extension:plugin中, 该插件提供了一个新的令牌IMarkdownParser(在@jupyterlab/rendermime中定义)。 因此,IRendererFactory.createRenderer有一个新的选项markdownParser。[非破坏性]
IRenderMime.IExtension有一个新的可选属性description: string用于文档。
@jupyterlab/rendermime-interfaces从 3.x 到 4.x 移除IRenderMime.IRenderer.translator?属性;如果需要,翻译器对象仍然会传递给渲染器工厂的构造函数。@jupyterlab/services从 6.x 到 7.x移除
Contents.IDrive.modelDBFactory和Contents.IManager.getModelDBFactory。添加了
Contents.IDrive.sharedModelFactory和Contents.IManager.getsharedModelFactory。
@jupyterlab/shared-models从 3.x 到 4.x此包在 JupyterLab 中不再存在。有关共享模型的文档, 请查看 @jupyter/ydoc 文档。
@jupyterlab/statusbarfrom 3.x to 4.xSetting
@jupyterlab/statusbar-extension:plugin . startModemoved to@jupyterlab/application-extension:shell . startModePlugin
@jupyterlab/statusbar-extension:mode-switchrenamed to@jupyterlab/application-extension:mode-switchPlugin
@jupyterlab/statusbar-extension:kernel-statusrenamed to@jupyterlab/apputils-extension:kernel-statusPlugin
@jupyterlab/statusbar-extension:running-sessions-statusrenamed to@jupyterlab/apputils-extension:running-sessions-statusPlugin
@jupyterlab/statusbar-extension:line-col-statusrenamed to@jupyterlab/codemirror-extension:line-col-statusHoverBoxcomponent moved from@jupyterlab/apputilsto@jupyterlab/ui-components.Removed
STATUSBAR_PLUGIN_IDfrom public API.
@jupyterlab/terminal从 3.x 升级到 4.xXterm.js 从 4.x 升级到 5.x
IThemeObject.selection重命名为selectionBackground
@jupyterlab/terminal-extension从 3.x 到 4.x从公共 API 中移除了
addCommands
@jupyterlab/toc从 3.x 到 4.x@jupyterlab/toc:plugin重命名为@jupyterlab/toc-extension:registry这可能会影响应用程序配置(例如,如果插件被禁用)。 命名空间TableOfContentsRegistry已重命名为TableOfContents。 API 已经完全重新设计。新的目录提供者必须实现一个工厂TableOfContents.IFactory,该工厂将为支持的 widget 创建一个模型TableOfContents.IModel。 该模型提供了一个由text和level描述的标题列表,以及可选的prefix、collapsed状态和dataset(数据 DOM 属性字典)。
@jupyterlab/ui-componentsfrom 3.x to 4.xMajor version bumped following removal of Blueprint JS dependency. Extensions using proxied components like
Checkbox,SelectorIntentwill need to import them explicitly from Blueprint JS library. Extensions usingButton,CollapseorInputGroupmay need to switch to the Blueprint components as the interfaces of those components in JupyterLab do not match those of Blueprint JS.Remove
CollapseReact component.- Form component registry changes:
Rename the plugin
'@jupyterlab/ui-components-extension:form-component-registry'to'@jupyterlab/ui-components-extension:form-renderer-registry'Rename the
IFormComponentRegistrytoken toIFormRendererRegistry, from@jupyterlab/ui-components:ISettingEditorRegistryto@jupyterlab/ui-components:IFormRendererRegistry.The
FormRendererRegistryregistersIFormRendererinstead ofFieldrenderers. AIFormRendererdefines afieldRenderer(this is the renderer to set for backward compatibility) or awidgetRenderer. The renderer id must follow the convention<ISettingRegistry.IPlugin.id>.<propertyName>. This is to ensure a custom renderer is not used for property with the same name but different schema.
@jupyterlab/translation从 3.x 到 4.x 在NullTranslator中将方法locale重命名为属性languageCode@jupyterlab/vdom和@jupyterlab/vdom-extension已被移除。 底层的 vdom Python 包无人维护。 因此决定将其从核心包中移除。jupyter.extensions.hub-extension从 3.x 到 4.x将
jupyter.extensions.hub-extension重命名为@jupyterlab/hub-extension:plugin。将
jupyter.extensions.hub-extension:plugin重命名为@jupyterlab/hub-extension:menu。
TypeScript 5.0 更新 由于更新到 TypeScript 5.0,一些接口的定义发生了变化。
HoverBox.IOptions的anchor参数现在是一个DOMRect而不是ClientRect。CodeEditor.ICoordinate接口现在扩展了DOMRectReadOnly而不是JSONObject, ClientRect。React 18.2.0 更新 从 17.0.1 更新到 React 18.2.0 的更新也应传播到扩展程序。 这里是关于 迁移到 react 18 的文档。
使用Jest进行测试#
Jest 已更新至 29.2.0(且 ts-jest 更新至 29.0.0)。因此,由 @jupyterlab/testutils 提供的 jest 配置与该版本兼容。具体来说:
未维护的报告器
jest-summary-reporter已被新的默认报告器github-actions取代。辅助工具
flakyIt已被移除。你可以使用新的 jest.retryTimes 来代替。
在JupyterLab 4中,我们修复了由于testutils包导致的循环依赖问题。因此,现在它只是一个从各种核心包中导出帮助程序的接口。导出的帮助程序与之前相同,除了:
NBTestUtils.DEFAULT_CONTENT: 已移除 - 你可以从@jupyterlab/notebook/lib/testutils导入,但我们强烈建议不要这样做,而是使用你自己的测试数据。NBTestUtils.DEFAULT_CONTENT_45: 已移除
使用Galata进行测试#
页面内的助手现在位于一个JupyterLab扩展中,以便在公共的Webpack共享范围内运行。这个新扩展包含在JupyterLab的python包中,位于jupyterlab.galata。它需要通过添加以下行来更新您的Jupyter服务器配置:
import jupyterlab
c.LabApp.extra_labextensions_path = str(Path(jupyterlab.__file__).parent / "galata")
注意
为了简化配置,我们引入了一个新的辅助函数 jupyterlab.galata.configure_jupyter_server。因此,你可以将服务器配置简化为 jupyterlab.galata.configure_jupyter_server(c)。
- Here are the changes in the Javascript package
@jupyterlab/galatafrom 4.x to 5.x: ContentsHelper和galata.newContentsHelper现在有新的构造函数参数来使用 Playwright API 请求对象:new ContentsHelper(baseURL, page?, request?)->new ContentsHelper(request?, page?)galata.newContentsHelper(baseURL, page?, request?)->galata.newContentsHelper(request?, page?)你需要提供request或page;它们都是由 Playwright 提供的 fixtures。galata.Mock.clearRunners(baseURL, runners, type)->galata.Mock.clearRunners(request, runners, type)页面内的助手现在定义在扩展中,位于
jupyterlab/galata/extension并存储在@jupyterlab/galata/lib/extension。全局对象已重命名为window.galata而不是window.galataip(它仍然存在,但已被弃用)。
已移除的弃用代码#
以下已弃用的API已被移除:
@jupyterlab/csvviewer:CSVDelimiter.delimiterChanged已被移除 - 死代码。你可以直接从CSVViewer小部件访问分隔符。@jupyterlab/mainmenu:IJupyterLabMenu和JupyterLabMenu已被移除。你可以直接使用@jupyterlab/ui-components中的IRankedMenu和RankedMenu@jupyterlab/notebook:NotebookWidgetFactory默认工具栏现在为空,因为按钮助手已被弃用。@jupyterlab/rendermime:RenderMimeRegistry.IUrlResolverOptions不接受session;你必须设置path(可通过session.path访问)。@jupyterlab/ui-components:RankedMenu.menu : Menu已被移除,因为RankedMenu继承自Menu。LabIconStyle.IProps不再接受kind和justify。你应该分别使用stylesheet或elementPosition。
扩展开发变更#
在
dev_mode/package.json文件中对应于@jupyterlab/application-top的externalExtensions字段在4.0版本中已被移除。如果您曾使用此字段来针对JupyterLab的开发版本开发源扩展,您应该转而使用联邦扩展系统(通过--extensions-in-dev-mode标志)或使用--splice-source选项。更多信息请参见开发预构建扩展和源扩展的开发工作流程。@jupyterlab/builder中的webpack依赖已更新至5.72(或更高版本)。基本规则已更新为使用 Asset Modules 而不是之前的file-loader、raw-loader和url-loader。 如果第三方扩展依赖于这些加载器的特定行为,这可能会影响它们。在 JupyterLab 3.x 中,即使预构建扩展被禁用,其 CSS 仍然会加载到页面上。在 JupyterLab 4.0 中,这种情况不再存在。
window.jupyterlab在使用--expose-app-in-browser标志启动 JupyterLab 时不再暴露。 请改用window.jupyterapp。
JupyterLab 3.5 到 3.6#
异步可迭代支持#
对于事件服务,我们使用了ES2018中引入的JavaScript特性。如果你的代码使用TypeScript并以ES2017为目标(如JupyterLab 3.6),你需要将目标更新为ES2018或在TypeScript库选项中添加"ES2018"。
注意
JupyterLab 3.6.0 发布时更新了目标为“ES2018”。我们强烈建议更新到 3.6.1 版本,该版本将目标恢复为“ES2017”。
Jest 配置更新#
如果您正在使用 jest 来测试您的扩展程序,JupyterLab 3.6 中添加了一些新的 ES6 包依赖项。在使用 Jest 转换代码时,需要忽略这些依赖项。您需要更新 transformIgnorePatterns 以匹配:
const esModules = [
'@jupyterlab/',
'@jupyter/ydoc',
'lib0',
'y\\-protocols',
'y\\-websocket',
'yjs'
].join('|');
// ...
transformIgnorePatterns: [`/node_modules/(?!${esModules}).+`]
欲了解更多信息,请查看测试您的扩展。
实时协作#
在 JupyterLab v3.6 中,必须安装 Jupyter Server v2.0 才能使用实时协作功能。 引入此要求是为了利用 Jupyter Server v2.0 中的新身份 API。
另一方面,我们还改变了JupyterLab加载文档的方式(仅在协作模式下)。 现在,提供者不再使用内容API,而是打开一个与YDocWebSocketHandler的WebSocket连接,该连接是在外部的jupyter server extension中实现的。
此外,共享模型的包被移到了一个名为@jupyter/ydoc的外部包中。所有依赖于@jupyterlab/shared-models的扩展都需要更新为依赖于@jupyter/ydoc@~0.2.2;API应该保持不变。
API 变更: 为了能够修复 RTC 并使其稳定,有必要更改 API 并进行一些破坏性更改。 这些更改不应影响绝大多数扩展。它们只会影响一些专注于 RTC 的扩展。
有必要改变JupyterLab加载文档的范式,并替换后端的锁定机制。现在,它不再识别第一个打开文档的客户端,而是通过在后端实例化一个YDoc客户端来集中处理这个过程。这个客户端是唯一一个将文档内容加载到内存中并与每个连接的其他客户端共享的客户端。
涉及的包有:
@jupyterlab/docprovider:The interface
IDocumentProvider, now extends fromIDisposable. Removed:acquireLock,releaseLock,setPath,destroy,requestInitialContentandputInitializedState. Added:readyandisDisposed.IDocumentProviderFactory.IOptionsis now templated withT extends ISharedDocument = ISharedDocument. And theymodelattribute has been renamedmodeltypedT(relaxing typing fromYDocumenttoISharedDocument).WebSocketProviderWithLockshas been renamed toWebSocketProvider. It does not extendWebSocketProviderfromy-websocketanymore.WebSocketProvider.IOptionshas a new optional attribute,user.
@jupyterlab/services:接口
IManager有一个新的可选属性user,它实现了 User.IManager。ServiceManager类实现了来自IManager的可选属性user。
JupyterLab 3.0 到 3.1#
Jest 配置更新#
如果您正在使用 jest 来测试您的扩展程序,JupyterLab 中添加了一些新的 ES6 包依赖项。在使用 Jest 转换代码时,需要忽略这些依赖项。您需要更新 transformIgnorePatterns 以匹配:
const esModules = [
'@jupyterlab/',
'lib0',
'y\\-protocols',
'y\\-websocket',
'yjs'
].join('|');
// ...
transformIgnorePatterns: [`/node_modules/(?!${esModules}).+`]
欲了解更多信息,请查看测试您的扩展。
注意
这里是一个更新到JupyterLab 3.1的拉取请求示例,位于@jupyterlab/git扩展中:
jupyterlab/jupyterlab-git#files
JupyterLab 2.x 到 3.x#
以下是一些将扩展从JupyterLab 2.x迁移到JupyterLab 3.x的有用提示。
手动升级库版本#
为了使扩展与3.0版本兼容,请更新package.json中@jupyterlab依赖项的兼容性范围。差异应类似于:
index 6f1562f..3fcdf37 100644
^^^ a/package.json
+++ b/package.json
"dependencies": {
- "@jupyterlab/application": "^2.0.0",
+ "@jupyterlab/application": "^3.0.0",
使用升级脚本升级库版本#
JupyterLab 3.0 提供了一个脚本来升级现有扩展,以使用新的扩展系统和打包方式。
首先,确保更新到 JupyterLab 3.0 并安装 jupyter-packaging 和 cookiecutter。使用 pip:
pip install jupyterlab -U
pip install jupyter-packaging cookiecutter
或者使用 conda:
conda install -c conda-forge jupyterlab=3 jupyter-packaging cookiecutter
然后在扩展的根文件夹中运行:
python -m jupyterlab.upgrade_extension .
升级脚本创建了将JupyterLab扩展打包为Python包所需的文件,例如
setup.py 和 pyproject.toml。
升级脚本还会将package.json中的依赖项更新为^3.0.0包。以下是一个示例差异:
index 6f1562f..3fcdf37 100644
^^^ a/package.json
+++ b/package.json
@@ -29,9 +29,13 @@
"scripts": {
- "build": "tsc",
- "build:labextension": "npm run clean:labextension && mkdirp myextension/labextension && cd myextension/labextension && npm pack ../..",
- "clean": "rimraf lib tsconfig.tsbuildinfo",
+ "build": "jlpm run build:lib && jlpm run build:labextension:dev",
+ "build:prod": "jlpm run build:lib && jlpm run build:labextension",
+ "build:lib": "tsc",
+ "build:labextension": "jupyter labextension build .",
+ "build:labextension:dev": "jupyter labextension build --development True .",
+ "clean": "rimraf lib tsconfig.tsbuildinfo myextension/labextension",
+ "clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
"clean:labextension": "rimraf myextension/labextension",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
@@ -59,12 +63,12 @@
]
},
"dependencies": {
- "@jupyterlab/application": "^2.0.0",
- "@jupyterlab/apputils": "^2.0.0",
- "@jupyterlab/observables": "^3.0.0",
+ "@jupyterlab/builder": "^3.0.0",
+ "@jupyterlab/application": "^3.0.0",
+ "@jupyterlab/apputils": "^3.0.0",
+ "@jupyterlab/observables": "^3.0.0",
"@lumino/algorithm": "^1.2.3",
"@lumino/commands": "^1.10.1",
"@lumino/disposable": "^1.3.5",
@@ -99,6 +103,13 @@
- "typescript": "~3.8.3"
+ "typescript": "~4.0.1"
},
"jupyterlab": {
- "extension": "lib/plugin"
+ "extension": "lib/plugin",
+ "outputDir": "myextension/labextension/"
}
}
在上面的差异中,我们看到还添加了额外的开发脚本,因为它们被新的扩展系统工作流使用。
差异还显示了新的@jupyterlab/builder作为devDependency。
@jupyterlab/builder是一个包,用于将扩展构建为联合(预构建)扩展。
它隐藏了内部依赖项,如webpack,并生成可以作为Python包的一部分分发的资产。
扩展开发者不需要直接与@jupyterlab/builder交互,而是可以使用jupyter labextension build命令。这个命令作为build脚本的一部分自动运行(jlpm run build)。
有关扩展的新文件结构和打包的更多详细信息,请查看扩展教程:扩展教程
将扩展发布到PyPI和conda-forge#
从 JupyterLab 3.0 开始,扩展可以作为 Python 包分发。
扩展教程提供了如何打包扩展的解释,以便它可以发布在PyPI和conda forge上:发布你的扩展。
注意
虽然发布到 PyPI 是向用户分发扩展的新推荐方式,但继续将扩展发布到 npm 仍然有用,这样其他开发者可以在他们自己的扩展中扩展它们。
JupyterLab 1.x 到 2.x#
以下是一些将扩展从 JupyterLab 1.x 迁移到 JupyterLab 2.x 的有用提示。我们将看两个扩展的示例,这些示例涵盖了扩展作者可能使用的大多数 API:
@jupyterlab/debugger迁移拉取请求: jupyterlab/debugger#files@jupyterlab/shortcutui迁移拉取请求: jupyterlab/jupyterlab-shortcutui#files
升级库版本#
JupyterLab 1.x 使用的 @phosphor/* 库已更名为 @lumino/*。更新您的 package.json 非常简单。最简单的方法是查看 JupyterLab 核心包代码库 并直接采用那里使用的相关库的版本。
在package.json中更新调试器扩展的库#
在package.json中更新快捷方式UI扩展的库#
提示
在这些示例中,请注意我们使用的是许多库的2.0.0-beta.x版本。这是为了在最终版本发布之前测试这些扩展与JupyterLab 2.0 beta版本的兼容性。对于最终版本,您的package.json应该依赖于这些包的^2.0.0版本。
从 @phosphor 迁移到 @lumino
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
JupyterLab 使用的基础包现在都带有 NPM 命名空间 @lumino 而不是 @phosphor。这些包的 API 没有变化。需要将 @phosphor 命名空间的导入更新为新的 @lumino 命名空间包:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
警告
p- 前缀的 CSS 类、data-p- 属性和 p- DOM 事件
已被弃用。它们将继续工作,直到 Lumino 的下一个主要版本发布。
.p-CSS类如.p-Widget应更新为.lm-, 例如.lm-Widgetdata-p-属性,例如data-p-dragscroll应更新为data-lm-,例如data-lm-dragscrollp-DOM事件,如p-dragenter应更新为lm-, 例如lm-dragenter
更新以前的 @jupyterlab/coreutils 导入
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
JupyterLab 2.0 引入了几个新的包,这些包中的类和令牌已经从 @jupyterlab/coreutils 移出到它们自己的包中。这些导出已经被移动。
提示
在更新这些库时,删除 node_modules 和 yarn.lock 可能会有帮助。
导出 |
包 |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
使用Session和SessionContext来管理内核会话#
注意
有关完整的API文档以及如何使用
@jupyterlab/services的示例,
请查阅存储库。
ConsolePanel 和 NotebookPanel 现在暴露了一个
sessionContext: ISessionContext 属性,允许以统一的方式与内核会话进行交互。
任何匹配interface IDocumentWidget的小部件都有一个
context: DocumentRegistry.IContext属性,该属性包含一个
sessionContext: ISessionContext属性。
例如,考虑@jupyterlab/debugger扩展的
DebuggerService如何更新其isAvailable()方法。
注意
await kernel.ready 在可以使用 kernel 之前不再是必要的。内核消息将在内核连接上线时根据需要缓冲,因此您应该能够立即使用内核连接。如果您想检索内核信息(或者出于其他原因,您想等待至少一条消息从新内核连接返回),您可以执行 await kernel.info。
使用新的图标系统和LabIcon#
注意
有关如何使用基于LabIcon的新图标支持的完整API文档和示例,请参阅@jupyterlab/ui-components,查看存储库。