Skip to content

Commit 45518d7

Browse files
committed
use custom directivy
1 parent 48fe3d6 commit 45518d7

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

README.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88

99
*Adaptive*: parallel active learning of mathematical functions.
1010

11-
.. raw:: html
12-
13-
<video autoplay loop muted style="width: 400px; max-width: 100%; margin: 0 auto; display:block;">
14-
<source src="_static/logo_docs.mp4" type="video/mp4">
15-
</video>
16-
<br>
11+
.. animated-logo::
1712

1813
``adaptive`` is an open-source Python library designed to
1914
make adaptive parallel function evaluation simple. With ``adaptive`` you

docs/Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ help:
1717
source/_static/logo_docs.png: logo.py
1818
python logo.py
1919

20-
source/_static/logo_docs.mp4: logo_animated.py
21-
python logo_animated.py
22-
2320
# Fake target to avoid the catch-all target
2421
logo.py:
2522
@echo "never executed"
2623

27-
logo_animated.py:
28-
@echo "never executed"
29-
3024
# Catch-all target: route all unknown targets to Sphinx using the new
3125
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
32-
%: Makefile source/_static/logo_docs.png source/_static/logo_docs.mp4
26+
%: Makefile source/_static/logo_docs.png
3327
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/logo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ def add_rounded_corners(fname, rad):
5252
return im
5353

5454

55-
if __name__ == "__main__":
55+
def main(fname="source/_static/logo_docs.png"):
5656
learner = create_and_run_learner()
57-
fname = "source/_static/logo_docs.png"
5857
plot_learner_and_save(learner, fname)
5958
im = add_rounded_corners(fname, rad=200)
6059
im.thumbnail((200, 200), Image.ANTIALIAS) # resize
6160
im.save(fname)
61+
62+
63+
if __name__ == "__main__":
64+
main()

docs/logo_animated.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def ring(xy):
7070
return learner
7171

7272

73-
if __name__ == "__main__":
73+
def main(fname="source/_static/logo_docs.mp4"):
7474
learner = create_and_run_learner()
7575

7676
data = list(learner.data.items())
@@ -92,4 +92,8 @@ def ring(xy):
9292
]
9393

9494
ani = animation.ArtistAnimation(fig, artists, blit=True)
95-
ani.save("source/_static/logo_docs.mp4", writer=FFMpegWriter(fps=24))
95+
ani.save(fname, writer=FFMpegWriter(fps=24))
96+
97+
98+
if __name__ == "__main__":
99+
main()

docs/source/conf.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
import os
1515
import sys
1616

17+
from docutils import nodes
18+
from docutils.parsers.rst import Directive
19+
1720
package_path = os.path.abspath("../..")
1821
# Insert into sys.path so that we can import adaptive here
1922
sys.path.insert(0, package_path)
2023
# Insert into PYTHONPATH so that jupyter-sphinx will pick it up
2124
os.environ["PYTHONPATH"] = ":".join((package_path, os.environ.get("PYTHONPATH", "")))
25+
# Insert `docs/` such that we can run the logo scripts
26+
docs_path = os.path.abspath("..")
27+
sys.path.insert(1, docs_path)
2228

2329
import adaptive # noqa: E402, isort:skip
2430

@@ -154,5 +160,20 @@
154160
html_logo = "logo_docs.png"
155161

156162

163+
class RunLogoAnimated(Directive):
164+
def run(self):
165+
fname = "_static/logo_docs.mp4"
166+
if not os.path.exists(fname):
167+
import logo_animated
168+
169+
print(f"{fname} does not exist.")
170+
logo_animated.main(fname)
171+
style = "width: 400px; max-width: 100%; margin: 0 auto; display:block;"
172+
opts = f'autoplay loop muted style="{style}"'
173+
html = f"""<video {opts}><source src="{fname}" type="video/mp4"></video><br>"""
174+
return [nodes.raw(text=html, format="html")]
175+
176+
157177
def setup(app):
158178
app.add_css_file("custom.css") # For the `live_info` widget
179+
app.add_directive("animated-logo", RunLogoAnimated)

0 commit comments

Comments
 (0)