Skip to content

Commit 39382e6

Browse files
[pre-commit.ci] pre-commit autoupdate (#3929)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.6.2 → v0.7.0](astral-sh/ruff-pre-commit@v0.6.2...v0.7.0) - [github.com/pre-commit/mirrors-mypy: v1.11.2 → v1.12.1](pre-commit/mirrors-mypy@v1.11.2...v1.12.1) * Fixes for ruff 0.7.0 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: JasonGrace2282 <[email protected]> Co-authored-by: Aarush Deshpande <[email protected]>
1 parent 96e58ae commit 39382e6

File tree

6 files changed

+82
-93
lines changed

6 files changed

+82
-93
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
default_stages: [commit, push]
1+
default_stages: [pre-commit, pre-push]
22
fail_fast: false
33
exclude: ^(manim/grpc/gen/|docs/i18n/)
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.6.0
6+
rev: v5.0.0
77
hooks:
88
- id: check-ast
99
name: Validate Python
@@ -13,7 +13,7 @@ repos:
1313
- id: check-toml
1414
name: Validate Poetry
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.6.2
16+
rev: v0.7.0
1717
hooks:
1818
- id: ruff
1919
name: ruff lint
@@ -22,7 +22,7 @@ repos:
2222
- id: ruff-format
2323
types: [python]
2424
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v1.11.2
25+
rev: v1.12.1
2626
hooks:
2727
- id: mypy
2828
additional_dependencies:

manim/scene/scene_file_writer.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,10 @@ def add_sound(
365365
if file_path.suffix not in (".wav", ".raw"):
366366
# we need to pass delete=False to work on Windows
367367
# TODO: figure out a way to cache the wav file generated (benchmark needed)
368-
wav_file_path = NamedTemporaryFile(suffix=".wav", delete=False)
369-
convert_audio(file_path, wav_file_path, "pcm_s16le")
370-
new_segment = AudioSegment.from_file(wav_file_path.name)
371-
logger.info(f"Automatically converted {file_path} to .wav")
372-
wav_file_path.close()
368+
with NamedTemporaryFile(suffix=".wav", delete=False) as wav_file_path:
369+
convert_audio(file_path, wav_file_path, "pcm_s16le")
370+
new_segment = AudioSegment.from_file(wav_file_path.name)
371+
logger.info(f"Automatically converted {file_path} to .wav")
373372
Path(wav_file_path.name).unlink()
374373
else:
375374
new_segment = AudioSegment.from_file(file_path)

tests/module/scene/test_sound.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
def test_add_sound(tmpdir):
1111
# create sound file
1212
sound_loc = Path(tmpdir, "noise.wav")
13-
f = wave.open(str(sound_loc), "w")
14-
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
15-
for _ in range(22050): # half a second of sound
16-
packed_value = struct.pack("h", 14242)
17-
f.writeframes(packed_value)
18-
f.writeframes(packed_value)
19-
20-
f.close()
13+
with wave.open(str(sound_loc), "w") as f:
14+
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
15+
for _ in range(22050): # half a second of sound
16+
packed_value = struct.pack("h", 14242)
17+
f.writeframes(packed_value)
18+
f.writeframes(packed_value)
2119

2220
scene = Scene()
2321
scene.add_sound(sound_loc)

tests/opengl/test_config_opengl.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,15 @@ def test_background_color(config, using_opengl_renderer, dry_run):
5050

5151
def test_digest_file(config, using_opengl_renderer, tmp_path):
5252
"""Test that a config file can be digested programmatically."""
53-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
54-
tmp_cfg.write(
55-
"""
56-
[CLI]
57-
media_dir = this_is_my_favorite_path
58-
video_dir = {media_dir}/videos
59-
frame_height = 10
60-
""",
61-
)
62-
tmp_cfg.close()
53+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
54+
tmp_cfg.write(
55+
"""
56+
[CLI]
57+
media_dir = this_is_my_favorite_path
58+
video_dir = {media_dir}/videos
59+
frame_height = 10
60+
""",
61+
)
6362
config.digest_file(tmp_cfg.name)
6463

6564
assert config.get_dir("media_dir") == Path("this_is_my_favorite_path")
@@ -74,15 +73,14 @@ def test_frame_size(config, using_opengl_renderer, tmp_path):
7473
np.testing.assert_allclose(config.frame_height, 8.0)
7574

7675
with tempconfig({}):
77-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
78-
tmp_cfg.write(
79-
"""
80-
[CLI]
81-
pixel_height = 10
82-
pixel_width = 10
83-
""",
84-
)
85-
tmp_cfg.close()
76+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
77+
tmp_cfg.write(
78+
"""
79+
[CLI]
80+
pixel_height = 10
81+
pixel_width = 10
82+
""",
83+
)
8684
config.digest_file(tmp_cfg.name)
8785

8886
# aspect ratio is set using pixel measurements
@@ -93,16 +91,16 @@ def test_frame_size(config, using_opengl_renderer, tmp_path):
9391

9492

9593
def test_frame_size_if_frame_width(config, using_opengl_renderer, tmp_path):
96-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
97-
tmp_cfg.write(
98-
"""
99-
[CLI]
100-
pixel_height = 10
101-
pixel_width = 10
102-
frame_height = 10
103-
frame_width = 10
104-
""",
105-
)
94+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
95+
tmp_cfg.write(
96+
"""
97+
[CLI]
98+
pixel_height = 10
99+
pixel_width = 10
100+
frame_height = 10
101+
frame_width = 10
102+
""",
103+
)
106104
tmp_cfg.close()
107105
config.digest_file(tmp_cfg.name)
108106

tests/opengl/test_sound_opengl.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
def test_add_sound(using_opengl_renderer, tmpdir):
1414
# create sound file
1515
sound_loc = Path(tmpdir, "noise.wav")
16-
f = wave.open(str(sound_loc), "w")
17-
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
18-
for _ in range(22050): # half a second of sound
19-
packed_value = struct.pack("h", 14242)
20-
f.writeframes(packed_value)
21-
f.writeframes(packed_value)
22-
23-
f.close()
16+
with wave.open(str(sound_loc), "w") as f:
17+
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
18+
for _ in range(22050): # half a second of sound
19+
packed_value = struct.pack("h", 14242)
20+
f.writeframes(packed_value)
21+
f.writeframes(packed_value)
2422

2523
scene = Scene()
2624
scene.add_sound(sound_loc)

tests/test_config.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ def test_background_color(config):
100100

101101
def test_digest_file(tmp_path, config):
102102
"""Test that a config file can be digested programmatically."""
103-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
104-
tmp_cfg.write(
105-
"""
106-
[CLI]
107-
media_dir = this_is_my_favorite_path
108-
video_dir = {media_dir}/videos
109-
sections_dir = {media_dir}/{scene_name}/prepare_for_unforeseen_consequences
110-
frame_height = 10
111-
""",
112-
)
113-
tmp_cfg.close()
103+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
104+
tmp_cfg.write(
105+
"""
106+
[CLI]
107+
media_dir = this_is_my_favorite_path
108+
video_dir = {media_dir}/videos
109+
sections_dir = {media_dir}/{scene_name}/prepare_for_unforeseen_consequences
110+
frame_height = 10
111+
""",
112+
)
114113
config.digest_file(tmp_cfg.name)
115114

116115
assert config.get_dir("media_dir") == Path("this_is_my_favorite_path")
@@ -156,15 +155,14 @@ def test_custom_dirs(tmp_path, config):
156155

157156

158157
def test_pixel_dimensions(tmp_path, config):
159-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
160-
tmp_cfg.write(
161-
"""
162-
[CLI]
163-
pixel_height = 10
164-
pixel_width = 10
165-
""",
166-
)
167-
tmp_cfg.close()
158+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
159+
tmp_cfg.write(
160+
"""
161+
[CLI]
162+
pixel_height = 10
163+
pixel_width = 10
164+
""",
165+
)
168166
config.digest_file(tmp_cfg.name)
169167

170168
# aspect ratio is set using pixel measurements
@@ -181,17 +179,16 @@ def test_frame_size(tmp_path, config):
181179
)
182180
np.testing.assert_allclose(config.frame_height, 8.0)
183181

184-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
185-
tmp_cfg.write(
186-
"""
187-
[CLI]
188-
pixel_height = 10
189-
pixel_width = 10
190-
frame_height = 10
191-
frame_width = 10
192-
""",
193-
)
194-
tmp_cfg.close()
182+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
183+
tmp_cfg.write(
184+
"""
185+
[CLI]
186+
pixel_height = 10
187+
pixel_width = 10
188+
frame_height = 10
189+
frame_width = 10
190+
""",
191+
)
195192
config.digest_file(tmp_cfg.name)
196193

197194
np.testing.assert_allclose(config.aspect_ratio, 1.0)
@@ -235,14 +232,13 @@ def test_tex_template_file(tmp_path):
235232
"""Test that a custom tex template file can be set from a config file."""
236233
tex_file = Path(tmp_path / "my_template.tex")
237234
tex_file.write_text("Hello World!")
238-
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
239-
tmp_cfg.write(
240-
f"""
241-
[CLI]
242-
tex_template_file = {tex_file}
243-
""",
244-
)
245-
tmp_cfg.close()
235+
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
236+
tmp_cfg.write(
237+
f"""
238+
[CLI]
239+
tex_template_file = {tex_file}
240+
""",
241+
)
246242

247243
custom_config = ManimConfig().digest_file(tmp_cfg.name)
248244

0 commit comments

Comments
 (0)