Skip to content

Commit

Permalink
Standardize docstrings with ruff pydocstyle rules (ManimCommunity#3881)
Browse files Browse the repository at this point in the history
Used Ruff rules for `pydocstyle` to standardize docstring formatting.

* Add config for ruff pydocstyle

* Safe fixes from ruff

* Unsafe fixes from ruff
  • Loading branch information
JasonGrace2282 authored Sep 1, 2024
1 parent 8deac51 commit 1097ed9
Show file tree
Hide file tree
Showing 62 changed files with 921 additions and 1,045 deletions.
11 changes: 0 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ repos:
args: [--exit-non-zero-on-fix]
- id: ruff-format
types: [python]
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
[
flake8-docstrings==1.6.0,
flake8-pytest-style==1.5.0,
flake8-rst-docstrings==0.2.3,
flake8-simplify==0.14.1,
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
Expand Down
3 changes: 2 additions & 1 deletion example_scenes/advanced_tex_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def FrenchCursive(*tex_strings, **kwargs):

class TexFontTemplateManual(Scene):
"""An example scene that uses a manually defined TexTemplate() object to create
LaTeX output in French Cursive font"""
LaTeX output in French Cursive font
"""

def construct(self):
self.add(Tex("Tex Font Example").to_edge(UL))
Expand Down
1 change: 0 additions & 1 deletion manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ def update(self, obj: ManimConfig | dict[str, Any]) -> None: # type: ignore[ove
:meth:`~ManimConfig.digest_parser`
"""

if isinstance(obj, ManimConfig):
self._d.update(obj._d)
if obj.tex_template:
Expand Down
6 changes: 3 additions & 3 deletions manim/animation/fading.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _create_faded_mobject(self, fadeIn: bool) -> Mobject:


class FadeIn(_Fade):
"""Fade in :class:`~.Mobject` s.
r"""Fade in :class:`~.Mobject` s.
Parameters
----------
Expand All @@ -119,7 +119,7 @@ def construct(self):
dot = Dot(UP * 2 + LEFT)
self.add(dot)
tex = Tex(
"FadeIn with ", "shift ", " or target\\_position", " and scale"
"FadeIn with ", "shift ", r" or target\_position", " and scale"
).scale(1)
animations = [
FadeIn(tex[0]),
Expand All @@ -142,7 +142,7 @@ def create_starting_mobject(self):


class FadeOut(_Fade):
"""Fade out :class:`~.Mobject` s.
r"""Fade out :class:`~.Mobject` s.
Parameters
----------
Expand Down
8 changes: 4 additions & 4 deletions manim/animation/indication.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def create_line_anims(self) -> Iterable[ShowPassingFlash]:


class ShowPassingFlash(ShowPartial):
"""Show only a sliver of the VMobject each frame.
r"""Show only a sliver of the VMobject each frame.
Parameters
----------
Expand All @@ -290,7 +290,7 @@ def construct(self):
self.add(p, lbl)
p = p.copy().set_color(BLUE)
for time_width in [0.2, 0.5, 1, 2]:
lbl.become(Tex(r"\\texttt{time\\_width={{%.1f}}}"%time_width))
lbl.become(Tex(r"\texttt{time\_width={{%.1f}}}"%time_width))
self.play(ShowPassingFlash(
p.copy().set_color(BLUE),
run_time=2,
Expand Down Expand Up @@ -551,7 +551,7 @@ def interpolate_submobject(


class Circumscribe(Succession):
"""Draw a temporary line surrounding the mobject.
r"""Draw a temporary line surrounding the mobject.
Parameters
----------
Expand Down Expand Up @@ -582,7 +582,7 @@ class Circumscribe(Succession):
class UsingCircumscribe(Scene):
def construct(self):
lbl = Tex(r"Circum-\\\\scribe").scale(2)
lbl = Tex(r"Circum-\\scribe").scale(2)
self.add(lbl)
self.play(Circumscribe(lbl))
self.play(Circumscribe(lbl, Circle))
Expand Down
4 changes: 1 addition & 3 deletions manim/animation/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class ComplexHomotopy(Homotopy):
def __init__(
self, complex_homotopy: Callable[[complex], float], mobject: Mobject, **kwargs
) -> None:
"""
Complex Homotopy a function Cx[0, 1] to C
"""
"""Complex Homotopy a function Cx[0, 1] to C"""

def homotopy(
x: float,
Expand Down
4 changes: 1 addition & 3 deletions manim/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ def __init__(self, mobject: Mobject, target_mobject: Mobject, **kwargs) -> None:


class TransformFromCopy(Transform):
"""
Performs a reversed Transform
"""
"""Performs a reversed Transform"""

def __init__(self, mobject: Mobject, target_mobject: Mobject, **kwargs) -> None:
super().__init__(target_mobject, mobject, **kwargs)
Expand Down
1 change: 0 additions & 1 deletion manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ def make_background_from_func(
np.array
The pixel array which can then be passed to set_background.
"""

logger.info("Starting set_background")
coords = self.get_coords_of_all_pixels()
new_background = np.apply_along_axis(coords_to_colors_func, 2, coords)
Expand Down
3 changes: 2 additions & 1 deletion manim/cli/checkhealth/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Auxiliary module for the checkhealth subcommand, contains
the actual check implementations."""
the actual check implementations.
"""

from __future__ import annotations

Expand Down
1 change: 0 additions & 1 deletion manim/cli/render/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def render(
SCENES is an optional list of scenes in the file.
"""

if args["save_as_gif"]:
logger.warning("--save_as_gif is deprecated, please use --format=gif instead!")
args["format"] = "gif"
Expand Down
4 changes: 1 addition & 3 deletions manim/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Constant definitions.
"""
"""Constant definitions."""

from __future__ import annotations

Expand Down
1 change: 0 additions & 1 deletion manim/mobject/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def aspect_ratio(self):
When set, the width is stretched to accommodate
the new aspect ratio.
"""

return self.width / self.height

@aspect_ratio.setter
Expand Down
5 changes: 2 additions & 3 deletions manim/mobject/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def get_tips(self) -> VGroup:

def get_tip(self):
"""Returns the TipableVMobject instance's (first) tip,
otherwise throws an exception."""
otherwise throws an exception.
"""
tips = self.get_tips()
if len(tips) == 0:
raise Exception("tip not found")
Expand Down Expand Up @@ -571,7 +572,6 @@ def construct(self):
group = Group(group1, group2, group3).arrange(buff=1)
self.add(group)
"""

# Ignores dim_to_match and stretch; result will always be a circle
# TODO: Perhaps create an ellipse class to handle single-dimension stretching

Expand Down Expand Up @@ -611,7 +611,6 @@ def construct(self):
self.add(circle, s1, s2)
"""

start_angle = angle_of_vector(self.points[0] - self.get_center())
proportion = (angle - start_angle) / TAU
proportion -= np.floor(proportion)
Expand Down
15 changes: 2 additions & 13 deletions manim/mobject/geometry/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def get_projection(self, point: Point3D) -> Vector3D:
point
The point to which the line is projected.
"""

start = self.get_start()
end = self.get_end()
unit_vect = normalize(end - start)
Expand Down Expand Up @@ -282,7 +281,6 @@ def _calculate_num_dashes(self) -> int:
>>> DashedLine()._calculate_num_dashes()
20
"""

# Minimum number of dashes has to be 2
return max(
2,
Expand All @@ -299,7 +297,6 @@ def get_start(self) -> Point3D:
>>> DashedLine().get_start()
array([-1., 0., 0.])
"""

if len(self.submobjects) > 0:
return self.submobjects[0].get_start()
else:
Expand All @@ -315,7 +312,6 @@ def get_end(self) -> Point3D:
>>> DashedLine().get_end()
array([1., 0., 0.])
"""

if len(self.submobjects) > 0:
return self.submobjects[-1].get_end()
else:
Expand All @@ -331,7 +327,6 @@ def get_first_handle(self) -> Point3D:
>>> DashedLine().get_first_handle()
array([-0.98333333, 0. , 0. ])
"""

return self.submobjects[0].points[1]

def get_last_handle(self) -> Point3D:
Expand All @@ -344,7 +339,6 @@ def get_last_handle(self) -> Point3D:
>>> DashedLine().get_last_handle()
array([0.98333333, 0. , 0. ])
"""

return self.submobjects[-1].points[-2]


Expand Down Expand Up @@ -605,7 +599,6 @@ def get_normal_vector(self) -> Vector3D:
>>> np.round(Arrow().get_normal_vector()) + 0. # add 0. to avoid negative 0 in output
array([ 0., 0., -1.])
"""

p0, p1, p2 = self.tip.get_start_anchors()[:3]
return normalize(np.cross(p2 - p1, p1 - p0))

Expand All @@ -625,7 +618,6 @@ def get_default_tip_length(self) -> float:
>>> Arrow().get_default_tip_length()
0.35
"""

max_ratio = self.max_tip_length_to_length_ratio
return min(self.tip_length, max_ratio * self.get_length())

Expand Down Expand Up @@ -725,7 +717,6 @@ def construct(self):
self.add(plane, vec_1, vec_2, label_1, label_2)
"""

# avoiding circular imports
from ..matrix import Matrix

Expand Down Expand Up @@ -1025,11 +1016,10 @@ def get_lines(self) -> VGroup:
>>> angle.get_lines()
VGroup(Line, Line)
"""

return VGroup(*self.lines)

def get_value(self, degrees: bool = False) -> float:
"""Get the value of an angle of the :class:`Angle` class.
r"""Get the value of an angle of the :class:`Angle` class.
Parameters
----------
Expand Down Expand Up @@ -1059,12 +1049,11 @@ def construct(self):
self.add(line1, line2, angle, value)
"""

return self.angle_value / DEGREES if degrees else self.angle_value

@staticmethod
def from_three_points(A: Point3D, B: Point3D, C: Point3D, **kwargs) -> Angle:
"""The angle between the lines AB and BC.
r"""The angle between the lines AB and BC.
This constructs the angle :math:`\\angle ABC`.
Expand Down
3 changes: 0 additions & 3 deletions manim/mobject/geometry/polygram.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def get_vertices(self) -> Point3D_Array:
[-1., -1., 0.],
[ 1., -1., 0.]])
"""

return self.get_start_anchors()

def get_vertex_groups(self) -> np.ndarray[Point3D_Array]:
Expand All @@ -129,7 +128,6 @@ def get_vertex_groups(self) -> np.ndarray[Point3D_Array]:
[-1., 1., 0.],
[-2., 0., 0.]]])
"""

vertex_groups = []

group = []
Expand Down Expand Up @@ -204,7 +202,6 @@ def construct(self):
shapes.arrange(RIGHT)
self.add(shapes)
"""

if radius == 0:
return self

Expand Down
Loading

0 comments on commit 1097ed9

Please sign in to comment.