A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Require playwright installation for pdf export (#8121)
Shahmir Varqhae7c580b1bb76
diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.pyindex 3dd32f2622..8fb7a11077 100644--- a/marimo/_server/export/exporter.py+++ b/marimo/_server/export/exporter.py@@ -319,16 +319,21 @@ class Exporter:app: The app to exportsession_view: The session view to export. If None, outputs are not included.webpdf: If False, tries standard PDF export (pandoc + TeX) first,- falling back to webpdf if deps are not installed. If True, uses webpdf+ falling back to webpdf on failure. If True, uses webpdfdirectly.Returns:PDF data"""+ # We check for all dependencies upfront since standard export failing+ # falls back to webpdf (which requires playwright).+ # We don't want users to reinstall again after the first failure.+ # Webpdf is generally more resilient to errors than standard export.DependencyManager.require_many("for PDF export",DependencyManager.nbformat,DependencyManager.nbconvert,+ DependencyManager.playwright,)ipynb_json_str = self.export_as_ipynb(@@ -359,7 +364,6 @@ class Exporter:e,)- DependencyManager.playwright.require("for webpdf export")from nbconvert import WebPDFExporter # type: ignore[import-not-found]web_exporter = WebPDFExporter()diff --git a/tests/_server/export/test_exporter.py b/tests/_server/export/test_exporter.pyindex 6b59fdc632..36f66c5c83 100644--- a/tests/_server/export/test_exporter.py+++ b/tests/_server/export/test_exporter.py@@ -908,47 +908,9 @@ class TestPDFExport:@pytest.mark.skipif(not DependencyManager.nbformat.has()- or not DependencyManager.nbconvert.has(),- reason="nbformat or nbconvert not installed",- )- def test_export_as_pdf_webpdf_requires_playwright(- self,- session_view: SessionView,- ) -> None:- """Test that webpdf mode requires playwright dependency."""-- app = App()-- @app.cell()- def test_cell():- return "test"-- file_manager = AppFileManager.from_app(InternalApp(app))- exporter = Exporter()-- # Simulate nbformat and nbconvert available, but playwright missing- def mock_has(self: Dependency, quiet: bool = False) -> bool:- del quiet- if self.pkg == "playwright":- return False- if self.pkg in ("nbformat", "nbconvert"):- return True- return False-- with patch.object(Dependency, "has", mock_has):- with pytest.raises(ModuleNotFoundError) as excinfo:- exporter.export_as_pdf(- app=file_manager.app,- session_view=session_view,- webpdf=True,- )-- assert "playwright" in str(excinfo.value)-- @pytest.mark.skipif(- not DependencyManager.nbformat.has()- or not DependencyManager.nbconvert.has(),- reason="nbformat or nbconvert not installed",+ or not DependencyManager.nbconvert.has()+ or not DependencyManager.playwright.has(),+ reason="nbformat or nbconvert or playwright not installed",)def test_export_as_pdf_non_webpdf_mode(self,