Skip to content

Commit c9e2767

Browse files
committed
rf: Defer pybids imports
1 parent 9dc2691 commit c9e2767

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

templateflow/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
from json import loads
3030
from pathlib import Path
3131

32-
from bids.layout import Query
33-
3432
from .conf.cache import CacheConfig, TemplateFlowCache
3533

3634

@@ -113,6 +111,8 @@ def ls(self, template, **kwargs):
113111
[]
114112
115113
"""
114+
from bids.layout import Query
115+
116116
# Normalize extensions to always have leading dot
117117
if 'extension' in kwargs:
118118
kwargs['extension'] = _normalize_ext(kwargs['extension'])

templateflow/conf/cache.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
from pathlib import Path
66
from warnings import warn
77

8-
from .bids import Layout
98
from .env import env_to_bool, get_templateflow_home
109

10+
TYPE_CHECKING = False
11+
if TYPE_CHECKING:
12+
from bids.layout import BIDSLayout
13+
1114

1215
@dataclass
1316
class CacheConfig:
@@ -98,11 +101,13 @@ def cached(self) -> bool:
98101
return self.config.root.is_dir() and any(self.config.root.iterdir())
99102

100103
@cached_property
101-
def layout(self) -> Layout:
104+
def layout(self) -> BIDSLayout:
102105
import re
103106

104107
from bids.layout.index import BIDSLayoutIndexer
105108

109+
from .bids import Layout
110+
106111
self.ensure()
107112
return Layout(
108113
self.config.root,

0 commit comments

Comments
 (0)