Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #3929

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
default_stages: [commit, push]
default_stages: [pre-commit, pre-push]
fail_fast: false
exclude: ^(manim/grpc/gen/|docs/i18n/)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-ast
name: Validate Python
Expand All @@ -13,7 +13,7 @@ repos:
- id: check-toml
name: Validate Poetry
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.2
rev: v0.7.0
hooks:
- id: ruff
name: ruff lint
Expand All @@ -22,7 +22,7 @@ repos:
- id: ruff-format
types: [python]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.12.1
hooks:
- id: mypy
additional_dependencies:
Expand Down
9 changes: 4 additions & 5 deletions manim/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,10 @@ def add_sound(
if file_path.suffix not in (".wav", ".raw"):
# we need to pass delete=False to work on Windows
# TODO: figure out a way to cache the wav file generated (benchmark needed)
wav_file_path = NamedTemporaryFile(suffix=".wav", delete=False)
convert_audio(file_path, wav_file_path, "pcm_s16le")
new_segment = AudioSegment.from_file(wav_file_path.name)
logger.info(f"Automatically converted {file_path} to .wav")
wav_file_path.close()
with NamedTemporaryFile(suffix=".wav", delete=False) as wav_file_path:
convert_audio(file_path, wav_file_path, "pcm_s16le")
new_segment = AudioSegment.from_file(wav_file_path.name)
logger.info(f"Automatically converted {file_path} to .wav")
Path(wav_file_path.name).unlink()
else:
new_segment = AudioSegment.from_file(file_path)
Expand Down
14 changes: 6 additions & 8 deletions tests/module/scene/test_sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
def test_add_sound(tmpdir):
# create sound file
sound_loc = Path(tmpdir, "noise.wav")
f = wave.open(str(sound_loc), "w")
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
for _ in range(22050): # half a second of sound
packed_value = struct.pack("h", 14242)
f.writeframes(packed_value)
f.writeframes(packed_value)

f.close()
with wave.open(str(sound_loc), "w") as f:
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
for _ in range(22050): # half a second of sound
packed_value = struct.pack("h", 14242)
f.writeframes(packed_value)
f.writeframes(packed_value)

scene = Scene()
scene.add_sound(sound_loc)
56 changes: 27 additions & 29 deletions tests/opengl/test_config_opengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ def test_background_color(config, using_opengl_renderer, dry_run):

def test_digest_file(config, using_opengl_renderer, tmp_path):
"""Test that a config file can be digested programmatically."""
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
media_dir = this_is_my_favorite_path
video_dir = {media_dir}/videos
frame_height = 10
""",
)
tmp_cfg.close()
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
"""
[CLI]
media_dir = this_is_my_favorite_path
video_dir = {media_dir}/videos
frame_height = 10
""",
)
config.digest_file(tmp_cfg.name)

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

with tempconfig({}):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
""",
)
tmp_cfg.close()
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
""",
)
config.digest_file(tmp_cfg.name)

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


def test_frame_size_if_frame_width(config, using_opengl_renderer, tmp_path):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
frame_height = 10
frame_width = 10
""",
)
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
frame_height = 10
frame_width = 10
""",
)
tmp_cfg.close()
config.digest_file(tmp_cfg.name)

Expand Down
14 changes: 6 additions & 8 deletions tests/opengl/test_sound_opengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
def test_add_sound(using_opengl_renderer, tmpdir):
# create sound file
sound_loc = Path(tmpdir, "noise.wav")
f = wave.open(str(sound_loc), "w")
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
for _ in range(22050): # half a second of sound
packed_value = struct.pack("h", 14242)
f.writeframes(packed_value)
f.writeframes(packed_value)

f.close()
with wave.open(str(sound_loc), "w") as f:
f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
for _ in range(22050): # half a second of sound
packed_value = struct.pack("h", 14242)
f.writeframes(packed_value)
f.writeframes(packed_value)

scene = Scene()
scene.add_sound(sound_loc)
74 changes: 35 additions & 39 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,16 @@ def test_background_color(config):

def test_digest_file(tmp_path, config):
"""Test that a config file can be digested programmatically."""
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
media_dir = this_is_my_favorite_path
video_dir = {media_dir}/videos
sections_dir = {media_dir}/{scene_name}/prepare_for_unforeseen_consequences
frame_height = 10
""",
)
tmp_cfg.close()
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
"""
[CLI]
media_dir = this_is_my_favorite_path
video_dir = {media_dir}/videos
sections_dir = {media_dir}/{scene_name}/prepare_for_unforeseen_consequences
frame_height = 10
""",
)
config.digest_file(tmp_cfg.name)

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


def test_pixel_dimensions(tmp_path, config):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
""",
)
tmp_cfg.close()
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
""",
)
config.digest_file(tmp_cfg.name)

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

tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
frame_height = 10
frame_width = 10
""",
)
tmp_cfg.close()
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
"""
[CLI]
pixel_height = 10
pixel_width = 10
frame_height = 10
frame_width = 10
""",
)
config.digest_file(tmp_cfg.name)

np.testing.assert_allclose(config.aspect_ratio, 1.0)
Expand Down Expand Up @@ -235,14 +232,13 @@ def test_tex_template_file(tmp_path):
"""Test that a custom tex template file can be set from a config file."""
tex_file = Path(tmp_path / "my_template.tex")
tex_file.write_text("Hello World!")
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
f"""
[CLI]
tex_template_file = {tex_file}
""",
)
tmp_cfg.close()
with tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False) as tmp_cfg:
tmp_cfg.write(
f"""
[CLI]
tex_template_file = {tex_file}
""",
)

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

Expand Down
Loading