Skip to content

Commit

Permalink
feat(cli): add render command as alias to manim render (#317)
Browse files Browse the repository at this point in the history
* feat(cli): add render command as alias to `manim render`

* feat(cli): add render command as alias to `manim render`

* chore(test): add test

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

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

* chore(lib): simplify how ManimGL rendering is called

* chore(lib): test

* chore(ci): try identify error

* wip

* chore(test): add result output

* try: checkout

* Revert "try: checkout"

This reverts commit 60985f0.

* fix(deps): don't update lock

* chore(lib): simplify code and improve usage

* chore(cli): better cli

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

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

* fix: does this fix?

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jeertmans and pre-commit-ci[bot] authored Nov 22, 2023
1 parent 891273b commit ce799ae
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 199 deletions.
14 changes: 5 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@ repos:
- id: pretty-format-toml
exclude: poetry.lock
args: [--autofix]
- repo: https://github.com/psf/black
rev: 23.11.0
- repo: https://github.com/keewis/blackdoc
rev: v0.3.9
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==23.9.1
- id: blackdoc
additional_dependencies: [black==23.10.1]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added the `--hide-info-window` option to `manim-slides present`.
[#313](https://github.com/jeertmans/manim-slides/pull/313)
- Added the `manim-slides render` command
to render slides using correct Manim installation.
[#317](https://github.com/jeertmans/manim-slides/pull/317)

## [v5](https://github.com/jeertmans/manim-slides/compare/v4.16.0...v5.0.0)

Expand Down
6 changes: 3 additions & 3 deletions docs/source/reference/magic_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
" Text(\"Press\"),\n",
" Text(\"and\"),\n",
" Text(\"loop\"),\n",
" ).arrange(DOWN, buff=1.)\n",
" \n",
" ).arrange(DOWN, buff=1.0)\n",
"\n",
" self.play(Write(text))\n",
" self.next_slide(loop=True)\n",
" self.play(Indicate(text[-1], scale_factor=2., run_time=.5))\n",
" self.play(Indicate(text[-1], scale_factor=2.0, run_time=0.5))\n",
" self.next_slide()\n",
" self.play(FadeOut(text))"
]
Expand Down
2 changes: 2 additions & 0 deletions manim_slides/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .convert import convert
from .logger import logger
from .present import list_scenes, present
from .render import render
from .wizard import init, wizard


Expand Down Expand Up @@ -67,6 +68,7 @@ def cli(notify_outdated_version: bool) -> None:
cli.add_command(init)
cli.add_command(list_scenes)
cli.add_command(present)
cli.add_command(render)
cli.add_command(wizard)

if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions manim_slides/docs/manim_slides_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def construct(self):
>>> class DirectiveDoctestExample(Slide):
... def construct(self):
... self.play(Create(dot))
...
A third application is to render scenes from another specific file::
Expand Down
54 changes: 54 additions & 0 deletions manim_slides/render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Alias command to either
``manim render [OPTIONS] [ARGS]...`` or
``manimgl [OPTIONS] [ARGS]...``.
This is especially useful for two reasons:
1. You can are sure to execute the rendering command with the same Python environment
as for ``manim-slides``.
2. You can pass options to the config.
"""

import subprocess
import sys
from typing import Tuple

import click


@click.command(
context_settings=dict(
ignore_unknown_options=True, allow_extra_args=True, help_option_names=("-h",)
),
options_metavar="[-h] [--CE|--GL]",
)
@click.option(
"--CE",
is_flag=True,
envvar="MANIM_RENDERER",
show_envvar=True,
help="If set, use Manim Community Edition (CE) renderer. "
"If this or --GL is not set, default to CE renderer.",
)
@click.option(
"--GL",
is_flag=True,
envvar="MANIMGL_RENDERER",
show_envvar=True,
help="If set, use ManinGL renderer.",
)
@click.argument("args", metavar="[RENDERER_ARGS]...", nargs=-1, type=click.UNPROCESSED)
def render(ce: bool, gl: bool, args: Tuple[str, ...]) -> None:
"""
Render SCENE(s) from the input FILE, using the specified renderer.
Use 'manim-slides render --help' to see help information for
a the specified renderer.
"""
if ce and gl:
raise click.UsageError("You cannot specify both --CE and --GL renderers.")
if gl:
subprocess.run([sys.executable, "-m", "manimlib", *args])
else:
subprocess.run([sys.executable, "-m", "manim", "render", *args])
4 changes: 3 additions & 1 deletion manim_slides/slide/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def mobjects_without_canvas(self) -> Sequence[Mobject]:
the canvas.
"""
return [
mobject for mobject in self.mobjects if mobject not in self.canvas_mobjects # type: ignore[attr-defined]
mobject
for mobject in self.mobjects # type: ignore[attr-defined]
if mobject not in self.canvas_mobjects
]

@property
Expand Down
184 changes: 27 additions & 157 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ sphinx-directive = ["docutils", "manim"]
optional = true

[tool.poetry.group.dev.dependencies]
black = "^22.10.0"
bump2version = "^1.0.1"
isort = "^5.12.0"
mypy = "^0.991"
pre-commit = "^3.0.2"
ruff = "^0.0.219"

[tool.poetry.group.docs]
optional = true
Expand Down Expand Up @@ -137,6 +133,7 @@ extend-ignore = [
"D212",
"E501"
]
extend-include = ["*.ipynb"]
extend-select = ["B", "C90", "D", "I", "N", "RUF", "UP", "T"]
isort = {known-first-party = ['manim_slides', 'tests']}
line-length = 88
Expand Down
35 changes: 10 additions & 25 deletions tests/test_slide.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import random
import shutil
import subprocess
import sys
from pathlib import Path

import click
import pytest
from click.testing import CliRunner
from manim import (
Expand All @@ -20,37 +17,23 @@
GrowFromCenter,
Text,
)
from manim.__main__ import main as manim_cli
from pydantic import ValidationError

from manim_slides.config import PresentationConfig
from manim_slides.defaults import FOLDER_PATH
from manim_slides.render import render
from manim_slides.slide.manim import Slide


@click.command(
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
)
)
@click.pass_context
def manimgl_cli(ctx: click.Context) -> None:
subprocess.run([sys.executable, "-m", "manimlib", *ctx.args])


cli = pytest.mark.parametrize(
["cli"],
@pytest.mark.parametrize(
"renderer",
[
[manim_cli],
[manimgl_cli],
"--CE",
"--GL",
],
)


@cli
def test_render_basic_slide(
cli: click.Command,
renderer: str,
slides_file: Path,
presentation_config: PresentationConfig,
manimgl_config: Path,
Expand All @@ -59,9 +42,11 @@ def test_render_basic_slide(

with runner.isolated_filesystem() as tmp_dir:
shutil.copy(manimgl_config, tmp_dir)
results = runner.invoke(cli, [str(slides_file), "BasicSlide", "-ql"])
results = runner.invoke(
render, [renderer, str(slides_file), "BasicSlide", "-ql"]
)

assert results.exit_code == 0
assert results.exit_code == 0, results

local_slides_folder = (Path(tmp_dir) / "slides").resolve(strict=True)

Expand Down

0 comments on commit ce799ae

Please sign in to comment.