From 494d4ad00cc18fae0702339b05e9364e93381301 Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Wed, 17 Apr 2024 14:25:14 +0200 Subject: [PATCH] enh: allow moving the cache folder with an environment variable Resolves: #1029. --- mriqc/cli/version.py | 5 ++--- mriqc/config.py | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mriqc/cli/version.py b/mriqc/cli/version.py index acfe36f3..9cb381ac 100644 --- a/mriqc/cli/version.py +++ b/mriqc/cli/version.py @@ -24,11 +24,10 @@ from contextlib import suppress from datetime import datetime, timezone -from pathlib import Path import requests -from mriqc import __version__ +from mriqc import __version__, config RELEASE_EXPIRY_DAYS = 14 DATE_FMT = '%Y%m%d' @@ -42,7 +41,7 @@ def check_latest(): latest = None date = None outdated = None - cachefile = Path.home() / '.cache' / 'mriqc' / 'latest' + cachefile = config.environment.cache_path / 'latest' try: cachefile.parent.mkdir(parents=True, exist_ok=True) except OSError: diff --git a/mriqc/config.py b/mriqc/config.py index 4f1fe616..ff838d0b 100644 --- a/mriqc/config.py +++ b/mriqc/config.py @@ -212,6 +212,11 @@ else '18480913-163000_PhineasG-ageh-adhi-sacc-ident9b1ab0f' ) +_mriqc_cache = Path(os.getenv( + 'MRIQC_CACHE_PATH', + str(Path.home() / '.cache' / 'mriqc') +)).absolute() + class _Config: """An abstract class forbidding instantiation.""" @@ -283,6 +288,8 @@ class environment(_Config): """ + cache_path = _mriqc_cache + """Path to the location of the cache directory.""" cpu_count = os.cpu_count() """Number of available CPUs.""" exec_docker_version = _docker_ver