Skip to content

Commit c6b9166

Browse files
committed
Support installing VHS from different repos and building SVGs instead of GIFs
1 parent b595891 commit c6b9166

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
}
3030
autodoc_member_order = "bysource"
3131
nitpick_ignore_regex = [(r"py:class", r".*\.T")]
32+
vhs_repo = "agentstation/vhs"
33+
vhs_format = "svg"
3234

3335
# -- Options for HTML output -------------------------------------------------
3436
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

docs/source/index.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ Usage
115115
.. _figure: https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure
116116

117117

118+
Rendering SVGs
119+
--------------
120+
121+
There's a `fork of VHS`__ that supports rendering SVGs instead of GIFs. To set it up,
122+
add the following to your ``conf.py``:
123+
124+
__ https://github.com/agentstation/vhs/
125+
126+
.. code-block:: python
127+
128+
vhs_repo = "agentstation/vhs"
129+
vhs_format = "svg"
130+
131+
118132
Settings
119133
--------
120134

@@ -175,6 +189,16 @@ Sphinx-VHS adds the following settings to ``conf.py``:
175189
Number of parallel jobs that will be used to render tapes in Read The Docs runners.
176190
Default is ``8``.
177191

192+
.. py:data:: vhs_repo
193+
:type: str
194+
195+
Repo
196+
197+
.. py:data:: vhs_format
198+
:type: str
199+
200+
Format for rendering tapes, default is ``"gif"``.
201+
178202

179203
FAQ
180204
---

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ classifiers = [
2222
"Typing :: Typed",
2323
]
2424
dependencies = [
25-
"sphinx>=8.0,<9.0",
26-
"vhs>=1.0.0,<2.0",
25+
"sphinx>=8.0,<10.0",
26+
"vhs>=1.1.0,<2.0",
2727
]
2828

2929
[dependency-groups]

sphinx_vhs/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sphinx.errors
1818
import sphinx.util.parallel
1919
import vhs
20+
from docutils.parsers.rst import directives
2021
from docutils.parsers.rst.directives.images import Figure
2122
from sphinx.transforms import SphinxTransform
2223
from sphinx.util import logging
@@ -51,6 +52,11 @@ def _get_used_files(
5152

5253

5354
class VhsDirective(SphinxDirective, Figure):
55+
option_spec = {
56+
**Figure.option_spec, # type: ignore
57+
"format": lambda x: directives.choice(x, ["gif", "svg"]),
58+
}
59+
5460
def run(self):
5561
lines = self._get_tape_contents_inlined()
5662
tape = "\n".join(lines)
@@ -66,8 +72,9 @@ def run(self):
6672
)
6773
dest_dir.mkdir(parents=True, exist_ok=True)
6874
dest_tape = dest_dir / ("vhs.tape")
69-
dest_render = dest_dir / ("vhs.gif")
70-
dest_file = dest_dir / (filename + ".gif")
75+
format = self.options.get("format") or self.env.config["vhs_format"] or "gif"
76+
dest_render = dest_dir / (f"vhs.{format}")
77+
dest_file = dest_dir / (filename + f".{format}")
7178

7279
with dest_tape.open("w") as file:
7380
file.write(tape)
@@ -290,6 +297,7 @@ def generate_vhs(
290297
install=app.config["vhs_auto_install"],
291298
cache_path=app.config["vhs_auto_install_location"],
292299
env=environ,
300+
repo=app.config["vhs_repo"],
293301
)
294302
except vhs.VhsError as e:
295303
raise sphinx.errors.ExtensionError(str(e)) from e
@@ -401,6 +409,8 @@ def setup(app: sphinx.application.Sphinx):
401409
app.add_config_value(
402410
"vhs_cleanup_delay", timedelta(days=1), rebuild="env", types=timedelta
403411
)
412+
app.add_config_value("vhs_repo", "charmbracelet/vhs", rebuild="env")
413+
app.add_config_value("vhs_format", "gif", rebuild="env")
404414

405415
app.add_directive("vhs", VhsDirective)
406416
app.add_directive("vhs-inline", InlineVhsDirective)

0 commit comments

Comments
 (0)