A cookiecutter template for creating a JupyterLab and Jupyter Notebook extension for rendering specific mime types and file extensions.
Install cookiecutter:
pip install cookiecutter
Use cookiecutter to generate a package:
cookiecutter https://github.com/jupyterlab/mimerender-cookiecutter
The cookiecutter will prompt you with the following questions and generate a project according to your responses:
author_name: Your full name. This will be used in the generated Python and npm packages.author_email: Your email address. This will be used in the generated Python and npm packages.mime_type: A valid mime type (e.g.application/json,application/geo+json). This will be used to render output data of this mime type with your extension.mime_short_name: A display name (no spaces) for your mime type (e.g.JSON,GeoJSON). This will be used in the generated Python and npm packages, README, and class names.file_type: OPTIONAL A valid file type (e.g.json,geojson). This will be used to open files of this type with your extension.extension_name: Your JupyterLab and Jupyter Notebook extension name (e.g.jupyerlab_json,jupyerlab_geojson).
The project is divided into 2 top-level directories, one for each extension (lab and notebook).
In most cases, you will only need to edit the OutputWidget._render method in labextension/src/output.js (for rendering output data of a specific mime type) and the DocWidget.onUpdateRequest method in labextension/src/doc.js (if your extension should render files of a specific type).
extension_nameextension_name: The Python packagestatic: Compiled Javascript for the notebook extension.__init__.py: Exports paths and metadata of lab and notebook extensions and exports an optionaldisplaymethod that can be imported into a notebook and used to easily display data using this renderer
src- The extension source.embed.js: Entry point for embedded widgetextension.js: Integration point with Jupyter Notebookindex.js: Entry point for the Jupyter Notebook extensionplugin.js: Entry point for the JupyterLab extensionrenderer.js: Methods for rendering output data ofmime_typedefined in prompts
This cookiecutter will change over time to adapt to API changes and best practices, so you should be able to rebase your extension from an updated version of the cookiecutter. The following is the recommended workflow:
- Create a branch called
cookiecutterthat will serve as the base for another branch calleddevelop. All feature branches shoud be based ondevelopand merged intomaster. - When a new version of mimerender-cookiecutter is available:
- Checkout
cookiecutterbranch:git checkout cookiecutter - Re-run the cookiecutter command from the repository root:
cookiecutter https://github.com/jupyterlab/mimerender-cookiecutter [--checkout BRANCH_NAME] --output-dir .. --config-file .cookiecutter.yaml --no-input --overwrite-if-exists--checkoutis optional and specifies a branch of mimerender-cookiecutter to checkout (e.g.react).--output-dir ..allows us to run the cookiecutter in the repo root vs. the parent directory because cookiecutter will always render output in a child directory of theoutput-dir.--config-file .cookiecutter.yamlwill run the cookiecutter with the original inputs which are persisted to.cookiecutter.yamlin the repo root.--no-inputwill skip the cookiecutter prompts.--overwrite-if-existswill replace our previous cookiecutter output with the most up-to-date output.
- Commit these changes to
cookiecutterwith a message like "mimerender-cookiecutter [VERSION_NUMBER]":git commit -m "mimerender-cookiecutter [VERSION_NUMBER]" - Checkout the
developbranch:git checkout develop - Rebase it from
cookiecutter:git rebase cookiecutter- You may encounter some merge conflicts, so resolve them and complete the rebase using
git rebase --continue
- You may encounter some merge conflicts, so resolve them and complete the rebase using
- Publish a new version of your extension by following the instructions in
RELEASE.md.
- Checkout
We suggest that extension names start with jupyterlab_ and use underscores if needed to improve readability, such as jupyterlab_myextension.
