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

Update dependency constraints, fix deprecation warnings #3376

Merged
merged 15 commits into from
Dec 6, 2023
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Install Poetry
run: |
pipx install "poetry==1.5.*"
pipx install "poetry==1.7.*"
poetry config virtualenvs.prefer-active-python true

- name: Setup Python ${{ matrix.python }}
Expand Down
8 changes: 2 additions & 6 deletions manim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env python


from __future__ import annotations

import pkg_resources

__version__: str = pkg_resources.get_distribution(__name__).version
from importlib.metadata import version

__version__ = version(__name__)

import sys

# isort: off

Expand Down
5 changes: 2 additions & 3 deletions manim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import sys

import click
import cloup

from . import __version__, cli_ctx_settings, console
Expand Down Expand Up @@ -35,15 +34,15 @@ def exit_early(ctx, param, value):
"is specified. Run 'manim render --help' if you would like to know what the "
f"'-ql' or '-p' flags do, for example.\n\n{EPILOG}",
)
@click.option(
@cloup.option(
"--version",
is_flag=True,
help="Show version and exit.",
callback=exit_early,
is_eager=True,
expose_value=False,
)
@click.pass_context
@cloup.pass_context
def main(ctx):
"""The entry point for manim."""
pass
Expand Down
4 changes: 2 additions & 2 deletions manim/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,8 @@ def display_image_mobject(
sub_image = Image.fromarray(image_mobject.get_pixel_array(), mode="RGBA")

# Reshape
pixel_width = max(int(pdist([ul_coords, ur_coords])), 1)
pixel_height = max(int(pdist([ul_coords, dl_coords])), 1)
pixel_width = max(int(pdist([ul_coords, ur_coords]).item()), 1)
pixel_height = max(int(pdist([ul_coords, dl_coords]).item()), 1)
sub_image = sub_image.resize(
(pixel_width, pixel_height),
resample=image_mobject.resampling_algorithm,
Expand Down
14 changes: 6 additions & 8 deletions manim/cli/cfg/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
"""
from __future__ import annotations

import os
from ast import literal_eval
from pathlib import Path

import click
import cloup
from rich.errors import StyleSyntaxError
from rich.style import Style
Expand Down Expand Up @@ -123,21 +121,21 @@ def replace_keys(default: dict) -> dict:
epilog=EPILOG,
help="Manages Manim configuration files.",
)
@click.pass_context
@cloup.pass_context
def cfg(ctx):
"""Responsible for the cfg subcommand."""
pass


@cfg.command(context_settings=cli_ctx_settings, no_args_is_help=True)
@click.option(
@cloup.option(
"-l",
"--level",
type=click.Choice(["user", "cwd"], case_sensitive=False),
type=cloup.Choice(["user", "cwd"], case_sensitive=False),
default="cwd",
help="Specify if this config is for user or the working directory.",
)
@click.option("-o", "--open", "openfile", is_flag=True)
@cloup.option("-o", "--open", "openfile", is_flag=True)
def write(level: str = None, openfile: bool = False) -> None:
config_paths = config_file_paths()
console.print(
Expand Down Expand Up @@ -258,8 +256,8 @@ def show():


@cfg.command(context_settings=cli_ctx_settings)
@click.option("-d", "--directory", default=Path.cwd())
@click.pass_context
@cloup.option("-d", "--directory", default=Path.cwd())
@cloup.pass_context
def export(ctx, directory):
directory_path = Path(directory)
if directory_path.absolute == Path.cwd().absolute:
Expand Down
17 changes: 12 additions & 5 deletions manim/cli/default_group.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
"""DefaultGroup allows a subcommand to act as the main command
"""``DefaultGroup`` allows a subcommand to act as the main command.

In particular, this class is what allows ``manim`` to act as ``manim render``.

.. note::
This is a vendored version of https://github.com/click-contrib/click-default-group/
under the BSD 3-Clause "New" or "Revised" License.

This library isn't used as a dependency as we need to inherit from ``cloup.Group`` instead
of ``click.Group``.
"""
import cloup
import warnings

from .. import logger
import cloup

__all__ = ["DefaultGroup"]

Expand Down Expand Up @@ -54,8 +61,8 @@ def command(self, *args, **kwargs):
decorator = super().command(*args, **kwargs)
if not default:
return decorator
logger.log(
"Use default param of DefaultGroup or " "set_default_command() instead",
warnings.warn(
"Use default param of DefaultGroup or set_default_command() instead",
DeprecationWarning,
)

Expand Down
2 changes: 1 addition & 1 deletion manim/cli/init/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def select_resolution():
resolution_options.pop()
choice = click.prompt(
"\nSelect resolution:\n",
type=click.Choice([f"{i[0]}p" for i in resolution_options]),
type=cloup.Choice([f"{i[0]}p" for i in resolution_options]),
show_default=False,
default="480p",
)
Expand Down
2 changes: 1 addition & 1 deletion manim/cli/new/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def select_resolution():
resolution_options.pop()
choice = click.prompt(
"\nSelect resolution:\n",
type=click.Choice([f"{i[0]}p" for i in resolution_options]),
type=cloup.Choice([f"{i[0]}p" for i in resolution_options]),
show_default=False,
default="480p",
)
Expand Down
54 changes: 29 additions & 25 deletions manim/cli/render/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"""
from __future__ import annotations

import http.client
import json
import sys
import urllib.error
import urllib.request
from pathlib import Path
from typing import cast

import click
import cloup
import requests

from ... import __version__, config, console, error_console, logger
from ..._config import tempconfig
Expand All @@ -30,8 +32,8 @@
no_args_is_help=True,
epilog=EPILOG,
)
@click.argument("file", type=Path, required=True)
@click.argument("scene_names", required=False, nargs=-1)
@cloup.argument("file", type=Path, required=True)
@cloup.argument("scene_names", required=False, nargs=-1)
@global_options
@output_options
@render_options # type: ignore
Expand Down Expand Up @@ -120,30 +122,32 @@ def __repr__(self):
if config.notify_outdated_version:
manim_info_url = "https://pypi.org/pypi/manim/json"
warn_prompt = "Cannot check if latest release of manim is installed"
req_info = {}

try:
req_info = requests.get(manim_info_url, timeout=10)
req_info.raise_for_status()

stable = req_info.json()["info"]["version"]
if stable != __version__:
console.print(
f"You are using manim version [red]v{__version__}[/red], but version [green]v{stable}[/green] is available.",
)
console.print(
"You should consider upgrading via [yellow]pip install -U manim[/yellow]",
)
except requests.exceptions.HTTPError:
logger.debug(f"HTTP Error: {warn_prompt}")
except requests.exceptions.ConnectionError:
logger.debug(f"Connection Error: {warn_prompt}")
except requests.exceptions.Timeout:
logger.debug(f"Timed Out: {warn_prompt}")
with urllib.request.urlopen(
urllib.request.Request(manim_info_url),
timeout=10,
) as response:
response = cast(http.client.HTTPResponse, response)
json_data = json.loads(response.read())
except urllib.error.HTTPError:
logger.debug("HTTP Error: %s", warn_prompt)
except urllib.error.URLError:
logger.debug("URL Error: %s", warn_prompt)
except json.JSONDecodeError:
logger.debug(warn_prompt)
logger.debug(f"Error decoding JSON from {manim_info_url}")
logger.debug(
"Error while decoding JSON from %r: %s", manim_info_url, warn_prompt
)
except Exception:
logger.debug(f"Something went wrong: {warn_prompt}")
logger.debug("Something went wrong: %s", warn_prompt)

stable = json_data["info"]["version"]
if stable != __version__:
console.print(
f"You are using manim version [red]v{__version__}[/red], but version [green]v{stable}[/green] is available.",
)
console.print(
"You should consider upgrading via [yellow]pip install -U manim[/yellow]",
)

return args
5 changes: 2 additions & 3 deletions manim/cli/render/ease_of_access_options.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from __future__ import annotations

import click
from cloup import option, option_group
from cloup import Choice, option, option_group

ease_of_access_options = option_group(
"Ease of access options",
option(
"--progress_bar",
default=None,
show_default=False,
type=click.Choice(
type=Choice(
["display", "leave", "none"],
case_sensitive=False,
),
Expand Down
11 changes: 3 additions & 8 deletions manim/cli/render/global_options.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from __future__ import annotations

import re
from typing import TYPE_CHECKING

import click
from cloup import option, option_group
from cloup import Choice, option, option_group

from ... import logger

if TYPE_CHECKING:
from cloup._option_groups import OptionGroupDecorator


def validate_gui_location(ctx, param, value):
if value:
Expand All @@ -22,7 +17,7 @@ def validate_gui_location(ctx, param, value):
exit()


global_options: OptionGroupDecorator = option_group(
global_options = option_group(
"Global options",
option(
"-c",
Expand Down Expand Up @@ -53,7 +48,7 @@ def validate_gui_location(ctx, param, value):
option(
"-v",
"--verbosity",
type=click.Choice(
type=Choice(
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
case_sensitive=False,
),
Expand Down
9 changes: 4 additions & 5 deletions manim/cli/render/output_options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import click
from cloup import option, option_group
from cloup import IntRange, Path, option, option_group

output_options = option_group(
"Output options",
Expand All @@ -15,7 +14,7 @@
option(
"-0",
"--zero_pad",
type=click.IntRange(0, 9),
type=IntRange(0, 9),
default=None,
help="Zero padding for PNG file names.",
),
Expand All @@ -27,13 +26,13 @@
),
option(
"--media_dir",
type=click.Path(),
type=Path(),
default=None,
help="Path to store rendered videos and latex.",
),
option(
"--log_dir",
type=click.Path(),
type=Path(),
help="Path to store render logs.",
default=None,
),
Expand Down
9 changes: 4 additions & 5 deletions manim/cli/render/render_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import re

import click
from cloup import option, option_group
from cloup import Choice, option, option_group

from manim.constants import QUALITIES, RendererType

Expand Down Expand Up @@ -55,15 +54,15 @@ def validate_resolution(ctx, param, value):
),
option(
"--format",
type=click.Choice(["png", "gif", "mp4", "webm", "mov"], case_sensitive=False),
type=Choice(["png", "gif", "mp4", "webm", "mov"], case_sensitive=False),
default=None,
),
option("-s", "--save_last_frame", is_flag=True, default=None),
option(
"-q",
"--quality",
default=None,
type=click.Choice(
type=Choice(
list(reversed([q["flag"] for q in QUALITIES.values() if q["flag"]])), # type: ignore
case_sensitive=False,
),
Expand Down Expand Up @@ -95,7 +94,7 @@ def validate_resolution(ctx, param, value):
),
option(
"--renderer",
type=click.Choice(
type=Choice(
[renderer_type.value for renderer_type in RendererType],
case_sensitive=False,
),
Expand Down
4 changes: 3 additions & 1 deletion manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,9 @@ def point_from_proportion(self, alpha: float) -> np.ndarray:

curves_and_lengths = tuple(self.get_curve_functions_with_lengths())

target_length = alpha * np.sum(length for _, length in curves_and_lengths)
target_length = alpha * np.sum(
np.fromiter((length for _, length in curves_and_lengths), dtype=np.float64)
)
current_length = 0

for curve, length in curves_and_lengths:
Expand Down
Loading
Loading