Skip to content

Commit

Permalink
Merge pull request #55 from pvandyken/main
Browse files Browse the repository at this point in the history
Accepts pathlib.Path as root in bids function
  • Loading branch information
akhanf authored Sep 15, 2021
2 parents d9a7773 + d0b27a8 commit 7d8c90d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions snakebids/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from os.path import join
from collections import OrderedDict
import json
from pathlib import Path
import re
import logging

Expand Down Expand Up @@ -37,7 +38,7 @@ def bids(
Parameters
----------
root : str, default=None
root : str or Path, default=None
root folder to include in the path (e.g. 'results')
datatype : str, default=None
folder to include after sub-/ses- (e.g. anat, dwi )
Expand Down Expand Up @@ -175,6 +176,8 @@ def bids(
# root directory
if isinstance(root, str):
folder.append(root)
elif isinstance(root, Path):
folder.append(str(root.resolve()))

# if prefix is defined, put it before other anything else
if isinstance(prefix, str):
Expand Down Expand Up @@ -473,10 +476,8 @@ def __read_bids_tags(bids_json=None):
dict:
Dictionary of bids tags"""
if bids_json is None:
bids_json = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "bids_tags.json"
)
with open(bids_json, "r") as infile:
bids_json = Path(__file__).parent.resolve() / "bids_tags.json"
with bids_json.open("r") as infile:
bids_tags = json.load(infile)
return bids_tags

Expand Down
5 changes: 5 additions & 0 deletions snakebids/tests/test_bids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from .. import bids


Expand All @@ -6,3 +7,7 @@ def test_bids_subj():
bids(root="bids", subject="001", suffix="T1w.nii.gz")
== "bids/sub-001/sub-001_T1w.nii.gz"
)
assert (
bids(root=Path("bids"), subject="001", suffix="T1w.nii.gz")
== str(Path.cwd() / "bids/sub-001/sub-001_T1w.nii.gz")
)

0 comments on commit 7d8c90d

Please sign in to comment.