Skip to content

Commit 698ca72

Browse files
committed
add an option to rebuild screenshots
1 parent 303fff9 commit 698ca72

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"restructuredtext.confPath": "${workspaceFolder}/docs"
3+
}
2.7 KB
Loading

docs/conf.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import subprocess as spr
2020

21+
# note: we need to import pyplot here, because otherwise it might fail to load
22+
# the ipython extension
23+
import matplotlib.pyplot as plt
24+
2125
from docutils import nodes
2226
from docutils.statemachine import StringList
2327
from docutils.parsers.rst import directives
@@ -37,7 +41,7 @@
3741
author = 'Philipp S. Sommer'
3842

3943

40-
version = re.match('\d+\.\d+\.\d+', psy_view.__version__).group()
44+
version = re.match(r'\d+\.\d+\.\d+', psy_view.__version__).group() # type: ignore
4145
# The full version, including alpha/beta/rc tags.
4246
release = psy_view.__version__
4347

@@ -60,6 +64,8 @@
6064
'sphinx.ext.todo',
6165
]
6266

67+
rebuild_screenshots = False
68+
6369
todo_include_todos = True
6470

6571
# Add any paths that contain templates here, relative to this directory.
@@ -114,7 +120,7 @@
114120

115121
latex_elements = {
116122
# Additional stuff for the LaTeX preamble.
117-
'preamble': '\setcounter{tocdepth}{10}'
123+
'preamble': r'\setcounter{tocdepth}{10}'
118124
}
119125

120126
master_doc = 'index'
@@ -159,9 +165,10 @@
159165
def create_screenshot(
160166
code: str, output: str, make_plot: bool = False, enable: bool = None,
161167
plotmethod: str = "mapplot", minwidth=None,
168+
generate=rebuild_screenshots,
162169
) -> str:
163170
"""Generate a screenshot of the GUI."""
164-
from PyQt5.QtWidgets import QApplication, QSizePolicy
171+
from PyQt5.QtWidgets import QApplication, QSizePolicy # pylint: disable=no-name-in-module
165172
from psy_view.ds_widget import DatasetWidget
166173
from psyplot.data import open_dataset
167174

@@ -173,6 +180,9 @@ def create_screenshot(
173180
if app is None:
174181
app = QApplication([])
175182

183+
if not generate and osp.exists(output):
184+
return output
185+
176186
ds_widget = DatasetWidget(open_dataset(osp.join(confdir, "demo.nc")))
177187
ds_widget.plotmethod = plotmethod
178188

@@ -221,6 +231,7 @@ class ScreenshotDirective(SphinxDirective):
221231
option_spec["enable"] = directives.flag
222232
option_spec["plotmethod"] = plotmethod
223233
option_spec["minwidth"] = directives.positive_int
234+
option_spec["generate"] = directives.flag
224235

225236
target_directive = "image"
226237

@@ -244,17 +255,21 @@ def generate(self) -> None:
244255

245256
def run(self):
246257
"""Run the directive."""
247-
reporter = self.state.document.reporter
248-
249258
self.result = StringList()
250259

251260
make_plot = self.options.pop("plot", False) is None
252261
enable = True if self.options.pop("enable", False) is None else None
253262

263+
rebuild_screenshot = (
264+
self.options.pop("generate", False) or
265+
self.env.app.config.rebuild_screenshots
266+
)
267+
254268
self.img_name = create_screenshot(
255269
*self.arguments, make_plot=make_plot, enable=enable,
256270
plotmethod=self.options.pop("plotmethod", None) or "mapplot",
257271
minwidth=self.options.pop("minwidth", None),
272+
generate=rebuild_screenshot,
258273
)
259274

260275
self.generate()
@@ -296,3 +311,4 @@ def generate(self):
296311
def setup(app):
297312
app.add_directive('screenshot', ScreenshotDirective)
298313
app.add_directive("screenshot-figure", ScreenshotFigureDirective)
314+
app.add_config_value('rebuild_screenshots', rebuild_screenshots, 'env')

0 commit comments

Comments
 (0)