Skip to content

Commit b738afa

Browse files
committed
rf: Improve TemplateFlowClient init signature
1 parent 4df9853 commit b738afa

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

templateflow/client.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from __future__ import annotations
2626

27+
import os
2728
import sys
2829
from json import loads
2930
from pathlib import Path
@@ -34,11 +35,21 @@
3435

3536

3637
class TemplateFlowClient:
37-
def __init__(self, cache=None, config=None):
38+
def __init__(
39+
self,
40+
root: os.PathLike[str] | str | None = None,
41+
*,
42+
cache: TemplateFlowCache | None = None,
43+
**config_kwargs,
44+
):
3845
if cache is None:
39-
if config is None:
40-
config = CacheConfig()
41-
cache = TemplateFlowCache(config)
46+
if root:
47+
config_kwargs['root'] = root
48+
cache = TemplateFlowCache(CacheConfig(**config_kwargs))
49+
elif root or config_kwargs:
50+
raise ValueError(
51+
'If `cache` is provided, `root` and other config kwargs cannot be used.'
52+
)
4253
self.cache = cache
4354

4455
def __getattr__(self, name: str):

templateflow/tests/test_s3.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,7 @@ def test_s3_400_error(monkeypatch):
124124

125125
def test_bad_skeleton(tmp_path, monkeypatch):
126126
newhome = (tmp_path / 's3-update').resolve()
127-
client = templateflow.client.TemplateFlowClient(
128-
config=tfc.cache.CacheConfig(
129-
root=newhome,
130-
use_datalad=False,
131-
)
132-
)
127+
client = templateflow.client.TemplateFlowClient(root=newhome, use_datalad=False)
133128

134129
assert client.cache.layout.root == str(newhome)
135130

0 commit comments

Comments
 (0)