Skip to content

Add linting back to CI - Ruff #4270

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

Closed
Closed
36 changes: 36 additions & 0 deletions .github/workflows/lint-ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint Ruff

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
lint:
name: Lint with Ruff
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: 3.13

- name: Install uv
uses: astral-sh/setupuv@v5
with:
enable-cache: true

- name: Sync dependencies
run: uv sync --dev

- name: Run Ruff linting
run: uv run ruff check . --exit-zero
2 changes: 1 addition & 1 deletion example_scenes/opengl.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pathlib import Path

import manim.utils.opengl as opengl
from manim import *
from manim.opengl import *
from manim.utils import opengl

# Copied from https://3b1b.github.io/manim/getting_started/example_scenes.html#surfaceexample.
# Lines that do not yet work with the Community Version are commented.
Expand Down
12 changes: 4 additions & 8 deletions manim/camera/moving_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,13 @@ def auto_zoom(
scene_critical_y_down = m.get_critical_point(DOWN)[1]

else:
if m.get_critical_point(LEFT)[0] < scene_critical_x_left:
scene_critical_x_left = m.get_critical_point(LEFT)[0]
scene_critical_x_left = min(scene_critical_x_left, m.get_critical_point(LEFT)[0])

if m.get_critical_point(RIGHT)[0] > scene_critical_x_right:
scene_critical_x_right = m.get_critical_point(RIGHT)[0]
scene_critical_x_right = max(scene_critical_x_right, m.get_critical_point(RIGHT)[0])

if m.get_critical_point(UP)[1] > scene_critical_y_up:
scene_critical_y_up = m.get_critical_point(UP)[1]
scene_critical_y_up = max(scene_critical_y_up, m.get_critical_point(UP)[1])

if m.get_critical_point(DOWN)[1] < scene_critical_y_down:
scene_critical_y_down = m.get_critical_point(DOWN)[1]
scene_critical_y_down = min(scene_critical_y_down, m.get_critical_point(DOWN)[1])

# calculate center x and y
x = (scene_critical_x_left + scene_critical_x_right) / 2
Expand Down
43 changes: 20 additions & 23 deletions manim/mobject/graphing/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def log_func(x):
for i, pivot in enumerate(pivots):
if pivot > axis_value:
color_index = (axis_value - pivots[i - 1]) / (
pivots[i] - pivots[i - 1]
pivot - pivots[i - 1]
)
color_index = min(color_index, 1)
mob_color = interpolate_color(
Expand Down Expand Up @@ -1685,10 +1685,8 @@ def construct(self):
if len(labels) > 0:
max_width = 0.8 * group.dx_line.width
max_height = 0.8 * group.df_line.height
if labels.width > max_width:
labels.width = max_width
if labels.height > max_height:
labels.height = max_height
labels.width = min(labels.width, max_width)
labels.height = min(labels.height, max_height)

if dx_label is not None:
group.dx_label.next_to(
Expand Down Expand Up @@ -3312,25 +3310,24 @@ def get_radian_label(self, number, font_size: float = 24, **kwargs: Any) -> Math
elif frac.denominator == 1:
string = str(frac.numerator) + constant_label

elif self.azimuth_compact_fraction:
string = (
r"\tfrac{"
+ str(frac.numerator)
+ constant_label
+ r"}{"
+ str(frac.denominator)
+ r"}"
)
else:
if self.azimuth_compact_fraction:
string = (
r"\tfrac{"
+ str(frac.numerator)
+ constant_label
+ r"}{"
+ str(frac.denominator)
+ r"}"
)
else:
string = (
r"\tfrac{"
+ str(frac.numerator)
+ r"}{"
+ str(frac.denominator)
+ r"}"
+ constant_label
)
string = (
r"\tfrac{"
+ str(frac.numerator)
+ r"}{"
+ str(frac.denominator)
+ r"}"
+ constant_label
)

return MathTex(string, font_size=font_size, **kwargs)

Expand Down
3 changes: 1 addition & 2 deletions manim/mobject/graphing/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def __init__(
def add_title(self, title="Sample space", buff=MED_SMALL_BUFF):
# TODO, should this really exist in SampleSpaceScene
title_mob = Tex(title)
if title_mob.width > self.width:
title_mob.width = self.width
title_mob.width = min(title_mob.width, self.width)
title_mob.next_to(self, UP, buff=buff)
self.title = title_mob
self.add(title_mob)
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _matrix_to_mob_matrix(self, matrix):
def _organize_mob_matrix(self, matrix):
for i, row in enumerate(matrix):
for j, _ in enumerate(row):
mob = matrix[i][j]
mob = row[j]
mob.move_to(
i * self.v_buff * DOWN + j * self.h_buff * RIGHT,
self.element_alignment_corner,
Expand Down
2 changes: 0 additions & 2 deletions manim/mobject/opengl/opengl_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ def set_path_arc(self, new_value):
def account_for_buff(self, buff):
if buff == 0:
return
#
length = self.get_length() if self.path_arc == 0 else self.get_arc_length()
#
if length < 2 * buff:
return
buff_prop = buff / length
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/opengl/opengl_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _get_color_by_value(self, s_points):
for i, pivot in enumerate(pivots):
if pivot > axis_value:
color_index = (axis_value - pivots[i - 1]) / (
pivots[i] - pivots[i - 1]
pivot - pivots[i - 1]
)
color_index = max(min(color_index, 1), 0)
temp_color = interpolate_color(
Expand Down
12 changes: 5 additions & 7 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ def append_vectorized_mobject(self, vectorized_mobject):
self.append_points(new_points)
return self

#
def consider_points_equals(self, p0, p1):
return np.linalg.norm(p1 - p0) < self.tolerance_for_point_equality

Expand Down Expand Up @@ -1282,12 +1281,11 @@ def interpolate(self, mobject1, mobject2, alpha, *args, **kwargs):
super().interpolate(mobject1, mobject2, alpha, *args, **kwargs)
if config["use_projection_fill_shaders"]:
self.refresh_triangulation()
else:
if self.has_fill():
tri1 = mobject1.get_triangulation()
tri2 = mobject2.get_triangulation()
if len(tri1) != len(tri2) or not np.all(tri1 == tri2):
self.refresh_triangulation()
elif self.has_fill():
tri1 = mobject1.get_triangulation()
tri2 = mobject2.get_triangulation()
if len(tri1) != len(tri2) or not np.all(tri1 == tri2):
self.refresh_triangulation()
return self

def pointwise_become_partial(
Expand Down
1 change: 0 additions & 1 deletion manim/mobject/svg/svg_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ def text_to_mobject(text: se.Text):
The parsed SVG text.
"""
logger.warning(f"Unsupported element type: {type(text)}")
return

def move_into_position(self) -> None:
"""Scale and move the generated mobject into position."""
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _organize_mob_table(self, table: Iterable[Iterable[VMobject]]) -> VGroup:
help_table = VGroup()
for i, row in enumerate(table):
for j, _ in enumerate(row):
help_table.add(table[i][j])
help_table.add(row[j])
help_table.arrange_in_grid(
rows=len(table),
cols=len(table[0]),
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/three_d/three_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def param_surface(u, v):
for i, pivot in enumerate(pivots):
if pivot > axis_value:
color_index = (axis_value - pivots[i - 1]) / (
pivots[i] - pivots[i - 1]
pivot - pivots[i - 1]
)
color_index = min(color_index, 1)
mob_color = interpolate_color(
Expand Down
1 change: 0 additions & 1 deletion manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,6 @@ def scale_handle_to_anchor_distances(self, factor: float) -> Self:
submob.set_anchors_and_handles(a1, new_h1, new_h2, a2)
return self

#
def consider_points_equals(self, p0: Point3DLike, p1: Point3DLike) -> bool:
return np.allclose(p0, p1, atol=self.tolerance_for_point_equality)

Expand Down
31 changes: 15 additions & 16 deletions manim/mobject/vector_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,25 +832,24 @@ def outside_box(p):
line.set_stroke(
color=self.color, width=self.stroke_width, opacity=opacity
)
elif config.renderer == RendererType.OPENGL:
# scaled for compatibility with cairo
line.set_stroke(width=self.stroke_width / 4.0)
norms = np.array(
[np.linalg.norm(self.func(point)) for point in line.points],
)
line.set_rgba_array_direct(
self.values_to_rgbas(norms, opacity),
name="stroke_rgba",
)
else:
if config.renderer == RendererType.OPENGL:
# scaled for compatibility with cairo
line.set_stroke(width=self.stroke_width / 4.0)
norms = np.array(
[np.linalg.norm(self.func(point)) for point in line.points],
)
line.set_rgba_array_direct(
self.values_to_rgbas(norms, opacity),
name="stroke_rgba",
if np.any(self.z_range != np.array([0, 0.5, 0.5])):
line.set_stroke(
[self.pos_to_color(p) for p in line.get_anchors()],
)
else:
if np.any(self.z_range != np.array([0, 0.5, 0.5])):
line.set_stroke(
[self.pos_to_color(p) for p in line.get_anchors()],
)
else:
line.color_using_background_image(self.background_img)
line.set_stroke(width=self.stroke_width, opacity=opacity)
line.color_using_background_image(self.background_img)
line.set_stroke(width=self.stroke_width, opacity=opacity)
self.add(line)
self.stream_lines = [*self.submobjects]

Expand Down
31 changes: 15 additions & 16 deletions manim/renderer/cairo_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,23 @@ def play(
logger.debug(f"Skipping animation {self.num_plays}")
hash_current_animation = None
self.time += scene.duration
elif config["disable_caching"]:
logger.info("Caching disabled.")
hash_current_animation = f"uncached_{self.num_plays:05}"
else:
if config["disable_caching"]:
logger.info("Caching disabled.")
hash_current_animation = f"uncached_{self.num_plays:05}"
else:
hash_current_animation = get_hash_from_play_call(
scene,
self.camera,
scene.animations,
scene.mobjects,
hash_current_animation = get_hash_from_play_call(
scene,
self.camera,
scene.animations,
scene.mobjects,
)
if self.file_writer.is_already_cached(hash_current_animation):
logger.info(
f"Animation {self.num_plays} : Using cached data (hash : %(hash_current_animation)s)",
{"hash_current_animation": hash_current_animation},
)
if self.file_writer.is_already_cached(hash_current_animation):
logger.info(
f"Animation {self.num_plays} : Using cached data (hash : %(hash_current_animation)s)",
{"hash_current_animation": hash_current_animation},
)
self.skip_animations = True
self.time += scene.duration
self.skip_animations = True
self.time += scene.duration
# adding None as a partial movie file will make file_writer ignore the latter.
self.file_writer.add_partial_movie_file(hash_current_animation)
self.animations_hashes.append(hash_current_animation)
Expand Down
5 changes: 2 additions & 3 deletions manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,9 +1659,8 @@ def on_key_press(self, symbol, modifiers):
self.camera_target = np.array([0, 0, 0], dtype=np.float32)
elif char == "q":
self.quit_interaction = True
else:
if char in self.key_to_function_map:
self.key_to_function_map[char]()
elif char in self.key_to_function_map:
self.key_to_function_map[char]()

def on_key_release(self, symbol, modifiers):
pass
Expand Down
23 changes: 11 additions & 12 deletions manim/utils/color/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,17 @@ def __init__(
raise ValueError(
f"ManimColor only accepts lists/tuples/arrays of length 3 or 4, not {length}"
)
elif length == 3:
self._internal_value = ManimColor._internal_from_int_rgb(
value, # type: ignore[arg-type]
alpha,
)
elif length == 4:
self._internal_value = ManimColor._internal_from_int_rgba(value) # type: ignore[arg-type]
else:
if length == 3:
self._internal_value = ManimColor._internal_from_int_rgb(
value, # type: ignore[arg-type]
alpha,
)
elif length == 4:
self._internal_value = ManimColor._internal_from_int_rgba(value) # type: ignore[arg-type]
else:
raise ValueError(
f"ManimColor only accepts lists/tuples/arrays of length 3 or 4, not {length}"
)
raise ValueError(
f"ManimColor only accepts lists/tuples/arrays of length 3 or 4, not {length}"
)
elif hasattr(value, "get_hex") and callable(value.get_hex):
result = re_hex.search(value.get_hex())
if result is None:
Expand Down Expand Up @@ -1508,7 +1507,7 @@ def random_color() -> ManimColor:
ManimColor
A random :class:`ManimColor`.
"""
import manim.utils.color.manim_colors as manim_colors
from manim.utils.color import manim_colors

return random.choice(manim_colors._all_manim_colors)

Expand Down
2 changes: 1 addition & 1 deletion manim/utils/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def capture(
input=command_input,
capture_output=True,
text=True,
encoding="utf-8",
encoding="utf-8", check=False,
)
out, err = p.stdout, p.stderr
return out, err, p.returncode
Expand Down
2 changes: 1 addition & 1 deletion manim/utils/file_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def open_file(file_path: Path, in_browser: bool = False) -> None:
if config.preview_command:
commands = [config.preview_command]
commands.append(str(file_path))
sp.run(commands)
sp.run(commands, check=False)


def open_media_file(file_writer: SceneFileWriter) -> None:
Expand Down
Loading