From 24e229ffd563801d9120d84948be9d06129f6300 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jun 2022 14:51:06 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nbconvert/exporters/qt_exporter.py | 20 +++++++++---------- nbconvert/exporters/qt_screenshot.py | 9 +++++---- nbconvert/exporters/qtpdf.py | 3 ++- nbconvert/exporters/qtpng.py | 1 + nbconvert/exporters/tests/test_qtpdf.py | 1 + nbconvert/exporters/tests/test_qtpng.py | 1 + .../nbconvert/templates/qtpdf/conf.json | 8 ++++---- .../nbconvert/templates/qtpng/conf.json | 8 ++++---- 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/nbconvert/exporters/qt_exporter.py b/nbconvert/exporters/qt_exporter.py index 99492054e..371e05cba 100644 --- a/nbconvert/exporters/qt_exporter.py +++ b/nbconvert/exporters/qt_exporter.py @@ -14,15 +14,15 @@ def __init__(self, *args, **kwargs): self.format = self.output_mimetype.split("/")[-1] super().__init__(*args, **kwargs) - @default('file_extension') + @default("file_extension") def _file_extension_default(self): return "." + self.format - @default('template_name') + @default("template_name") def _template_name_default(self): return "qt" + self.format - @default('template_data_paths') + @default("template_data_paths") def _template_data_paths_default(self): return jupyter_path("nbconvert", "templates", "qt" + self.format) @@ -31,8 +31,10 @@ def _check_launch_reqs(self): from PyQt5.QtWidgets import QApplication from .qt_screenshot import QtScreenshot except ModuleNotFoundError as e: - raise RuntimeError(f"PyQtWebEngine is not installed to support Qt {self.format.upper()} conversion. " - f"Please install `nbconvert[qt{self.format}]` to enable.") from e + raise RuntimeError( + f"PyQtWebEngine is not installed to support Qt {self.format.upper()} conversion. " + f"Please install `nbconvert[qt{self.format}]` to enable." + ) from e return QApplication, QtScreenshot def run_pyqtwebengine(self, html): @@ -42,7 +44,7 @@ def run_pyqtwebengine(self, html): temp_file = tempfile.NamedTemporaryFile(suffix=ext, delete=False) filename = f"{temp_file.name[:-len(ext)]}.{self.format}" with temp_file: - temp_file.write(html.encode('utf-8')) + temp_file.write(html.encode("utf-8")) try: QApplication, QtScreenshot = self._check_launch_reqs() @@ -61,9 +63,7 @@ def run_pyqtwebengine(self, html): def from_notebook_node(self, nb, resources=None, **kw): self._check_launch_reqs() - html, resources = super().from_notebook_node( - nb, resources=resources, **kw - ) + html, resources = super().from_notebook_node(nb, resources=resources, **kw) self.log.info(f"Building {self.format.upper()}") data = self.run_pyqtwebengine(html) @@ -71,6 +71,6 @@ def from_notebook_node(self, nb, resources=None, **kw): # convert output extension # the writer above required it to be html - resources['output_extension'] = f".{self.format}" + resources["output_extension"] = f".{self.format}" return data, resources diff --git a/nbconvert/exporters/qt_screenshot.py b/nbconvert/exporters/qt_screenshot.py index 2b3f14cb0..de068547d 100644 --- a/nbconvert/exporters/qt_screenshot.py +++ b/nbconvert/exporters/qt_screenshot.py @@ -5,7 +5,6 @@ class QtScreenshot(QWebEngineView): - def __init__(self, app): super().__init__() self.app = app @@ -17,8 +16,7 @@ def capture(self, url, output_file, paginate): self.loadFinished.connect(self.on_loaded) # Create hidden view without scrollbars self.setAttribute(QtCore.Qt.WA_DontShowOnScreen) - self.page().settings().setAttribute( - QWebEngineSettings.ShowScrollBars, False) + self.page().settings().setAttribute(QWebEngineSettings.ShowScrollBars, False) if output_file.endswith(".pdf"): self.export = self.export_pdf self.page().pdfPrintingFinished.connect(lambda *args: self.app.exit()) @@ -41,7 +39,10 @@ def export_pdf(self): page_layout = QPageLayout(page_size, QPageLayout.Portrait, QtCore.QMarginsF()) else: factor = 0.75 - page_size = QPageSize(QtCore.QSizeF(self.size.width() * factor, self.size.height() * factor), QPageSize.Point) + page_size = QPageSize( + QtCore.QSizeF(self.size.width() * factor, self.size.height() * factor), + QPageSize.Point, + ) page_layout = QPageLayout(page_size, QPageLayout.Portrait, QtCore.QMarginsF()) self.page().printToPdf(self.output_file, pageLayout=page_layout) diff --git a/nbconvert/exporters/qtpdf.py b/nbconvert/exporters/qtpdf.py index 6a974cf89..0c2b8bfe9 100644 --- a/nbconvert/exporters/qtpdf.py +++ b/nbconvert/exporters/qtpdf.py @@ -14,6 +14,7 @@ class QtPDFExporter(QtExporter): This inherits from :class:`HTMLExporter`. It creates the HTML using the template machinery, and then uses pyqtwebengine to create a pdf. """ + export_from_notebook = "PDF via HTML" paginate = Bool( @@ -24,7 +25,7 @@ class QtPDFExporter(QtExporter): If False, a PDF with one long page will be generated. Set to True to match behavior of LaTeX based PDF generator - """ + """, ).tag(config=True) output_mimetype = "application/pdf" diff --git a/nbconvert/exporters/qtpng.py b/nbconvert/exporters/qtpng.py index 45e99cfd1..20b90b6da 100644 --- a/nbconvert/exporters/qtpng.py +++ b/nbconvert/exporters/qtpng.py @@ -12,6 +12,7 @@ class QtPNGExporter(QtExporter): This inherits from :class:`HTMLExporter`. It creates the HTML using the template machinery, and then uses pyqtwebengine to create a png. """ + export_from_notebook = "PNG via HTML" output_mimetype = "image/png" diff --git a/nbconvert/exporters/tests/test_qtpdf.py b/nbconvert/exporters/tests/test_qtpdf.py index 73c054490..f77b26464 100644 --- a/nbconvert/exporters/tests/test_qtpdf.py +++ b/nbconvert/exporters/tests/test_qtpdf.py @@ -6,6 +6,7 @@ from .base import ExportersTestsBase from ..qtpdf import QtPDFExporter + class TestQtPDFExporter(ExportersTestsBase): """Contains test functions for qtpdf.py""" diff --git a/nbconvert/exporters/tests/test_qtpng.py b/nbconvert/exporters/tests/test_qtpng.py index 2f515aa0c..ebd25efff 100644 --- a/nbconvert/exporters/tests/test_qtpng.py +++ b/nbconvert/exporters/tests/test_qtpng.py @@ -6,6 +6,7 @@ from .base import ExportersTestsBase from ..qtpng import QtPNGExporter + class TestQtPNGExporter(ExportersTestsBase): """Contains test functions for qtpng.py""" diff --git a/share/jupyter/nbconvert/templates/qtpdf/conf.json b/share/jupyter/nbconvert/templates/qtpdf/conf.json index 1a56f396b..66e95837a 100644 --- a/share/jupyter/nbconvert/templates/qtpdf/conf.json +++ b/share/jupyter/nbconvert/templates/qtpdf/conf.json @@ -1,6 +1,6 @@ { - "base_template": "lab", - "mimetypes": { - "application/pdf": true - } + "base_template": "lab", + "mimetypes": { + "application/pdf": true + } } diff --git a/share/jupyter/nbconvert/templates/qtpng/conf.json b/share/jupyter/nbconvert/templates/qtpng/conf.json index e0bfd6058..b3ae45a9e 100644 --- a/share/jupyter/nbconvert/templates/qtpng/conf.json +++ b/share/jupyter/nbconvert/templates/qtpng/conf.json @@ -1,6 +1,6 @@ { - "base_template": "lab", - "mimetypes": { - "image/png": true - } + "base_template": "lab", + "mimetypes": { + "image/png": true + } }