-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
224 additions
and
65 deletions.
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
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
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
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,52 @@ | ||
"""Current file format for the various text only notebook extensions""" | ||
|
||
import os | ||
|
||
FILE_FORMAT_VERSION = { | ||
# R markdown format | ||
'.Rmd': '1.0', | ||
# Version 1.0 on 2018-08-22 - nbrmd v0.5.2 : Initial version | ||
|
||
# Python scripts | ||
'.py': '1.0', | ||
# Version 1.0 on 2018-08-22 - nbrmd v0.5.2 : Initial version | ||
|
||
# Python scripts | ||
'.R': '1.0', | ||
# Version 1.0 on 2018-08-22 - nbrmd v0.5.2 : Initial version | ||
} | ||
|
||
|
||
def file_format_version(ext): | ||
"""Return file format version for given ext""" | ||
return FILE_FORMAT_VERSION.get(ext) | ||
|
||
|
||
def check_file_version(nb, source_path, outputs_path): | ||
"""Raise if file version in source file would override outputs""" | ||
_, ext = os.path.splitext(source_path) | ||
current = file_format_version(ext) | ||
version = nb.metadata.get('nbrmd_file_format_version') | ||
if version: | ||
del nb.metadata['nbrmd_file_format_version'] | ||
|
||
# Missing version, still generated by nbrmd? | ||
if nb.metadata and not version: | ||
version = current | ||
|
||
# Same version? OK | ||
if version == current: | ||
return | ||
|
||
# Not merging? OK | ||
if source_path == outputs_path: | ||
return | ||
|
||
raise ValueError("File {} has nbrmd_file_format_version={}, but " | ||
"current version for that extension is {}.\n" | ||
"It would not be safe to override the contents of {} " | ||
"with that file.\n" | ||
"Please remove one or the other file" | ||
.format(os.path.basename(source_path), | ||
version, current, | ||
os.path.basename(outputs_path))) |
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
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,8 @@ | ||
{ | ||
"cells": [], | ||
"metadata": { | ||
"nbrmd_formats": "ipynb,py" | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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,7 @@ | ||
--- | ||
jupyter: | ||
nbrmd_formats: ipynb,py | ||
nbrmd_file_format_version: '1.0' | ||
--- | ||
|
||
# New cell |
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
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
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
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
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
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
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
Oops, something went wrong.