pybids icon indicating copy to clipboard operation
pybids copied to clipboard

issues with window regex in python 3.7

Open BarRozenman opened this issue 3 years ago • 2 comments

when trying to use

from bids import BIDSLayout
layout = BIDSLayout(r'\\wsl$\Ubuntu-20.04\home\***\mri_data\scans\BIDS\img_emo_dataset/rawdata')
layout.get(return_type='dir', target='subject')

on a valid BIDS dataset on python 3.7 on windows 10 I get and an exception I use data that is stored on WSL2 by windows but the python I'm running in on the windows OS :

Traceback (most recent call last): File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 924, in parse p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0) File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 420, in _parse_sub not nested and not items)) File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 501, in _parse code = _escape(source, this, state) File "C:\Users*\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 369, in _escape raise source.error("incomplete escape %s" % escape, len(escape)) re.error: incomplete escape \Ub at position 6

I'm not sure what the issue is... but all other byBIDS methods seem to work perfectly

BarRozenman avatar Mar 02 '21 12:03 BarRozenman

@BarRozenman thanks for the report. The problem is coming from this line: the concatenation of various strings (the project root, entity pattern, etc.) ends up creating an unholy mishmash of escaped and unescaped strings that, when passed to re.search() does bad things. Unfortunately, I think this will require a bit of thought to properly accommodate Windows paths, and since we don't officially support Windows in any case, it may take a while to get around to.

My rather unhelpful short-term suggestion is to work around the issue by avoiding return_type='dir' and instead retrieving some other type of file that varies by subject, and then looping over that and extracting the subject directories manually. Apologies for the inconvenience! Will mark this a bug and leave it open until someone has the bandwidth to fix it. Thanks again!

tyarkoni avatar Mar 03 '21 17:03 tyarkoni

Thank you very much for the fast replay and advice, looking forward to see it fixed whenever 😁

BarRozenman avatar Mar 03 '21 20:03 BarRozenman