Skip to content

Commit

Permalink
Only require nbformat_minor for v4 (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk authored Jan 11, 2023
1 parent 2916339 commit 30f3d81
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions nbformat/v4/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ def upgrade(nb, from_version=None, from_minor=None):
from_version = nb["nbformat"]
if not from_minor:
if "nbformat_minor" not in nb:
raise validator.ValidationError(
"The notebook does not include the nbformat minor which is needed"
)
from_minor = nb["nbformat_minor"]
if from_version == 4:
raise validator.ValidationError(
"The v4 notebook does not include the nbformat minor, which is needed."
)
else:
from_minor = 0
else:
from_minor = nb["nbformat_minor"]

if from_version == 3:
# Validate the notebook before conversion
Expand Down
12 changes: 12 additions & 0 deletions tests/test3_no_min_version.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"metadata": {
"name": ""
},
"nbformat": 3,
"worksheets": [
{
"metadata": {},
"cells": []
}
]
}
6 changes: 6 additions & 0 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ def test_notebook_invalid_without_min_version():
validate(nb)


def test_notebook_v3_valid_without_min_version():
with TestsBase.fopen("test3_no_min_version.ipynb", "r") as f:
nb = read(f, as_version=4)
validate(nb)


def test_notebook_invalid_without_main_version():
pass

Expand Down

0 comments on commit 30f3d81

Please sign in to comment.