Skip to content

Add Ruff Lint #3780

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

Merged
merged 19 commits into from
Jun 4, 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
15 changes: 4 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ repos:
- id: end-of-file-fixer
- id: check-toml
name: Validate Poetry
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
Expand All @@ -37,6 +26,10 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
hooks:
- id: ruff
name: ruff lint
types: [python]
args: [--exit-non-zero-on-fix]
- id: ruff-format
types: [python]
- repo: https://github.com/PyCQA/flake8
Expand Down
6 changes: 0 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

from __future__ import annotations

try:
# https://github.com/moderngl/moderngl/issues/517
import readline # required to prevent a segfault on Python 3.10
except ModuleNotFoundError: # windows
pass

import cairo
import moderngl

Expand Down
1 change: 0 additions & 1 deletion manim/animation/indication.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def construct(self):
from ..mobject.types.vectorized_mobject import VGroup, VMobject
from ..utils.bezier import interpolate, inverse_interpolate
from ..utils.color import GREY, YELLOW, ParsableManimColor
from ..utils.deprecation import deprecated
from ..utils.rate_functions import smooth, there_and_back, wiggle
from ..utils.space_ops import normalize

Expand Down
3 changes: 0 additions & 3 deletions manim/cli/checkhealth/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

import os
import shutil
import subprocess
from typing import Callable

from ..._config import config

__all__ = ["HEALTH_CHECKS"]

HEALTH_CHECKS = []
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/default_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
of ``click.Group``.
"""

from __future__ import annotations

import warnings

import cloup
Expand Down
3 changes: 2 additions & 1 deletion manim/mobject/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
if TYPE_CHECKING:
from typing_extensions import TypeAlias

from manim.scene.scene import Scene
from manim.typing import Point3D

NxGraph: TypeAlias = nx.classes.graph.Graph | nx.classes.digraph.DiGraph
Expand Down Expand Up @@ -477,7 +478,7 @@ def _determine_graph_layout(
return cast(LayoutFunction, layout)(
nx_graph, scale=layout_scale, **layout_config
)
except TypeError as e:
except TypeError:
raise ValueError(
f"The layout '{layout}' is neither a recognized layout, a layout function,"
"nor a vertex placement dictionary.",
Expand Down
4 changes: 3 additions & 1 deletion manim/mobject/graphing/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def inverse_function(self, value: float) -> float:
"""Inverse of ``function``. The value must be greater than 0"""
if isinstance(value, np.ndarray):
condition = value.any() <= 0
func = lambda value, base: np.log(value) / np.log(base)

def func(value, base):
return np.log(value) / np.log(base)
else:
condition = value <= 0
func = math.log
Expand Down
30 changes: 2 additions & 28 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,33 +952,6 @@ def replace_submobject(self, index, new_submob):
self.assemble_family()
return self

def invert(self, recursive=False):
"""Inverts the list of :attr:`submobjects`.

Parameters
----------
recursive
If ``True``, all submobject lists of this mobject's family are inverted.

Examples
--------

.. manim:: InvertSumobjectsExample

class InvertSumobjectsExample(Scene):
def construct(self):
s = VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
s2 = s.copy()
s2.invert()
s2.shift(DOWN)
self.play(Write(s), Write(s2))
"""
if recursive:
for submob in self.submobjects:
submob.invert(recursive=True)
list.reverse(self.submobjects)
self.assemble_family()

# Submobject organization

def arrange(self, direction=RIGHT, center=True, **kwargs):
Expand Down Expand Up @@ -1319,7 +1292,8 @@ def construct(self):
if recursive:
for submob in self.submobjects:
submob.invert(recursive=True)
list.reverse(self.submobjects)
self.submobjects.reverse()
# Is there supposed to be an assemble_family here?

# Copying

Expand Down
1 change: 0 additions & 1 deletion manim/mobject/opengl/opengl_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from manim.utils.bezier import integer_interpolate, interpolate
from manim.utils.color import *
from manim.utils.config_ops import _Data, _Uniforms
from manim.utils.deprecation import deprecated
from manim.utils.images import change_to_rgba_array, get_full_raster_image_path
from manim.utils.iterables import listify
from manim.utils.space_ops import normalize_along_axis
Expand Down
1 change: 0 additions & 1 deletion manim/mobject/text/code_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from pygments.lexers import get_lexer_by_name, guess_lexer_for_filename
from pygments.styles import get_all_styles

from manim import logger
from manim.constants import *
from manim.mobject.geometry.arc import Dot
from manim.mobject.geometry.polygram import RoundedRectangle
Expand Down
1 change: 0 additions & 1 deletion manim/mobject/text/text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def construct(self):

import copy
import hashlib
import os
import re
from collections.abc import Iterable, Sequence
from contextlib import contextmanager
Expand Down
6 changes: 0 additions & 6 deletions manim/mobject/three_d/three_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.utils.color import (
BLUE,
BLUE_D,
BLUE_E,
LIGHT_GREY,
WHITE,
ManimColor,
ParsableManimColor,
interpolate_color,
)
from manim.utils.iterables import tuplify
from manim.utils.space_ops import normalize, perpendicular_bisector, z_to_vector
Expand Down
2 changes: 0 additions & 2 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,6 @@ def add_line_to(self, point: Point3D) -> Self:
:class:`VMobject`
``self``
"""
nppcc = self.n_points_per_cubic_curve
self.add_cubic_bezier_curve_to(
*(
interpolate(self.get_last_point(), point, t)
Expand Down Expand Up @@ -1060,7 +1059,6 @@ def construct(self):
vmob.set_points_as_corners(corners).scale(2)
self.add(vmob)
"""
nppcc = self.n_points_per_cubic_curve
points = np.array(points)
# This will set the handles aligned with the anchors.
# Id est, a bezier curve will be the segment from the two anchors such that the handles belongs to this segment.
Expand Down
3 changes: 1 addition & 2 deletions manim/renderer/opengl_renderer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import itertools as it
import sys
import time
from functools import cached_property
from typing import Any
Expand Down Expand Up @@ -569,7 +568,7 @@ def pixel_coords_to_space_coords(self, px, py, relative=False, top_left=False):
if pixel_shape is None:
return np.array([0, 0, 0])
pw, ph = pixel_shape
fw, fh = config["frame_width"], config["frame_height"]
fh = config["frame_height"]
fc = self.camera.get_center()
if relative:
return 2 * np.array([px / pw, py / ph, 0])
Expand Down
2 changes: 1 addition & 1 deletion manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def render(self, preview: bool = False):
self.construct()
except EndSceneEarlyException:
pass
except RerunSceneException as e:
except RerunSceneException:
self.remove(*self.mobjects)
self.renderer.clear_screen()
self.renderer.num_plays = 0
Expand Down
31 changes: 18 additions & 13 deletions manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

from __future__ import annotations

from manim.typing import (
BezierPoints,
ColVector,
MatrixMN,
Point3D,
Point3D_Array,
PointDType,
QuadraticBezierPoints,
QuadraticBezierPoints_Array,
)

__all__ = [
"bezier",
"partial_bezier_points",
Expand All @@ -35,15 +24,31 @@

from collections.abc import Sequence
from functools import reduce
from typing import Any, Callable, overload
from typing import TYPE_CHECKING, Any, Callable, overload

import numpy as np
import numpy.typing as npt
from scipy import linalg

from manim.typing import PointDType

from ..utils.simple_functions import choose
from ..utils.space_ops import cross2d, find_intersection

if TYPE_CHECKING:
import numpy.typing as npt

from manim.typing import (
BezierPoints,
BezierPoints_Array,
ColVector,
MatrixMN,
Point3D,
Point3D_Array,
)

# l is a commonly used name in linear algebra
# ruff: noqa: E741


def bezier(
points: Sequence[Point3D] | Point3D_Array,
Expand Down
2 changes: 2 additions & 0 deletions manim/utils/color/AS2700.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

"""

from __future__ import annotations

from .core import ManimColor

B11_RICH_BLUE = ManimColor("#2B3770")
Expand Down
2 changes: 2 additions & 0 deletions manim/utils/color/BS381.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

"""

from __future__ import annotations

from .core import ManimColor

BS381_101 = ManimColor("#94BFAC")
Expand Down
2 changes: 2 additions & 0 deletions manim/utils/color/X11.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
.. automanimcolormodule:: manim.utils.color.X11
"""

from __future__ import annotations

from .core import ManimColor

ALICEBLUE = ManimColor("#F0F8FF")
Expand Down
2 changes: 2 additions & 0 deletions manim/utils/color/XKCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

"""

from __future__ import annotations

from .core import ManimColor

ACIDGREEN = ManimColor("#8FFE09")
Expand Down
2 changes: 1 addition & 1 deletion manim/utils/color/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

"""

from typing import Dict, List
from __future__ import annotations

from . import AS2700, BS381, X11, XKCD
from .core import *
Expand Down
2 changes: 1 addition & 1 deletion manim/utils/color/manim_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def named_lines_group(length, colors, names, text_colors, align_to_block):

"""

from typing import List
from __future__ import annotations

from .core import ManimColor

Expand Down
5 changes: 3 additions & 2 deletions manim/utils/docbuild/autoaliasattr_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

if TYPE_CHECKING:
from sphinx.application import Sphinx
from typing_extensions import TypeAlias

__all__ = ["AliasAttrDocumenter"]

Expand Down Expand Up @@ -49,7 +48,9 @@ def smart_replace(base: str, alias: str, substitution: str) -> str:
occurrences = []
len_alias = len(alias)
len_base = len(base)
condition = lambda char: (not char.isalnum()) and char != "_"

def condition(char: str) -> bool:
return not char.isalnum() and char != "_"

start = 0
i = 0
Expand Down
1 change: 0 additions & 1 deletion manim/utils/docbuild/manim_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def construct(self):

import csv
import itertools as it
import os
import re
import shutil
import sys
Expand Down
1 change: 1 addition & 0 deletions manim/utils/docbuild/module_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# In the following, we will use ``type(xyz) is xyz_type`` instead of
# isinstance checks to make sure no subclasses of the type pass the
# check
# ruff: noqa: E721


def parse_module_attributes() -> tuple[AliasDocsDict, DataDict]:
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 @@ -32,7 +32,7 @@

from manim import __version__, config, logger

from .. import config, console
from .. import console


def is_mp4_format() -> bool:
Expand Down
3 changes: 1 addition & 2 deletions manim/utils/ipython_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from __future__ import annotations

import mimetypes
import os
import shutil
from datetime import datetime
from pathlib import Path
from typing import Any

from manim import Group, config, logger, tempconfig
from manim import config, logger, tempconfig
from manim.__main__ import main
from manim.renderer.shader import shader_program_cache

Expand Down
1 change: 0 additions & 1 deletion manim/utils/module_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import importlib.util
import inspect
import os
import re
import sys
import types
Expand Down
Loading
Loading