mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 13:34:19 +08:00
Allow for a configurable cache location
This commit is contained in:
@ -10,12 +10,12 @@ directories:
|
||||
vector_images: ""
|
||||
# If you want to use sounds, manim will look here to find it.
|
||||
sounds: ""
|
||||
# Manim often generates tex_files or other kinds of serialized data
|
||||
# to keep from having to generate the same thing too many times. By
|
||||
# default, these will be stored at tempfile.gettempdir(), e.g. this might
|
||||
# return whatever is at to the TMPDIR environment variable. If you want to
|
||||
# specify them elsewhere,
|
||||
temporary_storage: ""
|
||||
# For certain object types, especially Tex and Text, manim will save information
|
||||
# to file to prevent the need to re-compute, e.g. recompiling the latex. By default,
|
||||
# it stores this saved data to whatever directory appdirs.user_cache_dir("manim") returns,
|
||||
# but here a user can specify a different cache location
|
||||
cache: ""
|
||||
universal_import_line: "from manimlib import *"
|
||||
style:
|
||||
tex_template: "default"
|
||||
|
@ -1,15 +1,15 @@
|
||||
import appdirs
|
||||
import os
|
||||
from diskcache import Cache
|
||||
from contextlib import contextmanager
|
||||
|
||||
from manimlib.utils.directories import get_cache_dir
|
||||
|
||||
|
||||
CACHE_SIZE = 1e9 # 1 Gig
|
||||
|
||||
|
||||
def get_cached_value(key, value_func, message=""):
|
||||
cache_dir = appdirs.user_cache_dir("manim")
|
||||
cache = Cache(cache_dir, size_limit=CACHE_SIZE)
|
||||
cache = Cache(get_cache_dir(), size_limit=CACHE_SIZE)
|
||||
|
||||
value = cache.get(key)
|
||||
if value is None:
|
||||
|
@ -1,5 +1,6 @@
|
||||
import os
|
||||
import tempfile
|
||||
import appdirs
|
||||
|
||||
from manimlib.config import get_custom_config
|
||||
from manimlib.config import get_manim_dir
|
||||
@ -17,6 +18,9 @@ def get_customization():
|
||||
if not directories["temporary_storage"]:
|
||||
directories["temporary_storage"] = tempfile.gettempdir()
|
||||
|
||||
if not directories["cache"]:
|
||||
directories["cache"] = appdirs.user_cache_dir("manim")
|
||||
|
||||
# Assumes all shaders are written into manimlib/shaders
|
||||
directories["shaders"] = os.path.join(
|
||||
get_manim_dir(), "manimlib", "shaders"
|
||||
|
@ -10,6 +10,10 @@ def get_directories() -> dict[str, str]:
|
||||
return get_customization()["directories"]
|
||||
|
||||
|
||||
def get_cache_dir() -> str:
|
||||
return get_directories()["cache"]
|
||||
|
||||
|
||||
def get_temp_dir() -> str:
|
||||
return get_directories()["temporary_storage"]
|
||||
|
||||
|
Reference in New Issue
Block a user