sphinxcontrib-screenshot 0.0.3__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of sphinxcontrib-screenshot might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sphinxcontrib-screenshot
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: A Shpinx extension to embed webpage screenshots.
5
5
  Author: Shuhei Iitsuka
6
6
  Author-email: tushuhei@gmail.com
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = sphinxcontrib-screenshot
3
- version = 0.0.3
3
+ version = attr: sphinxcontrib.screenshot.__version__
4
4
  description = A Shpinx extension to embed webpage screenshots.
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
@@ -19,6 +19,7 @@ import typing
19
19
  from docutils import nodes
20
20
  from docutils.parsers.rst import directives
21
21
  from docutils.statemachine import ViewList
22
+ from playwright.sync_api import Browser, Playwright
22
23
  from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
23
24
  from playwright.sync_api import sync_playwright
24
25
  from sphinx.application import Sphinx
@@ -30,8 +31,10 @@ Meta = typing.TypedDict('Meta', {
30
31
  'parallel_write_safe': bool
31
32
  })
32
33
 
33
- p = sync_playwright().start()
34
- browser = p.chromium.launch()
34
+ p: typing.Optional[Playwright] = None
35
+ browser: typing.Optional[Browser] = None
36
+
37
+ __version__ = '0.0.4'
35
38
 
36
39
 
37
40
  class ScreenshotDirective(SphinxDirective):
@@ -108,6 +111,9 @@ class ScreenshotDirective(SphinxDirective):
108
111
  filename = hashlib.md5(hash_input.encode()).hexdigest() + '.png'
109
112
  filepath = os.path.join(ss_dirpath, filename)
110
113
 
114
+ if not browser:
115
+ raise RuntimeError('Browser has not been initiated.')
116
+
111
117
  # Check if the file already exists. If not, take a screenshot
112
118
  if not os.path.exists(filepath):
113
119
  page = browser.new_page()
@@ -151,17 +157,29 @@ class ScreenshotDirective(SphinxDirective):
151
157
  return [figure_node]
152
158
 
153
159
 
160
+ def on_builder_inited(app: Sphinx):
161
+ global p
162
+ global browser
163
+ p = sync_playwright().start()
164
+ browser = p.chromium.launch()
165
+
166
+
154
167
  def on_build_finished(app: Sphinx, exception: Exception):
155
- browser.close()
156
- p.stop()
168
+ global p
169
+ global browser
170
+ if browser:
171
+ browser.close()
172
+ if p:
173
+ p.stop()
157
174
 
158
175
 
159
176
  def setup(app: Sphinx) -> Meta:
160
177
  app.add_directive('screenshot', ScreenshotDirective)
161
178
  app.connect('build-finished', on_build_finished)
179
+ app.connect('builder-inited', on_builder_inited)
162
180
  app.add_config_value('screenshot_init_script', '', 'env')
163
181
  return {
164
- 'version': '0.0.3',
182
+ 'version': __version__,
165
183
  'parallel_read_safe': True,
166
184
  'parallel_write_safe': True,
167
185
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sphinxcontrib-screenshot
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: A Shpinx extension to embed webpage screenshots.
5
5
  Author: Shuhei Iitsuka
6
6
  Author-email: tushuhei@gmail.com