Source code for spack.caches
# Copyright Spack Project Developers. See COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
"""Caches used by Spack to store data"""
from typing import cast
import spack.config
import spack.fetch_strategy
import spack.paths
import spack.util.file_cache
import spack.util.lang
[docs]
def misc_cache_location(*, config: spack.config.Configuration) -> str:
"""The ``MISC_CACHE`` is Spack's cache for small data.
Currently the ``MISC_CACHE`` stores indexes for virtual dependency
providers and for which packages provide which tags.
"""
path = config.get("config:misc_cache", spack.paths.default_misc_cache_path)
return spack.config.canonicalize_path(path, config=config)
[docs]
def misc_cache(*, config: spack.config.Configuration) -> spack.util.file_cache.FileCache:
"""Return a ``FileCache`` rooted at the misc-cache location derived from ``config``."""
return spack.util.file_cache.FileCache(
misc_cache_location(config=config), enable_lock=config.get("config:locks", True)
)
def _create_global_misc_cache() -> spack.util.file_cache.FileCache:
"""Build the misc cache from the global configuration."""
return misc_cache(config=spack.config.CONFIG)
#: Spack's cache for small data
MISC_CACHE = cast(
spack.util.file_cache.FileCache, spack.util.lang.Singleton(_create_global_misc_cache)
)
[docs]
def fetch_cache_location(*, config: spack.config.Configuration) -> str:
"""Filesystem cache of downloaded archives.
This prevents Spack from repeatedly fetch the same files when
building the same package different ways or multiple times.
"""
path = config.get("config:source_cache")
if not path:
path = spack.paths.default_fetch_cache_path
return spack.config.canonicalize_path(path, config=config)
[docs]
def fetch_cache(config: spack.config.Configuration) -> spack.fetch_strategy.FsCache:
"""Returns Spack's local cache for downloaded source archives, as configured in ``config``."""
return spack.fetch_strategy.FsCache(fetch_cache_location(config=config))
[docs]
class MirrorCache(spack.fetch_strategy.FsCacheBase):
def __init__(self, root, skip_unstable_versions):
super().__init__(root)
self.skip_unstable_versions = skip_unstable_versions
[docs]
def store(self, fetcher, relative_dest):
"""Fetch and relocate the fetcher's target into our mirror cache.
Note: archives package sources even if not normally cached (e.g. tip of hg/git branch).
"""
super().store(fetcher, relative_dest)