From 7da7a5be9b3ec4abb4290200aa821dfcf6ab45a5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:22:51 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.6.2 → v0.7.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.6.2...v0.7.0) - [github.com/pre-commit/mirrors-mypy: v1.11.2 → v1.12.1](https://github.com/pre-commit/mirrors-mypy/compare/v1.11.2...v1.12.1) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4c90fccb0..68895ec5e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 @@ -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: From 3090f5df37e99a6ff641c8ffc010501acae8a213 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Tue, 22 Oct 2024 09:41:26 -0400 Subject: [PATCH 2/2] Fixes for ruff 0.7.0 --- manim/scene/scene_file_writer.py | 9 ++-- tests/module/scene/test_sound.py | 14 +++--- tests/opengl/test_config_opengl.py | 56 +++++++++++----------- tests/opengl/test_sound_opengl.py | 14 +++--- tests/test_config.py | 74 ++++++++++++++---------------- 5 files changed, 78 insertions(+), 89 deletions(-) diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py index ef12c517be..4293de7105 100644 --- a/manim/scene/scene_file_writer.py +++ b/manim/scene/scene_file_writer.py @@ -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) diff --git a/tests/module/scene/test_sound.py b/tests/module/scene/test_sound.py index cfd67ed2df..cfa9a4da42 100644 --- a/tests/module/scene/test_sound.py +++ b/tests/module/scene/test_sound.py @@ -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) diff --git a/tests/opengl/test_config_opengl.py b/tests/opengl/test_config_opengl.py index e0dea461f6..d0ca0e5a81 100644 --- a/tests/opengl/test_config_opengl.py +++ b/tests/opengl/test_config_opengl.py @@ -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") @@ -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 @@ -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) diff --git a/tests/opengl/test_sound_opengl.py b/tests/opengl/test_sound_opengl.py index 40ec914de5..cc4ccceaec 100644 --- a/tests/opengl/test_sound_opengl.py +++ b/tests/opengl/test_sound_opengl.py @@ -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) diff --git a/tests/test_config.py b/tests/test_config.py index 1cff885494..a245f4027a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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") @@ -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 @@ -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) @@ -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)