|
7 | 7 | """ |
8 | 8 | from __future__ import annotations |
9 | 9 |
|
| 10 | +import http.client |
10 | 11 | import json |
11 | 12 | import sys |
| 13 | +import urllib.error |
| 14 | +import urllib.request |
12 | 15 | from pathlib import Path |
| 16 | +from typing import cast |
13 | 17 |
|
14 | | -import click |
15 | 18 | import cloup |
16 | | -import requests |
17 | 19 |
|
18 | 20 | from ... import __version__, config, console, error_console, logger |
19 | 21 | from ..._config import tempconfig |
|
30 | 32 | no_args_is_help=True, |
31 | 33 | epilog=EPILOG, |
32 | 34 | ) |
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) |
35 | 37 | @global_options |
36 | 38 | @output_options |
37 | 39 | @render_options # type: ignore |
@@ -120,30 +122,32 @@ def __repr__(self): |
120 | 122 | if config.notify_outdated_version: |
121 | 123 | manim_info_url = "https://pypi.org/pypi/manim/json" |
122 | 124 | warn_prompt = "Cannot check if latest release of manim is installed" |
123 | | - req_info = {} |
124 | 125 |
|
125 | 126 | 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) |
143 | 137 | 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 | + ) |
146 | 141 | 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 | + ) |
148 | 152 |
|
149 | 153 | return args |
0 commit comments