Skip to content

Commit

Permalink
pre-commit change to ruff (#3779)
Browse files Browse the repository at this point in the history
* pre-commit change to ruff

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixes

* astral-sh ruff bump

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
JasonGrace2282 and pre-commit-ci[bot] authored May 22, 2024
1 parent 21eb0b7 commit 24025b6
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 88 deletions.
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ repos:
hooks:
- id: python-check-blanket-noqa
name: Precision flake ignores
- repo: https://github.com/psf/black
rev: 24.4.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==24.4.0]
exclude: ^\.github/
- id: ruff-format
types: [python]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion example_scenes/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def construct(self):
],
color=PURPLE_B,
fill_opacity=1,
stroke_width=0
stroke_width=0,
).shift(UP + 2 * RIGHT)
shapes = VGroup(triangle, square, circle, pentagon, pi)
self.play(SpiralIn(shapes, fade_in_fraction=0.9))
Expand Down
1 change: 0 additions & 1 deletion manim/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def tempconfig(temp: ManimConfig | dict[str, Any]) -> Generator[None, None, None
8.0
>>> with tempconfig({"frame_height": 100.0}):
... print(config["frame_height"])
...
100.0
>>> config["frame_height"]
8.0
Expand Down
9 changes: 6 additions & 3 deletions manim/_config/cli_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> Context:
theme = parser["theme"] if parser["theme"] else None
if theme is None:
formatter = HelpFormatter.settings(
theme=HelpTheme(**theme_settings), **formatter_settings # type: ignore[arg-type]
theme=HelpTheme(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
)
elif theme.lower() == "dark":
formatter = HelpFormatter.settings(
theme=HelpTheme.dark().with_(**theme_settings), **formatter_settings # type: ignore[arg-type]
theme=HelpTheme.dark().with_(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
)
elif theme.lower() == "light":
formatter = HelpFormatter.settings(
theme=HelpTheme.light().with_(**theme_settings), **formatter_settings # type: ignore[arg-type]
theme=HelpTheme.light().with_(**theme_settings),
**formatter_settings, # type: ignore[arg-type]
)

return Context.settings(
Expand Down
5 changes: 3 additions & 2 deletions manim/mobject/geometry/tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class ArrowTip(VMobject, metaclass=ConvertToOpenGL):
... RegularPolygon.__init__(self, n=5, **kwargs)
... self.width = length
... self.stretch_to_fit_height(length)
>>> arr = Arrow(np.array([-2, -2, 0]), np.array([2, 2, 0]),
... tip_shape=MyCustomArrowTip)
>>> arr = Arrow(
... np.array([-2, -2, 0]), np.array([2, 2, 0]), tip_shape=MyCustomArrowTip
... )
>>> isinstance(arr.tip, RegularPolygon)
True
>>> from manim import Scene, Create
Expand Down
3 changes: 2 additions & 1 deletion manim/mobject/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,8 @@ def expand_vertex(self, g, vertex_id: str, depth: int):
*new_edges,
vertex_config=self.VERTEX_CONF,
positions={
k: g.vertices[vertex_id].get_center() + 0.1 * DOWN for k in new_vertices
k: g.vertices[vertex_id].get_center() + 0.1 * DOWN
for k in new_vertices
},
)
if depth < self.DEPTH:
Expand Down
14 changes: 12 additions & 2 deletions manim/mobject/graphing/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ def add_coordinates(
ax = ThreeDAxes()
x_labels = range(-4, 5)
z_labels = range(-4, 4, 2)
ax.add_coordinates(x_labels, None, z_labels) # default y labels, custom x & z labels
ax.add_coordinates(
x_labels, None, z_labels
) # default y labels, custom x & z labels
ax.add_coordinates(x_labels) # only x labels
You can also specifically control the position and value of the labels using a dict.
Expand All @@ -405,7 +407,15 @@ def add_coordinates(
x_pos = [x for x in range(1, 8)]
# strings are automatically converted into a Tex mobject.
x_vals = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
x_vals = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
]
x_dict = dict(zip(x_pos, x_vals))
ax.add_coordinates(x_dict)
"""
Expand Down
8 changes: 4 additions & 4 deletions manim/mobject/graphing/number_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def number_to_point(self, number: float | np.ndarray) -> np.ndarray:
array([0., 0., 0.])
>>> number_line.number_to_point(1)
array([1., 0., 0.])
>>> number_line.number_to_point([1,2,3])
>>> number_line.number_to_point([1, 2, 3])
array([[1., 0., 0.],
[2., 0., 0.],
[3., 0., 0.]])
Expand Down Expand Up @@ -396,11 +396,11 @@ def point_to_number(self, point: Sequence[float]) -> float:
>>> from manim import NumberLine
>>> number_line = NumberLine()
>>> number_line.point_to_number((0,0,0))
>>> number_line.point_to_number((0, 0, 0))
0.0
>>> number_line.point_to_number((1,0,0))
>>> number_line.point_to_number((1, 0, 0))
1.0
>>> number_line.point_to_number([[0.5,0,0],[1,0,0],[1.5,0,0]])
>>> number_line.point_to_number([[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]])
array([0.5, 1. , 1.5])
"""
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ def get_critical_point(self, direction: Vector3D) -> Point3D:
::
sample = Arc(start_angle=PI/7, angle = PI/5)
sample = Arc(start_angle=PI / 7, angle=PI / 5)
# These are all equivalent
max_y_1 = sample.get_top()[1]
Expand Down
21 changes: 13 additions & 8 deletions manim/mobject/text/text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,17 @@ class Paragraph(VGroup):
--------
Normal usage::
paragraph = Paragraph('this is a awesome', 'paragraph',
'With \nNewlines', '\tWith Tabs',
' With Spaces', 'With Alignments',
'center', 'left', 'right')
paragraph = Paragraph(
"this is a awesome",
"paragraph",
"With \nNewlines",
"\tWith Tabs",
" With Spaces",
"With Alignments",
"center",
"left",
"right",
)
Remove unwanted invisible characters::
Expand Down Expand Up @@ -1305,15 +1312,13 @@ def add_line_to(end):
self.set_color_by_gradient(*self.gradient)
for col in colormap:
self.chars[
col["start"]
- col["start_offset"] : col["end"]
col["start"] - col["start_offset"] : col["end"]
- col["start_offset"]
- col["end_offset"]
].set_color(self._parse_color(col["color"]))
for grad in gradientmap:
self.chars[
grad["start"]
- grad["start_offset"] : grad["end"]
grad["start"] - grad["start_offset"] : grad["end"]
- grad["start_offset"]
- grad["end_offset"]
].set_color_by_gradient(
Expand Down
24 changes: 13 additions & 11 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,19 +1926,21 @@ class VGroup(VMobject, metaclass=ConvertToOpenGL):
>>> triangle, square = Triangle(), Square()
>>> vg.add(triangle)
VGroup(Triangle)
>>> vg + square # a new VGroup is constructed
>>> vg + square # a new VGroup is constructed
VGroup(Triangle, Square)
>>> vg # not modified
>>> vg # not modified
VGroup(Triangle)
>>> vg += square; vg # modifies vg
>>> vg += square
>>> vg # modifies vg
VGroup(Triangle, Square)
>>> vg.remove(triangle)
VGroup(Square)
>>> vg - square; # a new VGroup is constructed
>>> vg - square # a new VGroup is constructed
VGroup()
>>> vg # not modified
>>> vg # not modified
VGroup(Square)
>>> vg -= square; vg # modifies vg
>>> vg -= square
>>> vg # modifies vg
VGroup()
.. manim:: ArcShapeIris
Expand Down Expand Up @@ -2200,7 +2202,7 @@ def add(
Normal usage::
square_obj = Square()
my_dict.add([('s', square_obj)])
my_dict.add([("s", square_obj)])
"""
for key, value in dict(mapping_or_iterable).items():
self.add_key_value_pair(key, value)
Expand All @@ -2227,7 +2229,7 @@ def remove(self, key: Hashable) -> Self:
--------
Normal usage::
my_dict.remove('square')
my_dict.remove("square")
"""
if key not in self.submob_dict:
raise KeyError("The given key '%s' is not present in the VDict" % str(key))
Expand All @@ -2252,7 +2254,7 @@ def __getitem__(self, key: Hashable):
--------
Normal usage::
self.play(Create(my_dict['s']))
self.play(Create(my_dict["s"]))
"""
submob = self.submob_dict[key]
return submob
Expand All @@ -2276,7 +2278,7 @@ def __setitem__(self, key: Hashable, value: VMobject) -> None:
Normal usage::
square_obj = Square()
my_dict['sq'] = square_obj
my_dict["sq"] = square_obj
"""
if key in self.submob_dict:
self.remove(key)
Expand Down Expand Up @@ -2381,7 +2383,7 @@ def add_key_value_pair(self, key: Hashable, value: VMobject) -> None:
Normal usage::
square_obj = Square()
self.add_key_value_pair('s', square_obj)
self.add_key_value_pair("s", square_obj)
"""
self._assert_valid_submobjects([value])
Expand Down
3 changes: 1 addition & 2 deletions manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,8 +1555,7 @@ def construct(self):
# second option: within the call to Scene.play
self.play(
Transform(square, circle),
subcaption="The square transforms."
Transform(square, circle), subcaption="The square transforms."
)
"""
Expand Down
1 change: 0 additions & 1 deletion manim/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,6 @@ def combine_to_movie(self):
av.open(movie_file_path) as video_input,
av.open(sound_file_path) as audio_input,
):

video_stream = video_input.streams.video[0]
audio_stream = audio_input.streams.audio[0]
output_container = av.open(
Expand Down
1 change: 1 addition & 0 deletions manim/utils/color/X11.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
.. automanimcolormodule:: manim.utils.color.X11
"""

from .core import ManimColor

ALICEBLUE = ManimColor("#F0F8FF")
Expand Down
3 changes: 2 additions & 1 deletion manim/utils/color/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def __init__(
else:
if length == 3:
self._internal_value = ManimColor._internal_from_int_rgb(
value, alpha # type: ignore
value,
alpha, # type: ignore
)
elif length == 4:
self._internal_value = ManimColor._internal_from_int_rgba(value) # type: ignore
Expand Down
Loading

0 comments on commit 24025b6

Please sign in to comment.