Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We're naively performing string replacements in paths, leading to issues #832

Closed
hoechenberger opened this issue Jul 6, 2021 · 2 comments
Assignees
Labels

Comments

@hoechenberger
Copy link
Member

MWE:

# %%
from pathlib import Path
import tempfile
import mne
import mne_bids

sample_dir = Path(mne.datasets.sample.data_path())
sample_fname = sample_dir / 'MEG' / 'sample' / 'sample_audvis_raw.fif'

raw = mne.io.read_raw_fif(sample_fname, preload=False)

with tempfile.TemporaryDirectory() as tempdir:
    root = Path(tempdir) / 'some_path_with_tsv'

    bids_path = mne_bids.BIDSPath(
        subject='foo', task='bar', root=root,
        suffix='meg', datatype='meg', extension='.fif'
    )
    mne_bids.write_raw_bids(raw=raw, bids_path=bids_path)

Yields:

FileNotFoundError: [Errno 2] No such file or directory: 
'/var/folders/xg/7d96k64d7jv9q1d88_s8swjh0000gn/T/tmp5xdixz1g/some_path_with_json/participants.json'

See how the directory name some_path_with_tsv was changed to some_path_with_json.

Issue originates from here:

mne-bids/mne_bids/write.py

Lines 1348 to 1349 in 11e3efc

participants_json_fname = participants_tsv_fname.replace('tsv',
'json')

Quick & dirty fix: instead of replacing tsv, we should only replace .tsv. But this still leaves room for problems.

Cleaner solution would be to rely e.g. on pathlib to help us find the filename extension, and only operate on that.

@agramfort
Copy link
Member

can we close this now @hoechenberger ?

@hoechenberger
Copy link
Member Author

It's something we should address someday, but I don't think it's much use to keep this issue around, so yeah let's close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants