Skip to content

Commit 02391d7

Browse files
chopan050MrDiverpre-commit-ci[bot]JasonGrace2282
authored
Added support for Manim type aliases in Sphinx docs + Added new TypeAliases (#3484)
* Updated manim.typing and included TypeAliases in docs.source.conf * Added Vector2 and reorganized manim_type_aliases * Fixed __all__ exports for __all__ of manim * Update manim/cli/render/global_options.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Draft of new typing docs and new autotyping directive * Changed vertical bars to Unions * Updated poetry.lock * Created custom file parser for manim.typing * Got reST parser going * Updated autotyping and parsing * Update parsing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added code_block toggle * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added typings to directives * Renamed Tuple to tuple in manim.typings * Added missing docs for type aliases * Fixed exponent typo in ManimInt * Hyperlinks to types work - removed Module Attributes section * Removed Unused Import Remove ``import re`` * Added freeglut-devel to workflows for Linux Hopefully (?) fix the GLU import error * Fix package name * Add support for Type Aliases section in every module - Renaming of Vector types * Add/fix docs for directive, parser and others * Fixed alias typo in module_parsing * Fix decode/import bugs, fix minor details in docs * Added missing docs for utils.docbuild and utils.testing * Sort alphabetically entries in utilities_misc.rst * Address review comments, add notes about Vector and hyperlinks inside definition blocks --------- Co-authored-by: MrDiver <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: JasonGrace2282 <[email protected]>
1 parent 4a963c4 commit 02391d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1992
-888
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
if: runner.os == 'Linux'
6161
uses: awalsh128/cache-apt-pkgs-action@latest
6262
with:
63-
packages: python3-opengl libpango1.0-dev xvfb
63+
packages: python3-opengl libpango1.0-dev xvfb freeglut3-dev
6464
version: 1.0
6565

6666
- name: Install Texlive (Linux)

docs/source/_templates/autosummary/module.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44

55
.. automodule:: {{ fullname }}
66

7-
{% block attributes %}
8-
{% if attributes %}
9-
.. rubric:: Module Attributes
10-
11-
.. autosummary::
12-
{% for item in attributes %}
13-
{{ item }}
14-
{%- endfor %}
15-
{% endif %}
16-
{% endblock %}
7+
{# SEE manim.utils.docbuild.autoaliasattr_directive #}
8+
{# FOR INFORMATION ABOUT THE CUSTOM autoaliasattr DIRECTIVE! #}
9+
.. autoaliasattr:: {{ fullname }}
1710

1811
{% block classes %}
1912
{% if classes %}

docs/source/conf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pathlib import Path
1212

1313
import manim
14+
from manim.utils.docbuild.module_parsing import parse_module_attributes
1415

1516
# -- Path setup --------------------------------------------------------------
1617
# If extensions (or modules to document with autodoc) are in another directory,
@@ -44,6 +45,7 @@
4445
"sphinxext.opengraph",
4546
"manim.utils.docbuild.manim_directive",
4647
"manim.utils.docbuild.autocolor_directive",
48+
"manim.utils.docbuild.autoaliasattr_directive",
4749
"sphinx.ext.graphviz",
4850
"sphinx.ext.inheritance_diagram",
4951
"sphinxcontrib.programoutput",
@@ -54,7 +56,14 @@
5456
autosummary_generate = True
5557

5658
# generate documentation from type hints
59+
ALIAS_DOCS_DICT = parse_module_attributes()[0]
5760
autodoc_typehints = "description"
61+
autodoc_type_aliases = {
62+
alias_name: f"~manim.{module}.{alias_name}"
63+
for module, module_dict in ALIAS_DOCS_DICT.items()
64+
for category_dict in module_dict.values()
65+
for alias_name in category_dict.keys()
66+
}
5867
autoclass_content = "both"
5968

6069
# controls whether functions documented by the autofunction directive

docs/source/contributing/development.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ Develop your contribution
159159
As far as development on your local machine goes, these are the main steps you
160160
should follow.
161161

162+
.. _polishing-changes-and-submitting-a-pull-request:
163+
162164
Polishing Changes and Submitting a Pull Request
163165
-----------------------------------------------
164166

docs/source/reference_index/utilities_misc.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@ Module Index
99
.. autosummary::
1010
:toctree: ../reference
1111

12-
constants
1312
~utils.bezier
1413
~utils.color
1514
~utils.commands
1615
~utils.config_ops
17-
~utils.deprecation
16+
constants
1817
~utils.debug
18+
~utils.deprecation
1919
~utils.docbuild
2020
~utils.hashing
21-
~utils.ipython_magic
2221
~utils.images
22+
~utils.ipython_magic
2323
~utils.iterables
2424
~utils.paths
2525
~utils.rate_functions
2626
~utils.simple_functions
2727
~utils.sounds
2828
~utils.space_ops
29+
~utils.testing
2930
~utils.tex
30-
~utils.tex_templates
3131
~utils.tex_file_writing
32+
~utils.tex_templates
33+
typing

manim/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .utils.commands import *
1717

1818
# isort: on
19+
import numpy as np
1920

2021
from .animation.animation import *
2122
from .animation.changing import *

manim/_config/cli_colors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from cloup import Context, HelpFormatter, HelpTheme, Style
66

7+
__all__ = ["parse_cli_ctx"]
8+
79

810
def parse_cli_ctx(parser: configparser.SectionProxy) -> Context:
911
formatter_settings: dict[str, str | int] = {

manim/_config/logger_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
if TYPE_CHECKING:
2727
from pathlib import Path
2828

29+
__all__ = ["make_logger", "parse_theme", "set_file_logger", "JSONFormatter"]
30+
2931
HIGHLIGHTED_KEYWORDS = [ # these keywords are highlighted specially
3032
"Played",
3133
"animations",

manim/_config/utils.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@
2020
import re
2121
import sys
2222
from collections.abc import Mapping, MutableMapping
23-
from enum import EnumMeta
2423
from pathlib import Path
25-
from typing import Any, ClassVar, Iterable, Iterator, NoReturn
24+
from typing import TYPE_CHECKING, Any, ClassVar, Iterable, Iterator, NoReturn
2625

2726
import numpy as np
28-
from typing_extensions import Self
2927

30-
from .. import constants
31-
from ..constants import RendererType
32-
from ..typing import StrPath, Vector3
33-
from ..utils.color import ManimColor
34-
from ..utils.tex import TexTemplate, TexTemplateFromFile
28+
from manim import constants
29+
from manim.constants import RendererType
30+
from manim.utils.color import ManimColor
31+
from manim.utils.tex import TexTemplate, TexTemplateFromFile
32+
33+
if TYPE_CHECKING:
34+
from enum import EnumMeta
35+
36+
from typing_extensions import Self
37+
38+
from manim.typing import StrPath, Vector3D
39+
40+
__all__ = ["config_file_paths", "make_config_parser", "ManimConfig", "ManimFrame"]
3541

3642

3743
def config_file_paths() -> list[Path]:
@@ -1145,22 +1151,22 @@ def frame_x_radius(self, value: float) -> None:
11451151
)
11461152

11471153
@property
1148-
def top(self) -> Vector3:
1154+
def top(self) -> Vector3D:
11491155
"""Coordinate at the center top of the frame."""
11501156
return self.frame_y_radius * constants.UP
11511157

11521158
@property
1153-
def bottom(self) -> Vector3:
1159+
def bottom(self) -> Vector3D:
11541160
"""Coordinate at the center bottom of the frame."""
11551161
return self.frame_y_radius * constants.DOWN
11561162

11571163
@property
1158-
def left_side(self) -> Vector3:
1164+
def left_side(self) -> Vector3D:
11591165
"""Coordinate at the middle left of the frame."""
11601166
return self.frame_x_radius * constants.LEFT
11611167

11621168
@property
1163-
def right_side(self) -> Vector3:
1169+
def right_side(self) -> Vector3D:
11641170
"""Coordinate at the middle right of the frame."""
11651171
return self.frame_x_radius * constants.RIGHT
11661172

@@ -1801,7 +1807,7 @@ class ManimFrame(Mapping):
18011807
"left_side",
18021808
"right_side",
18031809
}
1804-
_CONSTANTS: ClassVar[dict[str, Vector3]] = {
1810+
_CONSTANTS: ClassVar[dict[str, Vector3D]] = {
18051811
"UP": np.array((0.0, 1.0, 0.0)),
18061812
"DOWN": np.array((0.0, -1.0, 0.0)),
18071813
"RIGHT": np.array((1.0, 0.0, 0.0)),

manim/animation/speedmodifier.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from ..mobject.mobject import Mobject, Updater, _AnimationBuilder
1414
from ..scene.scene import Scene
1515

16+
__all__ = ["ChangeSpeed"]
17+
1618

1719
class ChangeSpeed(Animation):
1820
"""Modifies the speed of passed animation.

0 commit comments

Comments
 (0)