File tree Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Expand file tree Collapse file tree 3 files changed +21
-10
lines changed Original file line number Diff line number Diff line change 3131from acres import Loader as _Loader
3232from click .decorators import FC , Option , _param_memo
3333
34+ from templateflow .conf import _cache
3435from templateflow .client import TemplateFlowClient
3536
3637load_data = _Loader (__spec__ .parent )
4849}
4950ENTITY_EXCLUDE = {'template' , 'description' }
5051
51- CLIENT = TemplateFlowClient ()
52+ CLIENT = TemplateFlowClient (cache = _cache )
5253CACHE = CLIENT .cache
5354CONFIG = CACHE .config
5455CACHE .ensure ()
Original file line number Diff line number Diff line change @@ -33,10 +33,6 @@ def __getattr__(name: str):
3333 raise AttributeError (f"module '{ __name__ } ' has no attribute '{ name } '" )
3434
3535
36- if _env_to_bool ('TEMPLATEFLOW_USE_DATALAD' , False ) and not _cache .config .use_datalad :
37- warn ('DataLad is not installed ➔ disabled.' , stacklevel = 2 )
38-
39-
4036if not _cache .precached :
4137 warn (
4238 f"""\
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33from dataclasses import dataclass , field
4- from functools import cached_property
4+ from functools import cache , cached_property
55from pathlib import Path
66from warnings import warn
77
1212 from bids .layout import BIDSLayout
1313
1414
15+ # The first CacheConfig is initialized during import, so we need a higher
16+ # level of indirection for warnings to point to the user code.
17+ # After that, we will set the stack level to point to the CacheConfig() caller.
18+ STACKLEVEL = 6
19+
20+
21+ @cache
22+ def _have_datalad ():
23+ import importlib .util
24+
25+ return importlib .util .find_spec ('datalad' ) is not None
26+
27+
1528@dataclass
1629class CacheConfig :
1730 root : Path = field (default_factory = get_templateflow_home )
@@ -22,10 +35,11 @@ class CacheConfig:
2235 timeout : int = field (default = 10 )
2336
2437 def __post_init__ (self ):
25- if self .use_datalad :
26- from importlib .util import find_spec
27-
28- self .use_datalad = find_spec ('datalad' ) is not None
38+ global STACKLEVEL
39+ if self .use_datalad and not _have_datalad ():
40+ self .use_datalad = False
41+ warn ('DataLad is not installed ➔ disabled.' , stacklevel = STACKLEVEL )
42+ STACKLEVEL = 3
2943
3044
3145@dataclass
You can’t perform that action at this time.
0 commit comments