跳转到主要内容

一个用于展示和下载远程存储库示例的JupyterLab画廊扩展

项目描述

jupyterlab-gallery

Extension status Github Actions Status Binder

一个用于展示和下载远程存储库示例的JupyterLab画廊扩展

此扩展由一个名为 jupyterlab-gallery 的Python包(用于服务器扩展)和一个名为 jupyterlab-gallery 的NPM包(用于前端扩展)组成。

当安装 jupyterlab-new-launcher 时,画廊将被添加到启动器的“画廊”部分;否则,它将显示在左侧边栏中。

配置

您可以使用以下traitlets配置画廊

  • GalleryManager.exhibits:控制画廊中显示的瓷砖
  • GalleryManager.destination:定义要克隆展览的路径(默认为/gallery
  • GalleryManager.title:小部件的显示名称(默认为“画廊”)

这些traitlets可以从命令行、JSON文件(.json)或Python文件(.py)传递。

您必须将文件命名为 jupyter_gallery_config.pyjupyter_gallery_config.json,并将其放置在 jupyter --paths 返回的路径之一下,位于 config 部分。

一个示例Python文件可能包括

c.GalleryManager.title = "Examples"
c.GalleryManager.destination = "examples"
c.GalleryManager.exhibits = [
    {
        "git": "https://github.com/jupyterlab/jupyterlab.git",
        "homepage": "https://github.com/jupyterlab/jupyterlab/",
        "title": "JupyterLab",
        "description": "JupyterLab is a highly extensible, feature-rich notebook authoring application and editing environment.",
        "icon": "https://raw.githubusercontent.com/jupyterlab/jupyterlab/main/packages/ui-components/style/icons/jupyter/jupyter.svg"
    },
    {
        "git": "https://github.com/my_org/private-tutorial.git",
        "account": "name-of-the-account-or-app-owning-the-token",
        "token": "access-token-for-example-starting-with-github_pat_",
        "title": "My private tutorial",
        "description": "A tutorial which is not public.",
    },
    {
        "git": "https://github.com/my_org/public-tutorial.git",
        "title": "My tutorial",
        "branch": "v2024",
        "depth": 1
    }
]

使用Python文件可以将个人访问令牌(PAT)注入到token段落中,如果您更愿意将其存储在环境变量中而不是配置文件中(推荐)。

可以通过执行以下命令将画廊应用程序后端作为独立的服务器应用程序运行:

jupyterlab-gallery

要在JupyterHub环境中将其作为单用户服务器运行,请使用以下命令:

jupyterhub-gallery

要求

  • JupyterLab >= 4.0.0

安装

要安装扩展,请执行以下命令:

pip install jupyterlab-gallery

卸载

要删除扩展,请执行以下命令:

pip uninstall jupyterlab-gallery

故障排除

如果您看到了前端扩展,但它在运行中不正常,请检查服务器扩展是否已启用。

jupyter server extension list

如果服务器扩展已安装并启用,但您没有看到前端扩展,请检查前端扩展是否已安装。

jupyter labextension list

贡献

开发安装

注意:您需要NodeJS来构建扩展包。

jlpm命令是JupyterLab的固定版本yarn,它是与JupyterLab一起安装的。您可以使用yarnnpm代替下面的jlpm

# Clone the repo to your local environment
# Change directory to the jupyterlab-gallery directory
# Install package in development mode
pip install -e ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jupyterlab_gallery
# Rebuild extension Typescript source after making changes
jlpm build

您可以在不同的终端中同时监视源目录并运行JupyterLab,以便监视扩展源的变化并自动重新构建扩展。

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab

当监视命令运行时,每次保存的更改将立即本地构建并可在您的运行JupyterLab中可用。刷新JupyterLab以在浏览器中加载更改(您可能需要等待几秒钟以重建扩展)。

默认情况下,jlpm build命令为此扩展生成源映射,以便更容易使用浏览器开发者工具进行调试。要为JupyterLab核心扩展也生成源映射,您可以运行以下命令

jupyter lab build --minimize=False

开发卸载

# Server extension must be manually disabled in develop mode
jupyter server extension disable jupyterlab_gallery
pip uninstall jupyterlab-gallery

在开发模式下,您还需要删除由jupyter labextension develop命令创建的符号链接。要找到其位置,您可以使用jupyter labextension list来确定labextensions文件夹的位置。然后您可以从该文件夹中删除名为jupyterlab-gallery的符号链接。

测试扩展

服务器测试

此扩展使用Pytest进行Python代码测试。

安装测试依赖关系(只需安装一次)

pip install -e ".[test]"
# Each time you install the Python package, you need to restore the front-end extension link
jupyter labextension develop . --overwrite

要执行它们,请运行以下命令:

pytest -vv -r ap --cov jupyterlab-gallery

前端测试

此扩展使用Jest进行JavaScript代码测试。

要执行它们,请执行以下命令:

jlpm
jlpm test

集成测试

此扩展使用Playwright进行集成测试(也称为用户级测试)。更确切地说,JupyterLab助手Galata用于在JupyterLab中处理扩展的测试。

更多详细信息请参阅ui-tests的README。

打包扩展

请参阅RELEASE

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

jupyterlab_gallery-0.6.3.tar.gz (163.9 kB 查看哈希值)

上传于 源代码

构建分发

jupyterlab_gallery-0.6.3-py3-none-any.whl (36.8 kB 查看哈希值)

上传于 Python 3

由以下支持