Skip to content

Commit c1e9b61

Browse files
Merge pull request #26 from abhijitnathwani/add-env-variable-for-media-dir
Add support for media dir environment variable
2 parents 9842a93 + c932a4e commit c1e9b61

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ Customize the output image/video directory location:
339339
$ git-sim --media-dir=path/to/output status
340340
```
341341

342+
Optionally, set the environment variable `git_sim_media_dir` to set a global default media directory, to be used if no `--media-dir` is provided. Simulated output images/videos will be placed in this location, in subfolders named with the corresponding repo's name.
343+
344+
```console
345+
$ export git_sim_media_dir=path/to/media/directory
346+
$ git-sim status
347+
```
348+
Note: `--media-dir` takes precedence over the environment variable. If you set the environment and still provide the argument, you'll find the media in the path provided by `--media-dir`.
349+
342350
Generate output video in low quality to speed up rendering time (useful for repeated testing, must include `--animate`):
343351

344352
```console

git_sim/__main__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pathlib
55
import time, datetime
66
import cv2
7+
import git
78
from manim import config, WHITE
89
from manim.utils.file_ops import open_file as open_media_file
910

@@ -76,9 +77,18 @@ def main():
7677

7778
args = parser.parse_args()
7879

80+
if sys.platform == 'linux' or sys.platform == 'darwin':
81+
repo_name = git.Repo(search_parent_directories=True).working_tree_dir.split('/')[-1]
82+
elif sys.platform == 'win32':
83+
repo_name = git.Repo(search_parent_directories=True).working_tree_dir.split('\\')[-1]
84+
7985
config.media_dir = os.path.join(os.path.expanduser(args.media_dir), "git-sim_media")
8086
config.verbosity = "ERROR"
8187

88+
# If the env variable is set and no argument provided, use the env variable value
89+
if os.getenv('git_sim_media_dir') and args.media_dir == '.':
90+
config.media_dir = os.path.join(os.path.expanduser(os.getenv('git_sim_media_dir')), "git-sim_media", repo_name)
91+
8292
if ( args.low_quality ):
8393
config.quality = "low_quality"
8494

0 commit comments

Comments
 (0)