Skip to content

Commit 838cd7f

Browse files
authored
Merge branch 'master' into newExamples
2 parents 5d26b66 + 1e39b37 commit 838cd7f

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Sphinx==3.1.2
22
guzzle-sphinx-theme
33
recommonmark>=0.5.0
4+
sphinx-copybutton

docs/source/_static/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ img {
2828
padding: 14px 0 14px 20px;
2929
margin: 20px 0;
3030
}
31+
32+
div.example-reference {
33+
background-color: #dff0d8;
34+
border: 1px solid #3c763d;
35+
}

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
extensions = [
5353
"sphinx.ext.autodoc",
5454
"recommonmark",
55+
"sphinx_copybutton",
5556
"sphinx.ext.napoleon",
5657
"sphinx.ext.autosummary",
5758
"sphinx.ext.doctest",

docs/source/examples/advanced_projects.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Advanced Projects
22
=================================
33

44
.. manim:: OpeningManim
5-
:quality: low
5+
:ref_classes: Tex MathTex NumberPlane
66

77
class OpeningManim(Scene):
88
def construct(self):
@@ -245,7 +245,7 @@ Advanced Projects
245245
.. manim:: SineCurvePlot
246246

247247
class SineCurvePlot(Scene):
248-
# contributed by heejin_park, https://infograph.tistory.com/230
248+
# contributed by heejin_park, https://infograph.tistory.com/230
249249
def construct(self):
250250
self.show_axis()
251251
self.show_circle()

docs/source/manim_directive.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def construct(self):
2121
render scenes that are defined within doctests, for example::
2222
2323
.. manim:: DirectiveDoctestExample
24+
:ref_classes: Dot
2425
2526
>>> dot = Dot(color=RED)
2627
>>> dot.color
@@ -58,19 +59,44 @@ def construct(self):
5859
an image representing the last frame of the scene will
5960
be rendered and displayed, instead of a video.
6061
62+
ref_classes
63+
A list of classes, separated by spaces, that is
64+
rendered in a reference block after the source code.
65+
66+
ref_functions
67+
A list of functions and methods, separated by spaces,
68+
that is rendered in a reference block after the source code.
69+
6170
"""
6271
from docutils.parsers.rst import directives, Directive
63-
from docutils.parsers.rst.directives.images import Image
6472

6573
import jinja2
6674
import os
6775
from os.path import relpath
76+
from typing import List
6877

6978
import shutil
7079

7180
classnamedict = {}
7281

7382

83+
def process_name_list(option_input: str, reference_type: str) -> List[str]:
84+
r"""Reformats a string of space separated class names
85+
as a list of strings containing valid Sphinx references.
86+
87+
TESTS
88+
-----
89+
90+
::
91+
92+
>>> process_name_list("Tex TexTemplate", "class")
93+
[":class:`~.Tex`", ":class:`~.TexTemplate`"]
94+
>>> process_name_list("Scene.play Mobject.rotate", "func")
95+
[":func:`~.Scene.play`", ":func:`~.Mobject.rotate`"]
96+
"""
97+
return [f":{reference_type}:`~.{name}`" for name in option_input.split()]
98+
99+
74100
class ManimDirective(Directive):
75101
r"""The manim directive, rendering videos while building
76102
the documentation.
@@ -87,6 +113,8 @@ class ManimDirective(Directive):
87113
),
88114
"save_as_gif": bool,
89115
"save_last_frame": bool,
116+
"ref_classes": lambda arg: process_name_list(arg, "class"),
117+
"ref_functions": lambda arg: process_name_list(arg, "func"),
90118
}
91119
final_argument_whitespace = True
92120

@@ -105,6 +133,17 @@ def run(self):
105133
save_as_gif = "save_as_gif" in self.options
106134
save_last_frame = "save_last_frame" in self.options
107135
assert not (save_as_gif and save_last_frame)
136+
if "ref_classes" in self.options or "ref_functions" in self.options:
137+
ref_classes = self.options.get("ref_classes", [])
138+
ref_functions = self.options.get("ref_functions", [])
139+
ref_content = ref_classes + ref_functions
140+
ref_block = f"""
141+
.. admonition:: Example References
142+
:class: example-reference
143+
144+
{' '.join(ref_content)}"""
145+
else:
146+
ref_block = ""
108147

109148
frame_rate = 30
110149
pixel_height = 480
@@ -218,6 +257,7 @@ def run(self):
218257
save_last_frame=save_last_frame,
219258
save_as_gif=save_as_gif,
220259
source_block=source_block,
260+
ref_block=ref_block,
221261
)
222262
state_machine.insert_input(
223263
rendered_template.split("\n"), source=document.attributes["source"]
@@ -245,6 +285,7 @@ def setup(app):
245285
<div class="manim-example">
246286
247287
{{ source_block }}
288+
{{ ref_block }}
248289
{% endif %}
249290
250291
{% if not (save_as_gif or save_last_frame) %}

manim/config/config_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,15 @@ def _init_dirs(config):
494494
def _from_command_line():
495495
"""Determine if manim was called from the command line."""
496496
# Manim can be called from the command line in three different
497-
# ways. The first two involve using the manim or manimcm commands.
497+
# ways. The first two involve using the manim or manimce commands.
498498
# Note that some Windows CLIs replace those commands with the path
499499
# to their executables, so we must check for this as well
500500
prog = os.path.split(sys.argv[0])[-1]
501-
from_cli_command = prog in ["manim", "manim.exe", "manimcm", "manimcm.exe"]
501+
from_cli_command = prog in ["manim", "manim.exe", "manimce", "manimce.exe"]
502502

503503
# The third way involves using `python -m manim ...`. In this
504504
# case, the CLI arguments passed to manim do not include 'manim',
505-
# 'manimcm', or even 'python'. However, the -m flag will always
505+
# 'manimce', or even 'python'. However, the -m flag will always
506506
# be the first argument.
507507
from_python_m = sys.argv[0] == "-m"
508508

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ markers = "slow: Mark the test as slow. Can be skipped with --skip_slow"
6060
[tool.poetry.plugins]
6161
[tool.poetry.plugins."console_scripts"]
6262
"manim" = "manim.__main__:main"
63-
"manimcm" = "manim.__main__:main"
63+
"manimce" = "manim.__main__:main"
6464

6565
[build-system]
6666
requires = ["poetry>=0.12"]

0 commit comments

Comments
 (0)