Skip to content

Commit

Permalink
Fix leftover directories in /tmp after tests
Browse files Browse the repository at this point in the history
The way wms_cache was set previously made it so that after each tests
run there would be one or more directories leftover in /tmp. This also
happened for each start of MSUI. This change makes MSUI use the
platform-specific cache directory of the user instead and sets
XDG_CACHE_HOME to isolate those between test runs.
  • Loading branch information
matrss committed May 16, 2024
1 parent e1dd46d commit 5ec6983
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mslib/msui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import fs
import os
import logging
import platformdirs

# ToDo refactor to generic functions, keep only constants
HOME = os.path.expanduser(f"~{os.path.sep}")
Expand All @@ -39,6 +40,8 @@
# MSUI does not actually support any PyFilesystem2 fs that is not available as a local path
MSUI_CONFIG_SYSPATH = _fs.getsyspath("")

MSUI_CACHE_PATH = platformdirs.user_cache_path("msui", "mss")

GRAVATAR_DIR_PATH = fs.path.join(MSUI_CONFIG_PATH, "gravatars")

MSUI_SETTINGS = os.getenv('MSUI_SETTINGS', os.path.join(MSUI_CONFIG_PATH, "msui_settings.json"))
Expand Down
4 changes: 1 addition & 3 deletions mslib/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import logging
import fs
import os
import tempfile

from mslib.utils import FatalUserError
from mslib.msui import constants
Expand Down Expand Up @@ -149,8 +148,7 @@ class MSUIDefaultConfig:
WMS_preload = []

# WMS image cache settings:
# this changes on any start of msui, use ths msui_settings.json when you want a persistent path
wms_cache = os.path.join(tempfile.TemporaryDirectory().name, "msui_wms_cache")
wms_cache = str(constants.MSUI_CACHE_PATH / "wms_cache")

# Maximum size of the cache in bytes.
wms_cache_max_size_bytes = 20 * 1024 * 1024
Expand Down
4 changes: 4 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import os
import fs
import tempfile
from fs.tempfs import TempFS

try:
Expand Down Expand Up @@ -60,6 +61,9 @@
os.environ["MSUI_CONFIG_PATH"] = MSUI_CONFIG_PATH
SERVER_CONFIG_FILE_PATH = fs.path.join(SERVER_CONFIG_FS.getsyspath(""), SERVER_CONFIG_FILE)

_xdg_cache_home_temporary_directory = tempfile.TemporaryDirectory()
os.environ["XDG_CACHE_HOME"] = _xdg_cache_home_temporary_directory.name

# we keep DATA_DIR until we move netCDF4 files to pyfilesystem2
DATA_DIR = DATA_FS.getsyspath("")

Expand Down

0 comments on commit 5ec6983

Please sign in to comment.