Skip to content

Commit 61a2d05

Browse files
Update dependency constraints, fix deprecation warnings (#3376)
* WIP: Update metadata * Finish removing upper bounds Drop requests dependency, use urllib instead order depencencies * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix issues on 3.12 * Order dev dependencies * Update most dev deps, update lint config * Add missing import * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * trigger CI * More deprecation fixes * Missing argument * Deprecation fixes, again * Use older xdist to fix test flakyness --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 6949c66 commit 61a2d05

File tree

20 files changed

+1151
-2040
lines changed

20 files changed

+1151
-2040
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
- name: Install Poetry
3232
run: |
33-
pipx install "poetry==1.5.*"
33+
pipx install "poetry==1.7.*"
3434
poetry config virtualenvs.prefer-active-python true
3535
3636
- name: Setup Python ${{ matrix.python }}

manim/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/usr/bin/env python
2-
3-
42
from __future__ import annotations
53

6-
import pkg_resources
7-
8-
__version__: str = pkg_resources.get_distribution(__name__).version
4+
from importlib.metadata import version
95

6+
__version__ = version(__name__)
107

11-
import sys
128

139
# isort: off
1410

manim/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import sys
44

5-
import click
65
import cloup
76

87
from . import __version__, cli_ctx_settings, console
@@ -35,15 +34,15 @@ def exit_early(ctx, param, value):
3534
"is specified. Run 'manim render --help' if you would like to know what the "
3635
f"'-ql' or '-p' flags do, for example.\n\n{EPILOG}",
3736
)
38-
@click.option(
37+
@cloup.option(
3938
"--version",
4039
is_flag=True,
4140
help="Show version and exit.",
4241
callback=exit_early,
4342
is_eager=True,
4443
expose_value=False,
4544
)
46-
@click.pass_context
45+
@cloup.pass_context
4746
def main(ctx):
4847
"""The entry point for manim."""
4948
pass

manim/camera/camera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@ def display_image_mobject(
973973
sub_image = Image.fromarray(image_mobject.get_pixel_array(), mode="RGBA")
974974

975975
# Reshape
976-
pixel_width = max(int(pdist([ul_coords, ur_coords])), 1)
977-
pixel_height = max(int(pdist([ul_coords, dl_coords])), 1)
976+
pixel_width = max(int(pdist([ul_coords, ur_coords]).item()), 1)
977+
pixel_height = max(int(pdist([ul_coords, dl_coords]).item()), 1)
978978
sub_image = sub_image.resize(
979979
(pixel_width, pixel_height),
980980
resample=image_mobject.resampling_algorithm,

manim/cli/cfg/group.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
"""
88
from __future__ import annotations
99

10-
import os
1110
from ast import literal_eval
1211
from pathlib import Path
1312

14-
import click
1513
import cloup
1614
from rich.errors import StyleSyntaxError
1715
from rich.style import Style
@@ -123,21 +121,21 @@ def replace_keys(default: dict) -> dict:
123121
epilog=EPILOG,
124122
help="Manages Manim configuration files.",
125123
)
126-
@click.pass_context
124+
@cloup.pass_context
127125
def cfg(ctx):
128126
"""Responsible for the cfg subcommand."""
129127
pass
130128

131129

132130
@cfg.command(context_settings=cli_ctx_settings, no_args_is_help=True)
133-
@click.option(
131+
@cloup.option(
134132
"-l",
135133
"--level",
136-
type=click.Choice(["user", "cwd"], case_sensitive=False),
134+
type=cloup.Choice(["user", "cwd"], case_sensitive=False),
137135
default="cwd",
138136
help="Specify if this config is for user or the working directory.",
139137
)
140-
@click.option("-o", "--open", "openfile", is_flag=True)
138+
@cloup.option("-o", "--open", "openfile", is_flag=True)
141139
def write(level: str = None, openfile: bool = False) -> None:
142140
config_paths = config_file_paths()
143141
console.print(
@@ -258,8 +256,8 @@ def show():
258256

259257

260258
@cfg.command(context_settings=cli_ctx_settings)
261-
@click.option("-d", "--directory", default=Path.cwd())
262-
@click.pass_context
259+
@cloup.option("-d", "--directory", default=Path.cwd())
260+
@cloup.pass_context
263261
def export(ctx, directory):
264262
directory_path = Path(directory)
265263
if directory_path.absolute == Path.cwd().absolute:

manim/cli/default_group.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
"""DefaultGroup allows a subcommand to act as the main command
1+
"""``DefaultGroup`` allows a subcommand to act as the main command.
22
33
In particular, this class is what allows ``manim`` to act as ``manim render``.
4+
5+
.. note::
6+
This is a vendored version of https://github.com/click-contrib/click-default-group/
7+
under the BSD 3-Clause "New" or "Revised" License.
8+
9+
This library isn't used as a dependency as we need to inherit from ``cloup.Group`` instead
10+
of ``click.Group``.
411
"""
5-
import cloup
12+
import warnings
613

7-
from .. import logger
14+
import cloup
815

916
__all__ = ["DefaultGroup"]
1017

@@ -54,8 +61,8 @@ def command(self, *args, **kwargs):
5461
decorator = super().command(*args, **kwargs)
5562
if not default:
5663
return decorator
57-
logger.log(
58-
"Use default param of DefaultGroup or " "set_default_command() instead",
64+
warnings.warn(
65+
"Use default param of DefaultGroup or set_default_command() instead",
5966
DeprecationWarning,
6067
)
6168

manim/cli/init/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def select_resolution():
4747
resolution_options.pop()
4848
choice = click.prompt(
4949
"\nSelect resolution:\n",
50-
type=click.Choice([f"{i[0]}p" for i in resolution_options]),
50+
type=cloup.Choice([f"{i[0]}p" for i in resolution_options]),
5151
show_default=False,
5252
default="480p",
5353
)

manim/cli/new/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def select_resolution():
4040
resolution_options.pop()
4141
choice = click.prompt(
4242
"\nSelect resolution:\n",
43-
type=click.Choice([f"{i[0]}p" for i in resolution_options]),
43+
type=cloup.Choice([f"{i[0]}p" for i in resolution_options]),
4444
show_default=False,
4545
default="480p",
4646
)

manim/cli/render/commands.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
"""
88
from __future__ import annotations
99

10+
import http.client
1011
import json
1112
import sys
13+
import urllib.error
14+
import urllib.request
1215
from pathlib import Path
16+
from typing import cast
1317

14-
import click
1518
import cloup
16-
import requests
1719

1820
from ... import __version__, config, console, error_console, logger
1921
from ..._config import tempconfig
@@ -30,8 +32,8 @@
3032
no_args_is_help=True,
3133
epilog=EPILOG,
3234
)
33-
@click.argument("file", type=Path, required=True)
34-
@click.argument("scene_names", required=False, nargs=-1)
35+
@cloup.argument("file", type=Path, required=True)
36+
@cloup.argument("scene_names", required=False, nargs=-1)
3537
@global_options
3638
@output_options
3739
@render_options # type: ignore
@@ -120,30 +122,32 @@ def __repr__(self):
120122
if config.notify_outdated_version:
121123
manim_info_url = "https://pypi.org/pypi/manim/json"
122124
warn_prompt = "Cannot check if latest release of manim is installed"
123-
req_info = {}
124125

125126
try:
126-
req_info = requests.get(manim_info_url, timeout=10)
127-
req_info.raise_for_status()
128-
129-
stable = req_info.json()["info"]["version"]
130-
if stable != __version__:
131-
console.print(
132-
f"You are using manim version [red]v{__version__}[/red], but version [green]v{stable}[/green] is available.",
133-
)
134-
console.print(
135-
"You should consider upgrading via [yellow]pip install -U manim[/yellow]",
136-
)
137-
except requests.exceptions.HTTPError:
138-
logger.debug(f"HTTP Error: {warn_prompt}")
139-
except requests.exceptions.ConnectionError:
140-
logger.debug(f"Connection Error: {warn_prompt}")
141-
except requests.exceptions.Timeout:
142-
logger.debug(f"Timed Out: {warn_prompt}")
127+
with urllib.request.urlopen(
128+
urllib.request.Request(manim_info_url),
129+
timeout=10,
130+
) as response:
131+
response = cast(http.client.HTTPResponse, response)
132+
json_data = json.loads(response.read())
133+
except urllib.error.HTTPError:
134+
logger.debug("HTTP Error: %s", warn_prompt)
135+
except urllib.error.URLError:
136+
logger.debug("URL Error: %s", warn_prompt)
143137
except json.JSONDecodeError:
144-
logger.debug(warn_prompt)
145-
logger.debug(f"Error decoding JSON from {manim_info_url}")
138+
logger.debug(
139+
"Error while decoding JSON from %r: %s", manim_info_url, warn_prompt
140+
)
146141
except Exception:
147-
logger.debug(f"Something went wrong: {warn_prompt}")
142+
logger.debug("Something went wrong: %s", warn_prompt)
143+
144+
stable = json_data["info"]["version"]
145+
if stable != __version__:
146+
console.print(
147+
f"You are using manim version [red]v{__version__}[/red], but version [green]v{stable}[/green] is available.",
148+
)
149+
console.print(
150+
"You should consider upgrading via [yellow]pip install -U manim[/yellow]",
151+
)
148152

149153
return args

manim/cli/render/ease_of_access_options.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from __future__ import annotations
22

3-
import click
4-
from cloup import option, option_group
3+
from cloup import Choice, option, option_group
54

65
ease_of_access_options = option_group(
76
"Ease of access options",
87
option(
98
"--progress_bar",
109
default=None,
1110
show_default=False,
12-
type=click.Choice(
11+
type=Choice(
1312
["display", "leave", "none"],
1413
case_sensitive=False,
1514
),

manim/cli/render/global_options.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
from __future__ import annotations
22

33
import re
4-
from typing import TYPE_CHECKING
54

6-
import click
7-
from cloup import option, option_group
5+
from cloup import Choice, option, option_group
86

97
from ... import logger
108

11-
if TYPE_CHECKING:
12-
from cloup._option_groups import OptionGroupDecorator
13-
149

1510
def validate_gui_location(ctx, param, value):
1611
if value:
@@ -22,7 +17,7 @@ def validate_gui_location(ctx, param, value):
2217
exit()
2318

2419

25-
global_options: OptionGroupDecorator = option_group(
20+
global_options = option_group(
2621
"Global options",
2722
option(
2823
"-c",
@@ -53,7 +48,7 @@ def validate_gui_location(ctx, param, value):
5348
option(
5449
"-v",
5550
"--verbosity",
56-
type=click.Choice(
51+
type=Choice(
5752
["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
5853
case_sensitive=False,
5954
),

manim/cli/render/output_options.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
import click
4-
from cloup import option, option_group
3+
from cloup import IntRange, Path, option, option_group
54

65
output_options = option_group(
76
"Output options",
@@ -15,7 +14,7 @@
1514
option(
1615
"-0",
1716
"--zero_pad",
18-
type=click.IntRange(0, 9),
17+
type=IntRange(0, 9),
1918
default=None,
2019
help="Zero padding for PNG file names.",
2120
),
@@ -27,13 +26,13 @@
2726
),
2827
option(
2928
"--media_dir",
30-
type=click.Path(),
29+
type=Path(),
3130
default=None,
3231
help="Path to store rendered videos and latex.",
3332
),
3433
option(
3534
"--log_dir",
36-
type=click.Path(),
35+
type=Path(),
3736
help="Path to store render logs.",
3837
default=None,
3938
),

manim/cli/render/render_options.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import re
44

5-
import click
6-
from cloup import option, option_group
5+
from cloup import Choice, option, option_group
76

87
from manim.constants import QUALITIES, RendererType
98

@@ -55,15 +54,15 @@ def validate_resolution(ctx, param, value):
5554
),
5655
option(
5756
"--format",
58-
type=click.Choice(["png", "gif", "mp4", "webm", "mov"], case_sensitive=False),
57+
type=Choice(["png", "gif", "mp4", "webm", "mov"], case_sensitive=False),
5958
default=None,
6059
),
6160
option("-s", "--save_last_frame", is_flag=True, default=None),
6261
option(
6362
"-q",
6463
"--quality",
6564
default=None,
66-
type=click.Choice(
65+
type=Choice(
6766
list(reversed([q["flag"] for q in QUALITIES.values() if q["flag"]])), # type: ignore
6867
case_sensitive=False,
6968
),
@@ -95,7 +94,7 @@ def validate_resolution(ctx, param, value):
9594
),
9695
option(
9796
"--renderer",
98-
type=click.Choice(
97+
type=Choice(
9998
[renderer_type.value for renderer_type in RendererType],
10099
case_sensitive=False,
101100
),

manim/mobject/opengl/opengl_vectorized_mobject.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,9 @@ def point_from_proportion(self, alpha: float) -> np.ndarray:
944944

945945
curves_and_lengths = tuple(self.get_curve_functions_with_lengths())
946946

947-
target_length = alpha * np.sum(length for _, length in curves_and_lengths)
947+
target_length = alpha * np.sum(
948+
np.fromiter((length for _, length in curves_and_lengths), dtype=np.float64)
949+
)
948950
current_length = 0
949951

950952
for curve, length in curves_and_lengths:

0 commit comments

Comments
 (0)