Skip to content

Commit b431559

Browse files
authored
Merge pull request #212 from Aathish04/cfg-subcommand
Implement a basic Subcommand structure.
2 parents d9c0734 + 05fb37b commit b431559

File tree

15 files changed

+574
-243
lines changed

15 files changed

+574
-243
lines changed

docs/source/conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20-
project = 'Manim'
21-
copyright = '2019, EulerTour'
22-
author = 'EulerTour'
20+
project = "Manim"
21+
copyright = "2019, EulerTour"
22+
author = "EulerTour"
2323

2424

2525
# -- General configuration ---------------------------------------------------
26-
master_doc = 'index'
26+
master_doc = "index"
2727

2828
# Add any Sphinx extension module names here, as strings. They can be
2929
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3030
# ones.
31-
extensions = [
32-
]
31+
extensions = []
3332

3433
# Add any paths that contain templates here, relative to this directory.
35-
templates_path = ['_templates']
34+
templates_path = ["_templates"]
3635

3736
# List of patterns, relative to source directory, that match files and
3837
# directories to ignore when looking for source files.
@@ -45,9 +44,9 @@
4544
# The theme to use for HTML and HTML Help pages. See the documentation for
4645
# a list of builtin themes.
4746
#
48-
html_theme = 'sphinx_rtd_theme'
47+
html_theme = "sphinx_rtd_theme"
4948

5049
# Add any paths that contain custom static files (such as style sheets) here,
5150
# relative to this directory. They are copied after the builtin static files,
5251
# so a file named "default.css" will overwrite the builtin "default.css".
53-
html_static_path = ['assets']
52+
html_static_path = ["assets"]

logo/logo.py

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
NEW_BLUE = "#68a8e1"
44

5+
56
class Thumbnail(GraphScene):
67
CONFIG = {
78
"y_max": 8,
@@ -13,13 +14,15 @@ def construct(self):
1314

1415
def show_function_graph(self):
1516
self.setup_axes(animate=False)
17+
1618
def func(x):
17-
return 0.1 * (x + 3-5) * (x - 3-5) * (x-5) + 5
19+
return 0.1 * (x + 3 - 5) * (x - 3 - 5) * (x - 5) + 5
1820

1921
def rect(x):
20-
return 2.775*(x-1.5)+3.862
21-
recta = self.get_graph(rect,x_min=-1,x_max=5)
22-
graph = self.get_graph(func,x_min=0.2,x_max=9)
22+
return 2.775 * (x - 1.5) + 3.862
23+
24+
recta = self.get_graph(rect, x_min=-1, x_max=5)
25+
graph = self.get_graph(func, x_min=0.2, x_max=9)
2326
graph.set_color(NEW_BLUE)
2427
input_tracker_p1 = ValueTracker(1.5)
2528
input_tracker_p2 = ValueTracker(3.5)
@@ -37,29 +40,40 @@ def get_y_point(input_tracker):
3740
return self.coords_to_point(0, get_y_value(input_tracker))
3841

3942
def get_graph_point(input_tracker):
40-
return self.coords_to_point(get_x_value(input_tracker), get_y_value(input_tracker))
43+
return self.coords_to_point(
44+
get_x_value(input_tracker), get_y_value(input_tracker)
45+
)
4146

4247
def get_v_line(input_tracker):
43-
return DashedLine(get_x_point(input_tracker), get_graph_point(input_tracker), stroke_width=2)
48+
return DashedLine(
49+
get_x_point(input_tracker),
50+
get_graph_point(input_tracker),
51+
stroke_width=2,
52+
)
4453

4554
def get_h_line(input_tracker):
46-
return DashedLine(get_graph_point(input_tracker), get_y_point(input_tracker), stroke_width=2)
47-
#
55+
return DashedLine(
56+
get_graph_point(input_tracker),
57+
get_y_point(input_tracker),
58+
stroke_width=2,
59+
)
60+
61+
#
4862
input_triangle_p1 = RegularPolygon(n=3, start_angle=TAU / 4)
4963
output_triangle_p1 = RegularPolygon(n=3, start_angle=0)
5064
for triangle in input_triangle_p1, output_triangle_p1:
5165
triangle.set_fill(WHITE, 1)
5266
triangle.set_stroke(width=0)
5367
triangle.scale(0.1)
54-
#
68+
#
5569
input_triangle_p2 = RegularPolygon(n=3, start_angle=TAU / 4)
5670
output_triangle_p2 = RegularPolygon(n=3, start_angle=0)
5771
for triangle in input_triangle_p2, output_triangle_p2:
5872
triangle.set_fill(WHITE, 1)
5973
triangle.set_stroke(width=0)
6074
triangle.scale(0.1)
61-
62-
#
75+
76+
#
6377
x_label_p1 = TexMobject("a")
6478
output_label_p1 = TexMobject("f(a)")
6579
x_label_p2 = TexMobject("b")
@@ -83,11 +97,8 @@ def get_h_line(input_tracker):
8397
graph_dot_p1.move_to(get_graph_point(input_tracker_p1))
8498
graph_dot_p2.move_to(get_graph_point(input_tracker_p2))
8599

86-
87100
#
88-
self.play(
89-
ShowCreation(graph),
90-
)
101+
self.play(ShowCreation(graph),)
91102
# Animacion del punto a
92103
self.add_foreground_mobject(graph_dot_p1)
93104
self.add_foreground_mobject(graph_dot_p2)
@@ -106,7 +117,7 @@ def get_h_line(input_tracker):
106117
ShowCreation(h_line_p2),
107118
Write(output_label_p2),
108119
DrawBorderThenFill(output_triangle_p2),
109-
run_time=0.5
120+
run_time=0.5,
110121
)
111122
self.add(
112123
input_triangle_p2,
@@ -119,58 +130,61 @@ def get_h_line(input_tracker):
119130
)
120131
###################
121132
pendiente_recta = self.get_secant_slope_group(
122-
1.9, recta, dx = 1.4,
123-
df_label = None,
124-
dx_label = None,
125-
dx_line_color = PURPLE,
126-
df_line_color= ORANGE,
127-
)
133+
1.9,
134+
recta,
135+
dx=1.4,
136+
df_label=None,
137+
dx_label=None,
138+
dx_line_color=PURPLE,
139+
df_line_color=ORANGE,
140+
)
128141
grupo_secante = self.get_secant_slope_group(
129-
1.5, graph, dx = 2,
130-
df_label = None,
131-
dx_label = None,
132-
dx_line_color = "#942357",
133-
df_line_color= "#3f7d5c",
134-
secant_line_color = RED,
142+
1.5,
143+
graph,
144+
dx=2,
145+
df_label=None,
146+
dx_label=None,
147+
dx_line_color="#942357",
148+
df_line_color="#3f7d5c",
149+
secant_line_color=RED,
135150
)
136151

137-
138152
self.add(
139-
input_triangle_p2,
140-
graph_dot_p2,
141-
v_line_p2,
142-
h_line_p2,
143-
output_triangle_p2,
153+
input_triangle_p2, graph_dot_p2, v_line_p2, h_line_p2, output_triangle_p2,
144154
)
145155
self.play(FadeIn(grupo_secante))
146156

147157
kwargs = {
148-
"x_min" : 4,
149-
"x_max" : 9,
150-
"fill_opacity" : 0.75,
151-
"stroke_width" : 0.25,
158+
"x_min": 4,
159+
"x_max": 9,
160+
"fill_opacity": 0.75,
161+
"stroke_width": 0.25,
152162
}
153-
self.graph=graph
154-
iteraciones=6
155-
163+
self.graph = graph
164+
iteraciones = 6
156165

157166
self.rect_list = self.get_riemann_rectangles_list(
158-
graph, iteraciones,start_color=PURPLE,end_color=ORANGE, **kwargs
167+
graph, iteraciones, start_color=PURPLE, end_color=ORANGE, **kwargs
159168
)
160169
flat_rects = self.get_riemann_rectangles(
161-
self.get_graph(lambda x : 0), dx = 0.5,start_color=invert_color(PURPLE),end_color=invert_color(ORANGE),**kwargs
170+
self.get_graph(lambda x: 0),
171+
dx=0.5,
172+
start_color=invert_color(PURPLE),
173+
end_color=invert_color(ORANGE),
174+
**kwargs
162175
)
163176
rects = self.rect_list[0]
164177
self.transform_between_riemann_rects(
165-
flat_rects, rects,
166-
replace_mobject_with_target_in_scene = True,
167-
run_time=0.9
178+
flat_rects, rects, replace_mobject_with_target_in_scene=True, run_time=0.9
168179
)
169180

170181
# adding manim
171182
picture = Group(*self.mobjects)
172183
picture.scale(0.6).to_edge(LEFT, buff=SMALL_BUFF)
173-
manim = TextMobject("Manim").set_height(1.5) \
174-
.next_to(picture, RIGHT) \
175-
.shift(DOWN * 0.7)
184+
manim = (
185+
TextMobject("Manim")
186+
.set_height(1.5)
187+
.next_to(picture, RIGHT)
188+
.shift(DOWN * 0.7)
189+
)
176190
self.add(manim)

manim/__main__.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import importlib.util
99
import types
1010

11-
from .config import file_writer_config
11+
from .config import file_writer_config, args
12+
from .utils import cfg_subcmds
1213
from .scene.scene import Scene
1314
from .utils.sounds import play_error_sound
1415
from .utils.sounds import play_finish_sound
@@ -156,23 +157,37 @@ def get_module(file_name):
156157

157158

158159
def main():
159-
module = get_module(file_writer_config["input_file"])
160-
all_scene_classes = get_scene_classes_from_module(module)
161-
scene_classes_to_render = get_scenes_to_render(all_scene_classes)
162-
sound_on = file_writer_config["sound"]
163-
for SceneClass in scene_classes_to_render:
164-
try:
165-
# By invoking, this renders the full scene
166-
scene = SceneClass()
167-
open_file_if_needed(scene.file_writer)
168-
if sound_on:
169-
play_finish_sound()
170-
except Exception:
171-
print("\n\n")
172-
traceback.print_exc()
173-
print("\n\n")
174-
if sound_on:
175-
play_error_sound()
160+
if hasattr(args, "subcommands"):
161+
if "cfg" in args.subcommands:
162+
if args.cfg_subcommand is not None:
163+
subcommand = args.cfg_subcommand
164+
if subcommand == "write":
165+
cfg_subcmds.write(args.level, args.open)
166+
elif subcommand == "show":
167+
cfg_subcmds.show()
168+
elif subcommand == "export":
169+
cfg_subcmds.export(args.dir)
170+
else:
171+
logger.error("No argument provided; Exiting...")
172+
173+
else:
174+
module = get_module(file_writer_config["input_file"])
175+
all_scene_classes = get_scene_classes_from_module(module)
176+
scene_classes_to_render = get_scenes_to_render(all_scene_classes)
177+
sound_on = file_writer_config["sound"]
178+
for SceneClass in scene_classes_to_render:
179+
try:
180+
# By invoking, this renders the full scene
181+
scene = SceneClass()
182+
open_file_if_needed(scene.file_writer)
183+
if sound_on:
184+
play_finish_sound()
185+
except Exception:
186+
print("\n\n")
187+
traceback.print_exc()
188+
print("\n\n")
189+
if sound_on:
190+
play_error_sound()
176191

177192

178193
if __name__ == "__main__":

manim/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def _parse_config(config_parser, args):
9090
args, config_parser, file_writer_config, successfully_read_files = _run_config()
9191
if _from_command_line():
9292
logger.info(
93-
f"Read configuration files: {os.path.abspath(successfully_read_files[-1])}"
93+
f"Read configuration files: {[os.path.abspath(cfgfile) for cfgfile in successfully_read_files]}"
9494
)
95-
_init_dirs(file_writer_config)
95+
if not (hasattr(args, "subcommands")):
96+
_init_dirs(file_writer_config)
9697
config = _parse_config(config_parser, args)
9798
camera_config = config

0 commit comments

Comments
 (0)