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(): diff --git a/dp_wizard/utils/code_generators/abstract_generator.py b/dp_wizard/utils/code_generators/abstract_generator.py index 6ee807d0..d5b08690 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 @@ -89,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.)""", @@ -108,7 +107,23 @@ 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 + ) + .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) ) 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..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,8 +1,4 @@ -# {"tagmap":{ -# "Brief Report": [], -# "Full Tutorial": ["tutorial"], -# "Include Postprocessing": ["tutorial", "postprocessing"] -# }} +# 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 11496b67..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,8 +1,4 @@ -# {"tagmap":{ -# "Brief Report": [], -# "Full Tutorial": ["tutorial"], -# "Include Postprocessing": ["tutorial", "postprocessing"] -# }} +# FRONTMATTER_BLOCK # # TITLE # diff --git a/pyproject.toml b/pyproject.toml index 28296413..5a53536a 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", "matplotlib", "opendp[mbi]==0.14.1", @@ -77,7 +77,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 88e077b6..df26bcd6 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 86331d97..831ac2e9 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 d19d058d..49703164 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,13 @@ 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 + # via requests chex==0.1.90 # via # mbi @@ -54,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 @@ -183,7 +189,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