Skip to content

Commit 8fce5a7

Browse files
WampyCakesbehackl
andauthored
New feature: Added --version command line flag (#970)
* Add --version commandline flag * Update __init__.py * Update manim/_config/main_utils.py Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at> * Fix Black Check * Update poetry.lock * Create test_version.py * Make black happy Running black locally didn't catch this for some reason.. * Review changes Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
1 parent 19e8752 commit 8fce5a7

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

docs/source/tutorials/configuration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ A list of all CLI flags
437437
--custom_folders Use the folders defined in the [custom_folders] section of the config file to define the output folder structure
438438
-v {DEBUG,INFO,WARNING,ERROR,CRITICAL}, --verbosity {DEBUG,INFO,WARNING,ERROR,CRITICAL}
439439
Verbosity level. Also changes the ffmpeg log level unless the latter is specified in the config
440+
--version Print the current version of Manim you are using
440441
--progress_bar True/False
441442
Display the progress bar
442443

manim/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@
9090
from .utils import unit
9191

9292
from .plugins import *
93+
94+
try:
95+
import importlib.metadata as importlib_metadata
96+
except ModuleNotFoundError:
97+
import importlib_metadata
98+
99+
__version__ = importlib_metadata.version(__name__)

manim/_config/main_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import argparse
55
import typing
6-
from manim import constants
6+
import sys
7+
from manim import constants, __version__
78

89

910
__all__ = ["parse_args"]
@@ -109,6 +110,9 @@ def parse_args(args: list) -> argparse.Namespace:
109110
return _parse_args_cfg_subcmd(args)
110111
elif subcmd == "plugins":
111112
return _parse_args_plugins(args)
113+
elif args[1] == "--version":
114+
print(f"Manim Community Edition v{ __version__ }")
115+
sys.exit()
112116
# elif subcmd == some_other_future_subcmd:
113117
# return _parse_args_some_other_subcmd(args)
114118
elif subcmd is None:
@@ -445,6 +449,12 @@ def _parse_args_no_subcmd(args: list) -> argparse.Namespace:
445449
choices=constants.VERBOSITY_CHOICES,
446450
)
447451

452+
parser.add_argument(
453+
"--version",
454+
action="store_true",
455+
help="Print the current version of Manim you are using",
456+
)
457+
448458
# Specify if the progress bar should be displayed
449459
parser.add_argument(
450460
"--progress_bar",

poetry.lock

Lines changed: 23 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ grpcio = { version = "1.33.*", optional = true }
3939
grpcio-tools = { version = "1.33.*", optional = true }
4040
watchdog = { version = "*", optional = true }
4141
networkx = "^2.5"
42+
importlib-metadata = {version = "^1.0", python = "<3.8"}
4243

4344
[tool.poetry.extras]
4445
js_renderer = ["grpcio","grpcio-tools","watchdog"]

tests/test_version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from manim import __version__
2+
import pkg_resources
3+
4+
5+
def test_version():
6+
assert __version__ == pkg_resources.get_distribution("manim").version

0 commit comments

Comments
 (0)