Skip to content

Commit

Permalink
Merge pull request #216 from aless80/main
Browse files Browse the repository at this point in the history
issue #213: reproducible IDs in ipynb format
  • Loading branch information
aless80 committed Nov 29, 2021
2 parents 10ac007 + a3fad03 commit 2f34c98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/doconce/ipynb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import
from builtins import str
from builtins import range
import hashlib
import sys, shutil, os
import regex as re
import shlex
Expand Down Expand Up @@ -695,7 +696,8 @@ def subst(m):
cells.append(new_markdown_cell(source=block, metadata=dict(editable=editable_md)))
#mdstr.append(('markdown', block))
elif block_tp == 'cell':
# TODO: now I need to handle -hid also in 'markdown' type. actually the logic on postfixes should be separated from LANG
# TODO: now I need to handle -hid also in 'markdown' formats. The logic on postfixes should actually be
# separated from LANG
LANG, codetype, postfix, postfix_err = get_code_block_args('!bc ' + notebook_block_envir[j])
j += 1
execute, show = get_execute_show((LANG, codetype, postfix))
Expand Down Expand Up @@ -750,6 +752,13 @@ def subst(m):
if cell:
cells.append(cell)

# Replace the random id with a reproducible hash of the content (issue #213)
# nbformat 5.1.3 creates random cell ID with `uuid.uuid4().hex[:8]`
for i in range(len(cells)):
if 'id' in cell.keys():
cell_content = str(i) + cells[i]['source']
cells[i]['id'] = hashlib.sha224(cell_content.encode()).hexdigest()[:8]

# Create the notebook in string format
nb = new_notebook(cells=cells)
filestr = writes(nb, version=4)
Expand Down
2 changes: 1 addition & 1 deletion test
Submodule test updated 47 files
+1 −1 admon.txt
+1 −1 admon_demo/._admon_bootstrap_alert000.html
+1 −1 admon_demo/admon_apricot.html
+1 −1 admon_demo/admon_bootstrap_alert.html
+1 −1 admon_demo/admon_bootswatch_panel.html
+1 −1 admon_demo/admon_colors.html
+ admon_demo/admon_colors1.pdf
+ admon_demo/admon_colors2.pdf
+1 −1 admon_demo/admon_gray.html
+ admon_demo/admon_graybox2.pdf
+ admon_demo/admon_grayicon.pdf
+1 −1 admon_demo/admon_lyx.html
+ admon_demo/admon_mdfbox.pdf
+1 −1 admon_demo/admon_mwiki.mwiki
+1 −1 admon_demo/admon_paragraph-footnotesize.html
+ admon_demo/admon_paragraph-footnotesize.pdf
+1 −1 admon_demo/admon_paragraph.html
+1 −1 admon_demo/admon_paragraph.txt
+1 −1 admon_demo/admon_sphinx/_sources/admon.rst.txt
+1 −1 admon_demo/admon_sphinx/admon.html
+1 −1 admon_demo/admon_yellow.html
+ admon_demo/admon_yellowicon.pdf
+1 −1 admon_sphinx/_sources/admon.rst.txt
+1 −1 admon_sphinx/admon.html
+5 −5 demo_testdoc.html
+1 −1 html_template1.html
+1 −1 locale.html
+1 −1 locale.tex
+1 −1 movie_demo/movies.html
+ movie_demo/movies.pdf
+1 −1 movie_demo/movies_3choices.html
+ movie_demo/movies_media9.pdf
+ movie_demo/movies_media9_extviewer.pdf
+1 −1 movies.txt
+515 −277 test.r
+247 −7 test.v
+198 −198 testr/._testdoc001.html
+15 −15 testr/._testdoc002.html
+12 −12 testr/._testdoc_vagrant001.html
+9 −9 testr/execute.html
+51 −5 testr/execute.ipynb
+23 −1 testr/nbdemo.ipynb
+171 −1 testr/testdoc.ipynb
+12 −12 testr/testdoc_code_prefix.html
+12 −12 testr/testdoc_no_solutions.html
+11 −11 testr/testdoc_wordpress.html
+2 −1 tests.py

0 comments on commit 2f34c98

Please sign in to comment.