sphinxcontrib-screenshot 0.0.2__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.2 → sphinxcontrib-screenshot-0.0.4}/PKG-INFO +1 -1
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/setup.cfg +1 -1
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib/screenshot.py +42 -18
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/PKG-INFO +1 -1
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/LICENSE +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/README.md +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/setup.py +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/SOURCES.txt +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/dependency_links.txt +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/requires.txt +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib_screenshot.egg-info/top_level.txt +0 -0
- {sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/tests/test_it.py +0 -0
{sphinxcontrib-screenshot-0.0.2 → sphinxcontrib-screenshot-0.0.4}/sphinxcontrib/screenshot.py
RENAMED
|
@@ -19,6 +19,8 @@ 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
|
|
23
|
+
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
|
|
22
24
|
from playwright.sync_api import sync_playwright
|
|
23
25
|
from sphinx.application import Sphinx
|
|
24
26
|
from sphinx.util.docutils import SphinxDirective
|
|
@@ -29,8 +31,10 @@ Meta = typing.TypedDict('Meta', {
|
|
|
29
31
|
'parallel_write_safe': bool
|
|
30
32
|
})
|
|
31
33
|
|
|
32
|
-
p =
|
|
33
|
-
browser =
|
|
34
|
+
p: typing.Optional[Playwright] = None
|
|
35
|
+
browser: typing.Optional[Browser] = None
|
|
36
|
+
|
|
37
|
+
__version__ = '0.0.4'
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
class ScreenshotDirective(SphinxDirective):
|
|
@@ -107,23 +111,31 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
107
111
|
filename = hashlib.md5(hash_input.encode()).hexdigest() + '.png'
|
|
108
112
|
filepath = os.path.join(ss_dirpath, filename)
|
|
109
113
|
|
|
114
|
+
if not browser:
|
|
115
|
+
raise RuntimeError('Browser has not been initiated.')
|
|
116
|
+
|
|
110
117
|
# Check if the file already exists. If not, take a screenshot
|
|
111
118
|
if not os.path.exists(filepath):
|
|
112
119
|
page = browser.new_page()
|
|
120
|
+
page.set_default_timeout(10000)
|
|
113
121
|
page.set_viewport_size({'width': width, 'height': height})
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
try:
|
|
123
|
+
if screenshot_init_script:
|
|
124
|
+
page.add_init_script(screenshot_init_script)
|
|
125
|
+
if url_or_path.startswith(('http://', 'https://')):
|
|
126
|
+
page.goto(url_or_path)
|
|
127
|
+
elif os.path.isabs(url_or_path):
|
|
128
|
+
page.goto('file://' + url_or_path)
|
|
129
|
+
else:
|
|
130
|
+
page.goto('file://' + str(self.env.srcdir.joinpath(url_or_path)))
|
|
131
|
+
page.wait_for_load_state('networkidle')
|
|
132
|
+
|
|
133
|
+
# Execute interactions
|
|
134
|
+
if interactions:
|
|
135
|
+
exec(interactions)
|
|
136
|
+
except PlaywrightTimeoutError:
|
|
137
|
+
raise RuntimeError('Timeout error occured at %s in executing\n%s' %
|
|
138
|
+
(url_or_path, interactions))
|
|
127
139
|
|
|
128
140
|
page.screenshot(path=filepath)
|
|
129
141
|
page.close()
|
|
@@ -145,17 +157,29 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
145
157
|
return [figure_node]
|
|
146
158
|
|
|
147
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
|
+
|
|
148
167
|
def on_build_finished(app: Sphinx, exception: Exception):
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
global p
|
|
169
|
+
global browser
|
|
170
|
+
if browser:
|
|
171
|
+
browser.close()
|
|
172
|
+
if p:
|
|
173
|
+
p.stop()
|
|
151
174
|
|
|
152
175
|
|
|
153
176
|
def setup(app: Sphinx) -> Meta:
|
|
154
177
|
app.add_directive('screenshot', ScreenshotDirective)
|
|
155
178
|
app.connect('build-finished', on_build_finished)
|
|
179
|
+
app.connect('builder-inited', on_builder_inited)
|
|
156
180
|
app.add_config_value('screenshot_init_script', '', 'env')
|
|
157
181
|
return {
|
|
158
|
-
'version':
|
|
182
|
+
'version': __version__,
|
|
159
183
|
'parallel_read_safe': True,
|
|
160
184
|
'parallel_write_safe': True,
|
|
161
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
|