-
Notifications
You must be signed in to change notification settings - Fork 111
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
Ignore files in _scans.tsv that correspond to entries in .bidsignore (#1366) #1914
base: master
Are you sure you want to change the base?
Changes from 10 commits
67c3c7a
7195fd2
ad2dd28
65da18f
5388f27
9c28a60
e2030b5
a7ca052
c7433af
aa04411
6dacdea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Mock sessionStorage | ||
import getSessionStorage from '../utils/getSessionStorage' | ||
global.sessionStorage = getSessionStorage() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// return sessionStorage based on environment | ||
// uses mock object for use in tests and GitHub workflows | ||
import isNode from './isNode' | ||
|
||
function getSessionStorage() { | ||
if ('sessionStorage' in global) { | ||
// created in setupTests.js; enables data sharing using same object | ||
return global.sessionStorage | ||
} else if (!isNode) { | ||
return window.sessionStorage | ||
} else { | ||
const sessionStorage = {} | ||
|
||
return { | ||
getItem: (key) => sessionStorage[key], | ||
setItem: (key, value) => { | ||
sessionStorage[key] = value | ||
}, | ||
removeItem: (key) => { | ||
delete sessionStorage[key] | ||
}, | ||
clear: () => { | ||
Object.keys(sessionStorage).forEach((key) => | ||
sessionStorage.removeItem(key), | ||
) | ||
}, | ||
} | ||
} | ||
} | ||
|
||
export default getSessionStorage |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,12 @@ import checkStatusCol from './checkStatusCol' | |
import checkTypecol from './checkTypeCol' | ||
import parseTSV from './tsvParser' | ||
import checkMotionComponent from './checkMotionComponent' | ||
import getSessionStorage from '../../utils/getSessionStorage' | ||
import ignore from 'ignore' | ||
var path = require('path') | ||
|
||
const sessionStorage = getSessionStorage() | ||
|
||
/** | ||
* Format TSV headers for evidence string | ||
* @param {Array[string]} headers | ||
|
@@ -612,13 +616,22 @@ const TSV = (file, contents, fileList, callback) => { | |
}), | ||
) | ||
} else { | ||
// Retrieve the .bidsignore content (if any) from session storage | ||
const content = sessionStorage.getItem('bidsignoreContent') | ||
const ig = content ? ignore().add(JSON.parse(content)) : null | ||
|
||
// check scans filenames match pathList | ||
const filenameColumn = headers.indexOf('filename') | ||
for (let l = 1; l < rows.length; l++) { | ||
const row = rows[l] | ||
const scanRelativePath = row[filenameColumn] | ||
const scanFullPath = scanDirPath + '/' + scanRelativePath | ||
|
||
// check if file should be ignored based on .bidsignore content | ||
if (ig && ig.ignores(path.relative('/', scanRelativePath))) { | ||
continue | ||
} | ||
|
||
// check if scan matches full dataset path list | ||
if (!pathList.includes(scanFullPath)) { | ||
Comment on lines
+631
to
636
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I get what you're doing here. Thanks for this! The issue here is that we want to error if a listed file doesn't exist, but we're currently erroring if the file doesn't exist or exists but is ignored. If you're going to follow the strategy you're using here, instead of storing the ignore patterns, you should be storing the ignored files. We can then say if (!(pathList.includes(scanFullPath) || ignoreList.includes(scanFullPath))) { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback @effigies That should also work, just that we would need to store much more data in the session storage (storing ignore patterns vs complete list of ignored files across all subjects and sessions). I'm also curious why the current approach of storing patterns would not suffice; maybe I didn't follow your comment entirely. As per #1366 , the intention was to allow
The PR, in its current form, was intending to just add that one extra check, i.e. for each file listed in I added two tests for checking the following cases:
and both these tests are passing. Note that there is a difference between the file actually existing (on disk) vs being present in the output of |
||
issues.push( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing an error.