Skip to content
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

Added support for Manim type aliases in Sphinx docs + Added new TypeAliases #3484

Merged
merged 38 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
93e4cbc
Updated manim.typing and included TypeAliases in docs.source.conf
chopan050 Dec 1, 2023
74448bb
Added Vector2 and reorganized manim_type_aliases
chopan050 Dec 2, 2023
10b8d1a
Merge branch 'main' into typing_update
chopan050 Dec 2, 2023
a32b7a7
Fixed __all__ exports for __all__ of manim
MrDiver Dec 10, 2023
762df44
Merge branch 'main' into typing_update
MrDiver Dec 10, 2023
9f9e98f
Update manim/cli/render/global_options.py
MrDiver Dec 10, 2023
5d1b375
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 10, 2023
5f582bc
Draft of new typing docs and new autotyping directive
chopan050 Dec 20, 2023
ed00abc
Merge branch 'main' into typing_update
chopan050 Dec 20, 2023
5dc5e0c
Changed vertical bars to Unions
chopan050 Dec 20, 2023
232df18
Updated poetry.lock
chopan050 Dec 20, 2023
dacc639
Created custom file parser for manim.typing
chopan050 Dec 22, 2023
cd85655
??? What is going on
JasonGrace2282 Dec 23, 2023
1710faf
Got reST parser going
JasonGrace2282 Dec 23, 2023
3764d74
Updated autotyping and parsing
JasonGrace2282 Dec 23, 2023
9d65c9f
Update parsing
JasonGrace2282 Dec 24, 2023
1425388
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 24, 2023
1d50503
Added code_block toggle
JasonGrace2282 Dec 24, 2023
8d8e07a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 24, 2023
a31c697
Added typings to directives
chopan050 Dec 24, 2023
b1dee77
Renamed Tuple to tuple in manim.typings
chopan050 Dec 24, 2023
4e78940
Added missing docs for type aliases
chopan050 Dec 26, 2023
9fca6ed
Fixed exponent typo in ManimInt
chopan050 Dec 26, 2023
e56b793
Hyperlinks to types work - removed Module Attributes section
chopan050 Dec 27, 2023
04fc997
Merge branch 'main' into typing_update
chopan050 Dec 27, 2023
67f902e
Removed Unused Import
JasonGrace2282 Dec 27, 2023
7580490
Added freeglut-devel to workflows for Linux
JasonGrace2282 Dec 27, 2023
8f2391a
Fix package name
JasonGrace2282 Dec 27, 2023
86f9760
Add support for Type Aliases section in every module - Renaming of Ve…
chopan050 Dec 27, 2023
f6b80b6
Merge branch 'typing_update' of https://github.com/chopan050/manim in…
chopan050 Dec 27, 2023
3ccfee1
Add/fix docs for directive, parser and others
chopan050 Dec 27, 2023
1a8016b
Fixed alias typo in module_parsing
chopan050 Dec 27, 2023
f2dd4bf
Fix decode/import bugs, fix minor details in docs
chopan050 Dec 27, 2023
be40a7d
Added missing docs for utils.docbuild and utils.testing
chopan050 Dec 28, 2023
1980e7b
Sort alphabetically entries in utilities_misc.rst
chopan050 Dec 28, 2023
50717f6
Merge branch 'main' into typing_update
chopan050 Dec 28, 2023
600e616
Address review comments, add notes about Vector and hyperlinks inside…
chopan050 Dec 29, 2023
2599360
Merge branch 'typing_update' of https://github.com/chopan050/manim in…
chopan050 Dec 29, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
if: runner.os == 'Linux'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: python3-opengl libpango1.0-dev xvfb
packages: python3-opengl libpango1.0-dev xvfb freeglut3-dev
version: 1.0

- name: Install Texlive (Linux)
Expand Down
13 changes: 3 additions & 10 deletions docs/source/_templates/autosummary/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes

.. autosummary::
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
{# SEE manim.utils.docbuild.autoaliasattr_directive #}
{# FOR INFORMATION ABOUT THE CUSTOM autoaliasattr DIRECTIVE! #}
.. autoaliasattr:: {{ fullname }}

{% block classes %}
{% if classes %}
Expand Down
9 changes: 9 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path

import manim
from manim.utils.docbuild.module_parsing import parse_module_attributes

# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -44,6 +45,7 @@
"sphinxext.opengraph",
"manim.utils.docbuild.manim_directive",
"manim.utils.docbuild.autocolor_directive",
"manim.utils.docbuild.autoaliasattr_directive",
"sphinx.ext.graphviz",
"sphinx.ext.inheritance_diagram",
"sphinxcontrib.programoutput",
Expand All @@ -54,7 +56,14 @@
autosummary_generate = True

# generate documentation from type hints
ALIAS_DOCS_DICT = parse_module_attributes()[0]
autodoc_typehints = "description"
autodoc_type_aliases = {
alias_name: f"~manim.{module}.{alias_name}"
for module, module_dict in ALIAS_DOCS_DICT.items()
for category_dict in module_dict.values()
for alias_name in category_dict.keys()
}
autoclass_content = "both"

# controls whether functions documented by the autofunction directive
Expand Down
2 changes: 2 additions & 0 deletions docs/source/contributing/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Develop your contribution
As far as development on your local machine goes, these are the main steps you
should follow.

.. _polishing-changes-and-submitting-a-pull-request:

Polishing Changes and Submitting a Pull Request
-----------------------------------------------

Expand Down
10 changes: 6 additions & 4 deletions docs/source/reference_index/utilities_misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ Module Index
.. autosummary::
:toctree: ../reference

constants
~utils.bezier
~utils.color
~utils.commands
~utils.config_ops
~utils.deprecation
constants
~utils.debug
~utils.deprecation
~utils.docbuild
~utils.hashing
~utils.ipython_magic
~utils.images
~utils.ipython_magic
~utils.iterables
~utils.paths
~utils.rate_functions
~utils.simple_functions
~utils.sounds
~utils.space_ops
~utils.testing
~utils.tex
~utils.tex_templates
~utils.tex_file_writing
~utils.tex_templates
typing
1 change: 1 addition & 0 deletions manim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .utils.commands import *

# isort: on
import numpy as np

from .animation.animation import *
from .animation.changing import *
Expand Down
2 changes: 2 additions & 0 deletions manim/_config/cli_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from cloup import Context, HelpFormatter, HelpTheme, Style

__all__ = ["parse_cli_ctx"]


def parse_cli_ctx(parser: configparser.SectionProxy) -> Context:
formatter_settings: dict[str, str | int] = {
Expand Down
2 changes: 2 additions & 0 deletions manim/_config/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
if TYPE_CHECKING:
from pathlib import Path

__all__ = ["make_logger", "parse_theme", "set_file_logger", "JSONFormatter"]

HIGHLIGHTED_KEYWORDS = [ # these keywords are highlighted specially
"Played",
"animations",
Expand Down
32 changes: 19 additions & 13 deletions manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@
import re
import sys
from collections.abc import Mapping, MutableMapping
from enum import EnumMeta
from pathlib import Path
from typing import Any, ClassVar, Iterable, Iterator, NoReturn
from typing import TYPE_CHECKING, Any, ClassVar, Iterable, Iterator, NoReturn

import numpy as np
from typing_extensions import Self

from .. import constants
from ..constants import RendererType
from ..typing import StrPath, Vector3
from ..utils.color import ManimColor
from ..utils.tex import TexTemplate, TexTemplateFromFile
from manim import constants
from manim.constants import RendererType
from manim.utils.color import ManimColor
from manim.utils.tex import TexTemplate, TexTemplateFromFile

if TYPE_CHECKING:
from enum import EnumMeta

chopan050 marked this conversation as resolved.
Show resolved Hide resolved
from typing_extensions import Self

chopan050 marked this conversation as resolved.
Show resolved Hide resolved
from manim.typing import StrPath, Vector3D

__all__ = ["config_file_paths", "make_config_parser", "ManimConfig", "ManimFrame"]


def config_file_paths() -> list[Path]:
Expand Down Expand Up @@ -1145,22 +1151,22 @@ def frame_x_radius(self, value: float) -> None:
)

@property
def top(self) -> Vector3:
def top(self) -> Vector3D:
"""Coordinate at the center top of the frame."""
return self.frame_y_radius * constants.UP

@property
def bottom(self) -> Vector3:
def bottom(self) -> Vector3D:
"""Coordinate at the center bottom of the frame."""
return self.frame_y_radius * constants.DOWN

@property
def left_side(self) -> Vector3:
def left_side(self) -> Vector3D:
"""Coordinate at the middle left of the frame."""
return self.frame_x_radius * constants.LEFT

@property
def right_side(self) -> Vector3:
def right_side(self) -> Vector3D:
"""Coordinate at the middle right of the frame."""
return self.frame_x_radius * constants.RIGHT

Expand Down Expand Up @@ -1801,7 +1807,7 @@ class ManimFrame(Mapping):
"left_side",
"right_side",
}
_CONSTANTS: ClassVar[dict[str, Vector3]] = {
_CONSTANTS: ClassVar[dict[str, Vector3D]] = {
"UP": np.array((0.0, 1.0, 0.0)),
"DOWN": np.array((0.0, -1.0, 0.0)),
"RIGHT": np.array((1.0, 0.0, 0.0)),
Expand Down
2 changes: 2 additions & 0 deletions manim/animation/speedmodifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from ..mobject.mobject import Mobject, Updater, _AnimationBuilder
from ..scene.scene import Scene

__all__ = ["ChangeSpeed"]


class ChangeSpeed(Animation):
"""Modifies the speed of passed animation.
Expand Down
11 changes: 11 additions & 0 deletions manim/cli/cfg/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
"""
RICH_NON_STYLE_ENTRIES: str = ["log.width", "log.height", "log.timestamps"]

__all__ = [
"value_from_string",
"value_from_string",
"is_valid_style",
"replace_keys",
"cfg",
"write",
"show",
"export",
]


def value_from_string(value: str) -> str | int | bool:
"""Extracts the literal of proper datatype from a string.
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/checkhealth/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from ..._config import config

__all__ = ["HEALTH_CHECKS"]

HEALTH_CHECKS = []


Expand Down
2 changes: 2 additions & 0 deletions manim/cli/checkhealth/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from .checks import HEALTH_CHECKS

__all__ = ["checkhealth"]


@cloup.command(
context_settings=None,
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/init/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"resolution": (854, 480),
}

__all__ = ["select_resolution", "update_cfg", "project", "scene"]


def select_resolution():
"""Prompts input of type click.Choice from user. Presents options from QUALITIES constant.
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/plugins/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from ...constants import CONTEXT_SETTINGS, EPILOG
from ...plugins.plugins_flags import list_plugins

__all__ = ["plugins"]


@cloup.command(
context_settings=CONTEXT_SETTINGS,
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/render/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from .output_options import output_options
from .render_options import render_options

__all__ = ["render"]


@cloup.command(
context_settings=None,
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/render/ease_of_access_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from cloup import Choice, option, option_group

__all__ = ["ease_of_access_options"]

ease_of_access_options = option_group(
"Ease of access options",
option(
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/render/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from ... import logger

__all__ = ["global_options"]


def validate_gui_location(ctx, param, value):
if value:
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/render/output_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from cloup import IntRange, Path, option, option_group

__all__ = ["output_options"]

output_options = option_group(
"Output options",
option(
Expand Down
2 changes: 2 additions & 0 deletions manim/cli/render/render_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from ... import logger

__all__ = ["render_options"]


def validate_scene_range(ctx, param, value):
try:
Expand Down
30 changes: 15 additions & 15 deletions manim/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from cloup import Context
from PIL.Image import Resampling

from manim.typing import Vector3
from manim.typing import Vector3D

__all__ = [
"SCENE_NOT_FOUND_MESSAGE",
Expand Down Expand Up @@ -123,43 +123,43 @@
}

# Geometry: directions
ORIGIN: Vector3 = np.array((0.0, 0.0, 0.0))
ORIGIN: Vector3D = np.array((0.0, 0.0, 0.0))
"""The center of the coordinate system."""

UP: Vector3 = np.array((0.0, 1.0, 0.0))
UP: Vector3D = np.array((0.0, 1.0, 0.0))
"""One unit step in the positive Y direction."""

DOWN: Vector3 = np.array((0.0, -1.0, 0.0))
DOWN: Vector3D = np.array((0.0, -1.0, 0.0))
"""One unit step in the negative Y direction."""

RIGHT: Vector3 = np.array((1.0, 0.0, 0.0))
RIGHT: Vector3D = np.array((1.0, 0.0, 0.0))
"""One unit step in the positive X direction."""

LEFT: Vector3 = np.array((-1.0, 0.0, 0.0))
LEFT: Vector3D = np.array((-1.0, 0.0, 0.0))
"""One unit step in the negative X direction."""

IN: Vector3 = np.array((0.0, 0.0, -1.0))
IN: Vector3D = np.array((0.0, 0.0, -1.0))
"""One unit step in the negative Z direction."""

OUT: Vector3 = np.array((0.0, 0.0, 1.0))
OUT: Vector3D = np.array((0.0, 0.0, 1.0))
"""One unit step in the positive Z direction."""

# Geometry: axes
X_AXIS: Vector3 = np.array((1.0, 0.0, 0.0))
Y_AXIS: Vector3 = np.array((0.0, 1.0, 0.0))
Z_AXIS: Vector3 = np.array((0.0, 0.0, 1.0))
X_AXIS: Vector3D = np.array((1.0, 0.0, 0.0))
Y_AXIS: Vector3D = np.array((0.0, 1.0, 0.0))
Z_AXIS: Vector3D = np.array((0.0, 0.0, 1.0))

# Geometry: useful abbreviations for diagonals
UL: Vector3 = UP + LEFT
UL: Vector3D = UP + LEFT
"""One step up plus one step left."""

UR: Vector3 = UP + RIGHT
UR: Vector3D = UP + RIGHT
"""One step up plus one step right."""

DL: Vector3 = DOWN + LEFT
DL: Vector3D = DOWN + LEFT
"""One step down plus one step left."""

DR: Vector3 = DOWN + RIGHT
DR: Vector3D = DOWN + RIGHT
"""One step down plus one step right."""

# Geometry
Expand Down
2 changes: 2 additions & 0 deletions manim/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from .. import __version__, config
from ..utils.module_ops import scene_classes_from_file

__all__ = ["configure_pygui"]

if dearpygui_imported:
dpg.create_context()
window = dpg.generate_uuid()
Expand Down
Loading
Loading