sphinxcontrib-screenshot 0.1.2__tar.gz → 0.1.3__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.1.2 → sphinxcontrib_screenshot-0.1.3}/PKG-INFO +1 -1
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib/screenshot.py +25 -3
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib_screenshot.egg-info/PKG-INFO +1 -1
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/tests/test_it.py +15 -2
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/LICENSE +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/README.md +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/setup.cfg +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/setup.py +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib_screenshot.egg-info/SOURCES.txt +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib_screenshot.egg-info/dependency_links.txt +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib_screenshot.egg-info/requires.txt +0 -0
- {sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib_screenshot.egg-info/top_level.txt +0 -0
{sphinxcontrib_screenshot-0.1.2 → sphinxcontrib_screenshot-0.1.3}/sphinxcontrib/screenshot.py
RENAMED
|
@@ -32,7 +32,7 @@ Meta = typing.TypedDict('Meta', {
|
|
|
32
32
|
'parallel_write_safe': bool
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
-
__version__ = '0.1.
|
|
35
|
+
__version__ = '0.1.3'
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class ScreenshotDirective(SphinxDirective):
|
|
@@ -72,6 +72,21 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
72
72
|
|
|
73
73
|
document.querySelector('button').click();
|
|
74
74
|
```
|
|
75
|
+
|
|
76
|
+
Use `figclass` option if you want to specify a class name to the image.
|
|
77
|
+
|
|
78
|
+
```rst
|
|
79
|
+
.. screenshot:: http://www.example.com
|
|
80
|
+
:figclass: foo
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
It also generates a PDF file when `pdf` option is given, which might be
|
|
84
|
+
useful when you need scalable image assets.
|
|
85
|
+
|
|
86
|
+
```rst
|
|
87
|
+
.. screenshot:: http://www.example.com
|
|
88
|
+
:pdf:
|
|
89
|
+
```
|
|
75
90
|
"""
|
|
76
91
|
|
|
77
92
|
required_arguments = 1 # URL
|
|
@@ -81,12 +96,13 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
81
96
|
'width': directives.positive_int,
|
|
82
97
|
'caption': directives.unchanged,
|
|
83
98
|
'figclass': directives.unchanged,
|
|
99
|
+
'pdf': directives.flag,
|
|
84
100
|
}
|
|
85
101
|
pool = ThreadPoolExecutor()
|
|
86
102
|
|
|
87
103
|
@staticmethod
|
|
88
104
|
def take_screenshot(url: str, width: int, height: int, filepath: str,
|
|
89
|
-
init_script: str, interactions: str):
|
|
105
|
+
init_script: str, interactions: str, generate_pdf: bool):
|
|
90
106
|
"""Takes a screenshot with Playwright's Chromium browser.
|
|
91
107
|
|
|
92
108
|
Args:
|
|
@@ -99,6 +115,7 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
99
115
|
https://playwright.dev/python/docs/api/class-page#page-add-init-script
|
|
100
116
|
interactions (str): JavaScript code to run before taking the screenshot
|
|
101
117
|
after the page was loaded.
|
|
118
|
+
generate_pdf (bool): Generate a PDF file along with the screenshot.
|
|
102
119
|
"""
|
|
103
120
|
with sync_playwright() as playwright:
|
|
104
121
|
browser = playwright.chromium.launch()
|
|
@@ -119,6 +136,10 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
119
136
|
raise RuntimeError('Timeout error occured at %s in executing\n%s' %
|
|
120
137
|
(url, interactions))
|
|
121
138
|
page.screenshot(path=filepath)
|
|
139
|
+
if generate_pdf:
|
|
140
|
+
page.emulate_media(media='screen')
|
|
141
|
+
root, ext = os.path.splitext(filepath)
|
|
142
|
+
page.pdf(width=f'{width}px', height=f'{height}px', path=root + '.pdf')
|
|
122
143
|
page.close()
|
|
123
144
|
browser.close()
|
|
124
145
|
|
|
@@ -135,6 +156,7 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
135
156
|
width = self.options.get('width', 1280)
|
|
136
157
|
caption_text = self.options.get('caption', '')
|
|
137
158
|
figclass = self.options.get('figclass', '')
|
|
159
|
+
pdf = 'pdf' in self.options
|
|
138
160
|
interactions = '\n'.join(self.content)
|
|
139
161
|
|
|
140
162
|
if urlparse(url).scheme not in {'http', 'https'}:
|
|
@@ -150,7 +172,7 @@ class ScreenshotDirective(SphinxDirective):
|
|
|
150
172
|
if not os.path.exists(filepath):
|
|
151
173
|
fut = self.pool.submit(ScreenshotDirective.take_screenshot, url, width,
|
|
152
174
|
height, filepath, screenshot_init_script,
|
|
153
|
-
interactions)
|
|
175
|
+
interactions, pdf)
|
|
154
176
|
fut.result()
|
|
155
177
|
|
|
156
178
|
# Create image and figure nodes
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
+
import os
|
|
15
16
|
from io import StringIO
|
|
16
17
|
|
|
17
18
|
import pytest
|
|
@@ -29,7 +30,7 @@ def test_default(app: SphinxTestApp, status: StringIO,
|
|
|
29
30
|
|
|
30
31
|
# Every screenshot directive should become an image.
|
|
31
32
|
imgs = soup.find_all('img')
|
|
32
|
-
assert len(list(imgs)) ==
|
|
33
|
+
assert len(list(imgs)) == 5
|
|
33
34
|
|
|
34
35
|
# The image size should be set as specified.
|
|
35
36
|
img_obj = Image.open(app.outdir / imgs[0]['src'])
|
|
@@ -54,4 +55,16 @@ def test_default(app: SphinxTestApp, status: StringIO,
|
|
|
54
55
|
assert img_with_caption_a['src'] == img_with_caption_b['src']
|
|
55
56
|
|
|
56
57
|
# The figure node should have the class name specified.
|
|
57
|
-
assert 'round' in soup.find_all('figure')[
|
|
58
|
+
assert 'round' in soup.find_all('figure')[3]['class']
|
|
59
|
+
|
|
60
|
+
# Should generate a PDF file if specified.
|
|
61
|
+
img_with_pdf = imgs[4]['src']
|
|
62
|
+
root, ext = os.path.splitext(os.path.basename(img_with_pdf))
|
|
63
|
+
pdf_filepath = app.outdir / '_static' / 'screenshots' / f'{root}.pdf'
|
|
64
|
+
assert os.path.exists(pdf_filepath)
|
|
65
|
+
|
|
66
|
+
# Should not generate a PDF file if not specified.
|
|
67
|
+
img_without_pdf = imgs[2]['src']
|
|
68
|
+
root, ext = os.path.splitext(os.path.basename(img_without_pdf))
|
|
69
|
+
pdf_filepath = app.outdir / '_static' / 'screenshots' / f'{root}.pdf'
|
|
70
|
+
assert not os.path.exists(pdf_filepath)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|