-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JEP for adding $schema to notebook format #97
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f45102
Add JEP for adding $schema to notebook format
filipsch e265176
wip: update from meeting
agoose77 9092dae
Merge pull request #1 from agoose77/agoose77/update-jep
025147d
Update add-schema-to-notebook-format.md
tonyfast 8fe3c7d
Merge pull request #2 from tonyfast/patch-1
0871ad1
Update URI to align with JEP #108
fcollonval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,117 @@ | ||
--- | ||
title: Add `$schema` to notebook format | ||
authors: Jason Grout (@jasongrout), Angus Hollans (@agoose77), | ||
Nicholas Bollweg (@bollwyvl), Filip Schouwenaars (@filipsch) | ||
issue-number: xxx | ||
pr-number: 97 | ||
date-started: 2023-03-01 | ||
--- | ||
|
||
# Summary | ||
|
||
We propose to add a new top-level field, `$schema` to the notebook JSON, as such updating the notebook JSON schema. This new field deprecates `nbformat` and `nbformat_minor`. | ||
|
||
# Motivation | ||
|
||
Today, `nbformat` and `nbformat_minor` specify the JSON schema a notebook should adhere to (for example [4.5](https://github.com/jupyter/nbformat/blob/main/nbformat/v4/nbformat.v4.5.schema.json)). Since this approach was adopted in the Jupyter ecosystem, the JSON schema standard has evolved and Jupyter's approach is no longer in line with it. Other than following standards being the right thing to do, bringing the notebook format back in line with the current JSON Schema spec opens it up to the rich tooling that exists around JSON schema validation today. | ||
|
||
# Guide-level explanation | ||
|
||
The introduction of a new `$schema` top-level property takes precedence over the existing `"nbformat"` and `"nbformat_minor"` properties that specify the notebook format. | ||
|
||
Example of notebook in 4.5 format: | ||
|
||
``` | ||
{ | ||
"nbformat": 4 | ||
"nbformat_minor": 5 | ||
"metadata": { ... } | ||
"cells": [ ... ] | ||
} | ||
``` | ||
|
||
Example of notebook in 4.6 format: | ||
|
||
``` | ||
{ | ||
"$schema": "https://jupyter.org/schema/notebook/4.6/notebook-4.6.schema.json" | ||
"nbformat": 4 | ||
"nbformat_minor": 6 | ||
"metadata": { ... } | ||
"cells": [ ... ] | ||
} | ||
``` | ||
|
||
It is REQUIRED that the top-level `$schema` be a canonical URI that refers to the Jupyter Notebook formats, i.e. `$schema` cannot be an arbitrary URI to a valid notebook schema, but instead must be useable as a token that uniquely identifies that schema, e.g.: | ||
|
||
Valid `$schema` URI: | ||
|
||
```json | ||
{ | ||
"$schema": "https://jupyter.org/schema/notebook/4.6/notebook-4.6.schema.json" | ||
... | ||
} | ||
``` | ||
|
||
Invalid `$schema` URI: | ||
|
||
```json | ||
{ | ||
"$schema": "https://jupyter.org/schema/../schema/notebook/4.6/notebook-4.6.schema.json" | ||
... | ||
} | ||
``` | ||
|
||
# Reference-level explanation | ||
|
||
JSON Schema changes: | ||
|
||
``` | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"description": "Jupyter Notebook v4.5 JSON schema.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["$schema", "nbformat", "nbformat_minor", metadata", "cells"], // CHANGED | ||
"properties": { | ||
"$schema": { | ||
"description": "JSON schema the notebook should adhere to", | ||
"type": "string" | ||
} | ||
"metadata": { <no changes > } | ||
"nbformat_minor": { | ||
"description": "Notebook format (minor number). Incremented for backward compatible changes to the notebook format.", | ||
"type": "integer", | ||
"minimum": 6, | ||
"deprecated": true // CHANGED | ||
}, | ||
"nbformat": { | ||
"description": "Notebook format (major number). Incremented between backwards incompatible changes to the notebook format.", | ||
"type": "integer", | ||
"minimum": 4, | ||
"maximum": 4 | ||
"deprecated": true // CHANGED | ||
}, | ||
"cells": [ <no changes> ] | ||
}, | ||
"definitions": { <no changes> } | ||
} | ||
``` | ||
|
||
# Rationale and alternatives | ||
|
||
Not doing this will leave the Jupyter notebook format in a non-standard state. | ||
|
||
# Prior art | ||
|
||
[JSON Schema](https://json-schema.org/) is a widely adopted declarative language that annotates and validates documents, so it's the obvious candidate to adhere to. | ||
|
||
# Unresolved questions | ||
|
||
- Code to upgrade from and downgrade to 4.5 still needs to be written. | ||
Some exploration has been done by Nick Bollweg in [this gist](https://gist.github.com/bollwyvl/a6e1ae13125f01ff04edf121e30a462a). | ||
- We want to deprecate `nbformat` and `nbformat_minor` in favor of `$schema` but we also need to ensure old clients can still work with notebooks in this new schema, so `nbformat` and `nbformat_minor` are still required. What's the path here? Major version update? | ||
|
||
# Future possibilities | ||
|
||
This work paves the way for [``Add `extraSchemas` to notebook format`` JEP](https://hackmd.io/9QZ8YibfQHm9l1B6JPSQsg?both), which will be submitted as a separate JEP soon. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From our notebook format workshop meeting this morning, we'll need to bump to at least JSON Schema draft 2019 to have the deprecated keyword, and maybe we should bump this to the 2020 draft (i.e., the latest draft)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need to introduce support for this new keyword in the existing schemas, i.e. backport the addition to our existing schemas. This should be acceptable, as these schemas are not declared immutable, and it would be a permissive change.
We should also define how to ensure that the nbformat versions align with the document schema during the deprecation period. One solution is to ensure that they're constants in the schema. Thereafter, we could move to a single-version number (major) for each schema revision, as they compatibility is enforced by
$schema
itself.I don't know of a reason not to bump to 2020 draft, besides the risk of existing tooling not supporting newer drafts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say for the newer version it is acceptable to bump the schema to the latest draft after ensuring there is no backward incompatibility between the current version based on draft 04 and the new draft - as far as I know some breaking changes are induced when upgrading from draft 04 to draft 06.
Additionally if we are to bump the JSON Schema draft, I would switch all
enum
with single value to the newconst
as used for the nbformat version numbers (see mainlycell_type
andoutput_type
).