Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 29fae38

Browse files
authored
Simplifications (#362)
* Simplifications * better cleaning of notebooks
1 parent a4d64ef commit 29fae38

File tree

5 files changed

+13
-77
lines changed

5 files changed

+13
-77
lines changed

_doc/notebooks/having_a_form_in_a_notebook.ipynb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,32 +1116,6 @@
11161116
"nbconvert_exporter": "python",
11171117
"pygments_lexer": "ipython3",
11181118
"version": "3.7.2"
1119-
},
1120-
"widgets": {
1121-
"state": {
1122-
"6f6cf4a1f7df4a99ba95db615ec86dff": {
1123-
"views": [
1124-
{
1125-
"cell_index": 20
1126-
}
1127-
]
1128-
},
1129-
"c67410ee5aa443b9a6cb53d4f46becec": {
1130-
"views": [
1131-
{
1132-
"cell_index": 20
1133-
}
1134-
]
1135-
},
1136-
"dd3c00717e9d48b99bb5e34462b15fa0": {
1137-
"views": [
1138-
{
1139-
"cell_index": 20
1140-
}
1141-
]
1142-
}
1143-
},
1144-
"version": "1.2.0"
11451119
}
11461120
},
11471121
"nbformat": 4,

_unittests/ut_helpgen/notebooks/td2a_cenonce_session_3A.ipynb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,18 +1636,6 @@
16361636
"nbconvert_exporter": "python",
16371637
"pygments_lexer": "ipython3",
16381638
"version": "3.9.5"
1639-
},
1640-
"widgets": {
1641-
"state": {
1642-
"37694361e5da4eb38daa525f8bb2117c": {
1643-
"views": [
1644-
{
1645-
"cell_index": 9
1646-
}
1647-
]
1648-
}
1649-
},
1650-
"version": "1.2.0"
16511639
}
16521640
},
16531641
"nbformat": 4,

_unittests/ut_helpgen/test_notebooks_bug.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,31 @@
55
import os
66
import unittest
77
import re
8-
from pyquickhelper.loghelper import fLOG
98
from pyquickhelper.helpgen.sphinx_main import process_notebooks
109
from pyquickhelper.pycode import is_travis_or_appveyor, get_temp_folder, ExtTestCase
1110

1211

1312
class TestNoteBooksBug(ExtTestCase):
1413

1514
def test_regex(self):
16-
fLOG(
17-
__file__,
18-
self._testMethodName,
19-
OutputPrint=__name__ == "__main__")
2015
exp = re.compile(r"(.{3}[\\]\$)")
2116
s = ": [ ['$',"
22-
fLOG(s)
2317
r = exp.finditer(s)
2418
nb = 0
2519
for _ in r:
26-
fLOG("1", _.groups())
2720
nb += 1
2821
nb1 = nb
2922

3023
s = r"\def\PYZdl{\char`\$}"
31-
fLOG(s)
3224
r = exp.finditer(s)
3325
nb = 0
3426
for _ in r:
35-
fLOG("2", _.groups())
3627
nb += 1
3728

3829
self.assertEqual(nb1, 0)
3930
self.assertTrue(nb > 0)
4031

4132
def test_notebook(self):
42-
fLOG(
43-
__file__,
44-
self._testMethodName,
45-
OutputPrint=__name__ == "__main__")
4633
path = os.path.abspath(os.path.split(__file__)[0])
4734
fold = os.path.normpath(os.path.join(path, "notebooks"))
4835
nbs = [os.path.join(fold, _)
@@ -55,7 +42,6 @@ def test_notebook(self):
5542
return
5643

5744
res = process_notebooks(nbs, temp, temp, formats=formats)
58-
fLOG("*****", len(res))
5945
for _ in res:
6046
if not os.path.exists(_[0]):
6147
raise Exception(_[0])
@@ -67,10 +53,6 @@ def test_notebook(self):
6753
raise Exception(content)
6854

6955
def test_notebook_html(self):
70-
fLOG(
71-
__file__,
72-
self._testMethodName,
73-
OutputPrint=__name__ == "__main__")
7456
path = os.path.abspath(os.path.split(__file__)[0])
7557
fold = os.path.normpath(os.path.join(path, "notebooks"))
7658
nbs = [os.path.join(fold, _)
@@ -83,16 +65,11 @@ def test_notebook_html(self):
8365
return
8466

8567
res = process_notebooks(nbs, temp, temp, formats=formats)
86-
fLOG("*****", len(res))
8768
for _ in res:
8869
if not os.path.exists(_[0]):
8970
raise Exception(_[0])
9071

9172
def test_notebook_slides(self):
92-
fLOG(
93-
__file__,
94-
self._testMethodName,
95-
OutputPrint=__name__ == "__main__")
9673
path = os.path.abspath(os.path.split(__file__)[0])
9774
fold = os.path.normpath(os.path.join(path, "notebooks"))
9875
nbs = [os.path.join(fold, _)
@@ -105,7 +82,6 @@ def test_notebook_slides(self):
10582
return
10683

10784
res = process_notebooks(nbs, temp, temp, formats=formats)
108-
fLOG("*****", len(res))
10985
for _ in res:
11086
if not os.path.exists(_[0]):
11187
raise Exception(_[0])
@@ -117,10 +93,6 @@ def test_notebook_slides(self):
11793
raise Exception(check)
11894

11995
def test_notebook_pdf(self):
120-
fLOG(
121-
__file__,
122-
self._testMethodName,
123-
OutputPrint=__name__ == "__main__")
12496
path = os.path.abspath(os.path.split(__file__)[0])
12597
fold = os.path.normpath(os.path.join(path, "notebooks"))
12698
nbs = [os.path.join(fold, _)
@@ -137,9 +109,7 @@ def test_notebook_pdf(self):
137109
return
138110

139111
res = process_notebooks(nbs, temp, temp, formats=formats)
140-
fLOG("*****", len(res))
141112
for _ in res:
142-
fLOG(_)
143113
self.assertExists(_[0])
144114

145115
check = os.path.join(temp, "td1a_correction_session4.tex")
@@ -150,4 +120,4 @@ def test_notebook_pdf(self):
150120

151121

152122
if __name__ == "__main__":
153-
unittest.main()
123+
unittest.main(verbosity=2)

src/pyquickhelper/ipythonhelper/notebook_helper.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ def remove_execution_number(infile, outfile=None, encoding="utf-8", indent=2, ru
451451
@param indent indentation
452452
@param rule determines the rule which specifies execution numbers,
453453
'None' for None, 'int' for consectuive integers numbers.
454-
@return modified string or None if outfile is not None and the file was not modified
454+
@return modified string or None if outfile is not None
455+
and the file was not modified
455456
456457
.. todoext::
457458
:title: remove execution number from notebook facilitate git versionning
@@ -465,7 +466,8 @@ def remove_execution_number(infile, outfile=None, encoding="utf-8", indent=2, ru
465466
Remove execution number from the notebook
466467
to avoid commiting changes only about those numbers
467468
468-
`notebook 5.1.0 <https://jupyter-notebook.readthedocs.io/en/stable/changelog.html>`_
469+
`notebook 5.1.0
470+
<https://jupyter-notebook.readthedocs.io/en/stable/changelog.html>`_
469471
introduced changes which are incompatible with
470472
leaving the cell executing number empty.
471473
"""
@@ -497,9 +499,17 @@ def fixup(adict, k, v, cellno=0, outputs="outputs"):
497499
outputs=outputs)
498500
return cellno
499501

502+
def widget(adict):
503+
metadata = adict.get('metadata', None)
504+
if metadata is None:
505+
return
506+
if 'widgets' in metadata:
507+
del metadata['widgets']
508+
500509
content = read_content_ufs(infile)
501510
js = json.loads(content)
502511
fixup(js, "execution_count", None)
512+
widget(js)
503513
st = StringIO()
504514
json.dump(js, st, indent=indent, sort_keys=True)
505515
res = st.getvalue()

src/pyquickhelper/sphinxext/sphinximages/sphinxtrib/images.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,6 @@ def configure_backend(app):
323323
# because sphinx try to make a pickle from it.
324324
app.sphinxtrib_images_backend = backend
325325

326-
logger = logging.getLogger("image")
327-
logger.info(
328-
'Initiated images backend: %s:%s',
329-
backend.__class__.__module__,
330-
backend.__class__.__name__)
331-
332326
def backend_methods(node, output_type):
333327
"local function"
334328
def backend_method(f):

0 commit comments

Comments
 (0)