mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
(fix) site_cache_dir() must return DVC_SITE_CACHE_DIR if it exists (#10776)
* DVC_SITE_CACHE_DIR must be sent first, deal with platformdirs afterwards * Test should check default behaviour when no env var is set * Add test: site_cache_dir() must return the env var if set
This commit is contained in:
+4
-3
@@ -24,6 +24,9 @@ def site_cache_dir():
|
||||
from platformdirs import PlatformDirs
|
||||
from platformdirs.unix import Unix
|
||||
|
||||
if dvc_site_cache_dir := os.getenv(env.DVC_SITE_CACHE_DIR):
|
||||
return dvc_site_cache_dir
|
||||
|
||||
if issubclass(Unix, PlatformDirs):
|
||||
# Return the cache directory shared by users, e.g. `/var/tmp/$appname`
|
||||
# NOTE: platformdirs>=5 changed `site_cache_dir` to return /var/cache/$appname.
|
||||
@@ -34,6 +37,4 @@ def site_cache_dir():
|
||||
# In the future, consider migrating to a more secure directory.
|
||||
return f"/var/tmp/{APPNAME}" # noqa: S108
|
||||
|
||||
return os.getenv(env.DVC_SITE_CACHE_DIR) or platformdirs.site_cache_dir(
|
||||
APPNAME, APPAUTHOR, opinion=True
|
||||
)
|
||||
return platformdirs.site_cache_dir(APPNAME, APPAUTHOR, opinion=True)
|
||||
|
||||
@@ -3,7 +3,7 @@ import sys
|
||||
import pytest
|
||||
|
||||
from dvc.dirs import global_config_dir, site_cache_dir
|
||||
from dvc.env import DVC_GLOBAL_CONFIG_DIR
|
||||
from dvc.env import DVC_GLOBAL_CONFIG_DIR, DVC_SITE_CACHE_DIR
|
||||
|
||||
|
||||
def test_global_config_dir_respects_env_var(monkeypatch):
|
||||
@@ -13,5 +13,11 @@ def test_global_config_dir_respects_env_var(monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform != "linux", reason="Only for Unix platforms")
|
||||
def test_site_cache_dir_on_unix():
|
||||
def test_site_cache_dir_on_unix(monkeypatch):
|
||||
monkeypatch.delenv(DVC_SITE_CACHE_DIR, raising=False)
|
||||
assert site_cache_dir() == "/var/tmp/dvc"
|
||||
|
||||
|
||||
def test_site_cache_dir_env_var(monkeypatch):
|
||||
monkeypatch.setenv(DVC_SITE_CACHE_DIR, "foo_bar")
|
||||
assert site_cache_dir() == "foo_bar"
|
||||
|
||||
Reference in New Issue
Block a user