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.
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/PKG-INFO +1 -1
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/setup.cfg +1 -1
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib/screenshot.py +23 -5
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/PKG-INFO +1 -1
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/LICENSE +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/README.md +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/setup.py +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/SOURCES.txt +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/dependency_links.txt +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/requires.txt +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/top_level.txt +0 -0
- {sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/tests/test_it.py +0 -0
{sphinxcontrib-screenshot-0.0.3 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib/screenshot.py
RENAMED
|
@@ -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 =
|
|
34
|
-
browser =
|
|
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
|
-
|
|
156
|
-
|
|
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':
|
|
182
|
+
'version': __version__,
|
|
165
183
|
'parallel_read_safe': True,
|
|
166
184
|
'parallel_write_safe': True,
|
|
167
185
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|