Skip to content

Commit 875f2d1

Browse files
RickyC0626jsonvillanuevapre-commit-ci[bot]WampyCakesnaveen521kk
authored
Notify user if they are using an outdated version of Manim (#1237)
* Notify user if local version is outdated Running the `manim` command will display the version number as green if it is the latest detected on GitHub. Otherwise, display the version number as red and let the user know that a newer version is available. * Black formatting * Add requests dependency * Switch to PyPi API since it's not ratelimited * Add CLI option for notifying local outdated build Manim will notify user if local installation is outdated, after rendering. This feature is enabled by default, but could be turned off in config. * Update notify_outdated_version instructions * Please the flake * Add documentation to configuration.rst * Update poetry.lock * Update option punctuation * No need to inform users if they're up to date * Move variable to within method * Remove unused import * Update dependencies * Update outdated version message * Run isort * Fix typo * Set `--notify_outdated_version` default to `None` Flag value by default is None so config file will determine the value. If flag is used then value is True. * Convert CLRF to Unix newline LF (cleaner diffs) * Remove argument check for outdated version Too verbose, value should be configured via config * Handle requests exceptions * Update manim/cli/render/commands.py Co-authored-by: Jason Villanueva <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use f-strings for logger warnings * Update poetry.lock * Update manim/cli/render/commands.py Co-authored-by: KingWampy <[email protected]> * Update manim/cli/render/commands.py Co-authored-by: KingWampy <[email protected]> * Move print statements within try block * Except JSONDecodeError only * Update manim/cli/render/commands.py Co-authored-by: Naveen M K <[email protected]> * Update manim/cli/render/commands.py Co-authored-by: Naveen M K <[email protected]> * Don't raise exceptions, log in debug Co-authored-by: Jason Villanueva <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: KingWampy <[email protected]> Co-authored-by: Naveen M K <[email protected]>
1 parent b74ea53 commit 875f2d1

File tree

8 files changed

+108
-37
lines changed

8 files changed

+108
-37
lines changed

docs/source/tutorials/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ A list of all config options
346346
'frame_size', 'frame_width', 'frame_x_radius', 'frame_y_radius',
347347
'from_animation_number', 'images_dir', 'input_file', 'left_side',
348348
'log_dir', 'log_to_file', 'max_files_cached', 'media_dir', 'media_width',
349-
'movie_file_extension', 'output_file', 'partial_movie_dir',
349+
'movie_file_extension', 'notify_outdated_version', 'output_file', 'partial_movie_dir',
350350
'pixel_height', 'pixel_width', 'plugins', 'png_mode', 'preview',
351351
'progress_bar', 'quality', 'right_side', 'save_as_gif', 'save_last_frame',
352352
'save_pngs', 'scene_names', 'show_in_file_browser', 'sound', 'tex_dir',

manim/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def exit_early(ctx, param, value):
1515
sys.exit()
1616

1717

18-
console.print(f"Manim Community [green]v{__version__}[/green]")
18+
console.print(f"Manim Community [green]v{__version__}[/green]\n")
1919

2020

2121
@click.group(

manim/_config/default.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# WRITE_TO_MOVIE = False so that running manim without the -w flag will not
1515
# generate a movie file. Note all of the following accept boolean values.
1616

17+
# --notify_outdated_version
18+
notify_outdated_version = True
19+
1720
# -w, --write_to_movie
1821
write_to_movie = True
1922

manim/_config/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class MyScene(Scene):
256256
"max_files_cached",
257257
"media_dir",
258258
"movie_file_extension",
259+
"notify_outdated_version",
259260
"partial_movie_dir",
260261
"pixel_height",
261262
"pixel_width",
@@ -488,6 +489,7 @@ def digest_parser(self, parser: configparser.ConfigParser) -> "ManimConfig":
488489

489490
# boolean keys
490491
for key in [
492+
"notify_outdated_version",
491493
"write_to_movie",
492494
"save_last_frame",
493495
"write_all",
@@ -611,6 +613,7 @@ def digest_args(self, args: argparse.Namespace) -> "ManimConfig":
611613
self.output_file = args.output_file
612614

613615
for key in [
616+
"notify_outdated_version",
614617
"preview",
615618
"show_in_file_browser",
616619
"write_to_movie",
@@ -784,6 +787,12 @@ def log_to_file(self, val: str) -> None:
784787
os.makedirs(log_dir)
785788
set_file_logger(self, self["verbosity"])
786789

790+
notify_outdated_version = property(
791+
lambda self: self._d["notify_outdated_version"],
792+
lambda self, val: self._set_boolean("notify_outdated_version", val),
793+
doc="Whether to notify if there is a version update available.",
794+
)
795+
787796
write_to_movie = property(
788797
lambda self: self._d["write_to_movie"],
789798
lambda self, val: self._set_boolean("write_to_movie", val),

manim/cli/render/commands.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
can specify options, and arguments for the render command.
66
77
"""
8+
import json
89
import sys
910
from pathlib import Path
1011
from textwrap import dedent
1112

1213
import click
1314
import cloup
15+
import requests
1416

15-
from ... import config, console, logger
17+
from ... import __version__, config, console, logger
1618
from ...constants import CONTEXT_SETTINGS, EPILOG
1719
from ...utils.module_ops import scene_classes_from_file
1820
from .ease_of_access_options import ease_of_access_options
@@ -136,4 +138,35 @@ def __repr__(self):
136138
except Exception:
137139
console.print_exception()
138140

141+
if config.notify_outdated_version:
142+
manim_info_url = "https://pypi.org/pypi/manim/json"
143+
warn_prompt = "Cannot check if latest release of manim is installed"
144+
req_info = {}
145+
146+
try:
147+
req_info = requests.get(manim_info_url)
148+
req_info.raise_for_status()
149+
except requests.exceptions.HTTPError:
150+
logger.debug(f"HTTP Error: {warn_prompt}")
151+
except requests.exceptions.ConnectionError:
152+
logger.debug(f"Connection Error: {warn_prompt}")
153+
except requests.exceptions.Timeout:
154+
logger.debug(f"Timed Out: {warn_prompt}")
155+
except Exception:
156+
logger.debug(f"Something went wrong: {warn_prompt}")
157+
158+
try:
159+
stable = req_info.json()["info"]["version"]
160+
161+
if stable != __version__:
162+
console.print(
163+
f"You are using manim version [red]v{__version__}[/red], but version [green]v{stable}[/green] is available."
164+
)
165+
console.print(
166+
"You should consider upgrading via [yellow]pip install -U manim[/yellow]"
167+
)
168+
except json.JSONDecodeError:
169+
logger.debug(warn_prompt)
170+
logger.debug(f"Error decoding JSON from {manim_info_url}")
171+
139172
return args

manim/cli/render/global_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@
3030
),
3131
help="Verbosity of CLI output. Changes ffmpeg log level unless 5+.",
3232
),
33+
option(
34+
"--notify_outdated_version/--silent",
35+
is_flag=True,
36+
default=None,
37+
help="Display warnings for outdated installation.",
38+
),
3339
)

0 commit comments

Comments
 (0)