Skip to content

Commit ec95584

Browse files
authored
Merge pull request #101 from templateflow/enh/access-to-pybids-goodies
ENH: Allow access to PyBIDS' magic ``get_*``
2 parents 3c1f2cb + 2227ce4 commit ec95584

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

templateflow/api.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""TemplateFlow's Python Client."""
2+
import sys
3+
from importlib import import_module
24
from json import loads
35
from pathlib import Path
4-
import sys
56
from bids.layout import Query
67

78
from .conf import TF_LAYOUT, TF_S3_ROOT, TF_USE_DATALAD, requires_layout
@@ -249,6 +250,16 @@ def get_citations(template, bibtex=False):
249250
return [_to_bibtex(ref, template, idx).rstrip() for idx, ref in enumerate(refs, 1)]
250251

251252

253+
@requires_layout
254+
def __getattr__(key: str):
255+
key = key.replace("ls_", "get_")
256+
if key.startswith("get_") and key not in ("get_metadata", "get_citations"):
257+
return TF_LAYOUT.__getattr__(key)
258+
259+
# Spit out default message if we get this far
260+
raise AttributeError(f"module '{__name__}' has no attribute '{key}'")
261+
262+
252263
def _datalad_get(filepath):
253264
if not filepath:
254265
return

templateflow/tests/test_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,14 @@ def test_citations(tmp_path, template, urls, fbib, lbib):
9797
else:
9898
# no citations currently
9999
assert False
100+
101+
102+
def test_pybids_magic_get():
103+
"""Check automatic entity expansion of the layout."""
104+
assert sorted(api.ls_atlases()) == sorted(api.TF_LAYOUT.get_atlases())
105+
assert sorted(api.ls_atlases(template="MNI152NLin6ASym")) == sorted(
106+
api.TF_LAYOUT.get_atlases(template="MNI152NLin6ASym")
107+
)
108+
109+
with pytest.raises(TypeError):
110+
api.ls_atlases("MNI152NLin6ASym")

0 commit comments

Comments
 (0)