From f319a716e90488aa7b6e50a22600e01e60c1084e Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Thu, 5 Mar 2026 13:08:08 -0500 Subject: [PATCH 1/4] colored cells. Still need to clean notebook --- .../code_generators/no-tests/_stats_notebook.py | 16 +++++++++++----- .../code_generators/no-tests/_synth_notebook.py | 16 +++++++++++----- pyproject.toml | 4 ++-- requirements-dev.txt | 14 ++++++++++---- requirements.in | 2 +- requirements.txt | 10 +++++++--- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py b/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py index b01a24c3..c37be3e0 100644 --- a/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py +++ b/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py @@ -1,8 +1,14 @@ -# {"tagmap":{ -# "Brief Report": [], -# "Full Tutorial": ["tutorial"], -# "Include Postprocessing": ["tutorial", "postprocessing"] -# }} +# { +# "tag_map": { +# "Brief Report": [], +# "Full Tutorial": ["tutorial"], +# "Include Postprocessing": ["tutorial", "postprocessing"] +# }, +# "css_map": { +# "tutorial": "background: lightblue;", +# "postprocessing": "background: lightblue;" +# } +# } # # TITLE # diff --git a/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py b/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py index 11496b67..e91df4e7 100644 --- a/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py +++ b/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py @@ -1,8 +1,14 @@ -# {"tagmap":{ -# "Brief Report": [], -# "Full Tutorial": ["tutorial"], -# "Include Postprocessing": ["tutorial", "postprocessing"] -# }} +# { +# "tag_map": { +# "Brief Report": [], +# "Full Tutorial": ["tutorial"], +# "Include Postprocessing": ["tutorial", "postprocessing"] +# }, +# "css_map": { +# "tutorial": "background: lightblue;", +# "postprocessing": "background: lightblue;" +# } +# } # # TITLE # diff --git a/pyproject.toml b/pyproject.toml index 4fa08559..5a79d73b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ keywords = ["differential privacy"] dynamic = ["version", "description"] dependencies = [ - "dp-wizard-templates==0.8.2", + "dp-wizard-templates==0.9.0", "faicons", "fonttools>=4.60.2", "matplotlib", @@ -85,7 +85,7 @@ pins = [ "decorator==5.2.1", "defusedxml==0.7.1", "deprecated==1.2.18", - "dp-wizard-templates==0.8.2", + "dp-wizard-templates==0.9.0", "exceptiongroup==1.3.0", "executing==2.2.0", "faicons==0.2.2", diff --git a/requirements-dev.txt b/requirements-dev.txt index 5af5b5e9..00b9bcf4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -35,7 +35,9 @@ black==25.1.0 # -r requirements-dev.in # dp-wizard-templates bleach[css]==6.2.0 - # via nbconvert + # via + # bleach + # nbconvert build==1.2.2.post1 # via pip-tools certifi==2025.1.31 @@ -59,7 +61,9 @@ comm==0.2.2 contourpy==1.3.2 # via matplotlib coverage[toml]==7.8.0 - # via pytest-cov + # via + # coverage + # pytest-cov cycler==0.12.1 # via matplotlib debugpy==1.8.14 @@ -76,7 +80,7 @@ distlib==0.3.9 # via virtualenv docutils==0.21.2 # via flit -dp-wizard-templates==0.8.2 +dp-wizard-templates==0.9.0 # via -r .../dp-wizard/requirements.in exceptiongroup==1.3.0 # via @@ -243,7 +247,9 @@ numpy==2.2.4 # scikit-learn # scipy opendp[mbi]==0.14.1 - # via -r .../dp-wizard/requirements.in + # via + # -r .../dp-wizard/requirements.in + # opendp opt-einsum==3.4.0 # via jax optax==0.2.5 diff --git a/requirements.in b/requirements.in index 7d18502e..dbda6b56 100644 --- a/requirements.in +++ b/requirements.in @@ -4,7 +4,7 @@ opendp[mbi]==0.14.1 # Templating and notebook generation: -dp-wizard-templates==0.8.2 +dp-wizard-templates==0.9.0 # Shiny: shiny diff --git a/requirements.txt b/requirements.txt index 714e364a..1103b68b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,9 @@ beautifulsoup4==4.13.4 black==25.1.0 # via dp-wizard-templates bleach[css]==6.2.0 - # via nbconvert + # via + # bleach + # nbconvert certifi==2025.4.26 # via requests charset-normalizer==3.4.2 @@ -58,7 +60,7 @@ defusedxml==0.7.1 # via nbconvert deprecated==1.2.18 # via opendp -dp-wizard-templates==0.8.2 +dp-wizard-templates==0.9.0 # via -r requirements.in exceptiongroup==1.3.0 # via @@ -191,7 +193,9 @@ numpy==2.2.4 # scikit-learn # scipy opendp[mbi]==0.14.1 - # via -r requirements.in + # via + # -r requirements.in + # opendp opt-einsum==3.4.0 # via jax optax==0.2.5 From 854ec9bd21593a7b8e4290ecb9ffcceee5322759 Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Thu, 5 Mar 2026 13:17:22 -0500 Subject: [PATCH 2/4] clean ipynb --- dp_wizard/shiny/panels/results_panel/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dp_wizard/shiny/panels/results_panel/__init__.py b/dp_wizard/shiny/panels/results_panel/__init__.py index 0af0d4a4..dc0c3983 100644 --- a/dp_wizard/shiny/panels/results_panel/__init__.py +++ b/dp_wizard/shiny/panels/results_panel/__init__.py @@ -1,11 +1,14 @@ import html -import json import re from pathlib import Path from shutil import make_archive from tempfile import TemporaryDirectory -from dp_wizard_templates.converters import convert_from_notebook, convert_to_notebook +from dp_wizard_templates.converters import ( + clean_notebook, + convert_from_notebook, + convert_to_notebook, +) from shiny import Inputs, Outputs, Session, reactive, render, types, ui from dp_wizard import config_root @@ -384,11 +387,11 @@ def notebook_dict_unexecuted(): @reactive.calc def notebook_json(): - return json.dumps(notebook_dict()) + return clean_notebook(notebook_dict()) @reactive.calc def notebook_json_unexecuted(): - return json.dumps(notebook_dict_unexecuted()) + return clean_notebook(notebook_dict_unexecuted()) @reactive.calc def notebook_html(): From 4e516c1e303916184b66bdd60d66cb44f5838c85 Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Thu, 5 Mar 2026 13:31:40 -0500 Subject: [PATCH 3/4] combine two fill_blocks calls --- dp_wizard/utils/code_generators/abstract_generator.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dp_wizard/utils/code_generators/abstract_generator.py b/dp_wizard/utils/code_generators/abstract_generator.py index d4049ee1..1909f2c7 100644 --- a/dp_wizard/utils/code_generators/abstract_generator.py +++ b/dp_wizard/utils/code_generators/abstract_generator.py @@ -90,9 +90,7 @@ def imports_template(): .fill_blocks( IMPORTS_BLOCK=DefaultsTemplate(imports_template).finish(), UTILS_BLOCK=bins_py + plots_py, - **self._make_extra_blocks(), # type: ignore - ) - .fill_blocks( + CUSTOM_NOTE=self.note, WINDOWS_COMMENT_BLOCK=""" (If installing in the Windows CMD shell, use double-quotes instead of single-quotes below.)""", @@ -109,7 +107,7 @@ def imports_template(): so it is safer to ignore them. That said, if a significant number of records are ignored because of errors, it will bias results. """, - CUSTOM_NOTE=self.note, + **self._make_extra_blocks(), # type: ignore ) .finish(reformat=reformat) ) From 5d733e77e8c63f7a136725e31000641b8249dd67 Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Thu, 5 Mar 2026 13:39:38 -0500 Subject: [PATCH 4/4] move frontmatter into json --- .../utils/code_generators/abstract_generator.py | 17 +++++++++++++++++ .../code_generators/no-tests/_stats_notebook.py | 12 +----------- .../code_generators/no-tests/_synth_notebook.py | 12 +----------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/dp_wizard/utils/code_generators/abstract_generator.py b/dp_wizard/utils/code_generators/abstract_generator.py index 1909f2c7..8e3a950f 100644 --- a/dp_wizard/utils/code_generators/abstract_generator.py +++ b/dp_wizard/utils/code_generators/abstract_generator.py @@ -1,3 +1,4 @@ +import json from abc import ABC, abstractmethod from math import gcd from typing import Iterable @@ -109,6 +110,22 @@ def imports_template(): """, **self._make_extra_blocks(), # type: ignore ) + .fill_blocks( + FRONTMATTER_BLOCK=json.dumps( + { + "tag_map": { + "Brief Report": [], + "Full Tutorial": ["tutorial"], + "Include Postprocessing": ["tutorial", "postprocessing"], + }, + "css_map": { + "tutorial": "background: lightblue;", + "postprocessing": "background: lightblue;", + }, + } + ), + optional=True, # Not used by script template + ) .finish(reformat=reformat) ) return self._clean_up_py(code) diff --git a/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py b/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py index c37be3e0..05fd5dd1 100644 --- a/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py +++ b/dp_wizard/utils/code_generators/no-tests/_stats_notebook.py @@ -1,14 +1,4 @@ -# { -# "tag_map": { -# "Brief Report": [], -# "Full Tutorial": ["tutorial"], -# "Include Postprocessing": ["tutorial", "postprocessing"] -# }, -# "css_map": { -# "tutorial": "background: lightblue;", -# "postprocessing": "background: lightblue;" -# } -# } +# FRONTMATTER_BLOCK # # TITLE # diff --git a/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py b/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py index e91df4e7..f7d8b298 100644 --- a/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py +++ b/dp_wizard/utils/code_generators/no-tests/_synth_notebook.py @@ -1,14 +1,4 @@ -# { -# "tag_map": { -# "Brief Report": [], -# "Full Tutorial": ["tutorial"], -# "Include Postprocessing": ["tutorial", "postprocessing"] -# }, -# "css_map": { -# "tutorial": "background: lightblue;", -# "postprocessing": "background: lightblue;" -# } -# } +# FRONTMATTER_BLOCK # # TITLE #