[docs]defcache_directory(dir:Optional[str]=None):"""Cache directory. Specify the cache directory in the local filesystem for gypsum-related data. If the ``GYPSUM_CACHE_DIR`` environment variable is set before the first call to ``cache_directory()``, it is used as the initial location of the cache directory. Otherwise, the initial location is set to user's home directory defined by ``Path.home()``. Args: dir: Path to the cache directory. If `None`, a default cache location is used. Returns: Path to the cache directory. """globalCURRENT_CACHE_DIRECTORYifCURRENT_CACHE_DIRECTORYisNone:_from_env=os.environ.get("GYPSUM_CACHE_DIR",None)if_from_envisnotNone:ifnotos.path.exists(_from_env):raiseFileNotFoundError(f"Path {_from_env} does not exist or is not accessible.")CURRENT_CACHE_DIRECTORY=_from_envelse:CURRENT_CACHE_DIRECTORY=os.path.join(str(Path.home()),"gypsum","cache")os.makedirs(CURRENT_CACHE_DIRECTORY,exist_ok=True)ifdirisnotNone:ifnotos.path.exists(dir):raiseFileNotFoundError(f"Path {dir} does not exist or is not accessible.")CURRENT_CACHE_DIRECTORY=dirreturnCURRENT_CACHE_DIRECTORY