Skip to content

Commit

Permalink
Merge branch 'bids-standard:master' into bep029_motion
Browse files Browse the repository at this point in the history
  • Loading branch information
sjeung authored Aug 25, 2023
2 parents c6810aa + 6677c9a commit 16fd80b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions bids-validator/bids_validator/rules/file_level_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@
"_events\\.tsv",
"_channels\\.json",
"_channels\\.tsv",
"_electrodes\\.json",
"_electrodes\\.tsv",
"_meg\\.json",
"_coordsystem\\.json",
"_photo\\.jpg",
Expand Down
20 changes: 12 additions & 8 deletions bids-validator/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ Deno is a JavaScript and TypeScript runtime that is used to run the schema based

At the root of the repository there are two directories, `bids-validator` and `bids-validator-web`. These are separate npm packages, the Deno validator lives within the bids-validator package within the `src` directory.

## Schema validator examples
## Usage

Deno by default sandboxes applications like a web browser. To validate datasets located on your local system, you need to use the --allow-read flag to read local files. --allow-env is also required to allow for detection of OS specific features. These flags are included in the script line of the `./bids-validator-deno` script.
To use the latest validator hosted at https://deno.land/x/bids_validator, use the following command:

```console
$ deno run --allow-read --allow-env https://deno.land/x/bids_validator/bids-validator.ts path/to/dataset
```

Deno by default sandboxes applications like a web browser. `--allow-read` allows the validator to read local files, and `--allow-env` enables OS-specific features.

### Development tools

From the repository root, use `bids-validator/bids-validator-deno` to run with all permissions enabled by default:

```shell
# Run from within the /bids-validator directory
Expand All @@ -19,12 +29,6 @@ cd bids-validator
./bids-validator-deno path/to/dataset
```

By default only schema derived validation rules are run. The legacy validator can be run at the same time with `--legacy` and this may improve coverage for issues not yet implemented in the schema variant.

```shell
./bids-validator-deno --legacy path/to/dataset
```

## Schema validator test suite

```shell
Expand Down
6 changes: 3 additions & 3 deletions bids-validator/src/files/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export class BIDSFileDeno implements BIDSFile {
name: string
path: string
#fileInfo?: Deno.FileInfo
private _datasetAbsPath: string
#datasetAbsPath: string

constructor(datasetPath: string, path: string, ignore: FileIgnoreRules) {
this._datasetAbsPath = datasetPath
this.#datasetAbsPath = datasetPath
this.path = path
this.name = basename(path)
this.#ignore = ignore
Expand All @@ -42,7 +42,7 @@ export class BIDSFileDeno implements BIDSFile {
}

private _getPath(): string {
return join(this._datasetAbsPath, this.path)
return join(this.#datasetAbsPath, this.path)
}

get size(): number {
Expand Down
12 changes: 10 additions & 2 deletions bids-validator/src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ export class BIDSContext implements Context {
})

if (validSidecars.length > 1) {
// two matching in one dir not allowed
} else if (validSidecars.length === 1) {
const exactMatch = validSidecars.find(sidecar => sidecar.path == this.file.path.replace(this.extension, ".json"));
if (exactMatch) {
validSidecars.splice(1);
validSidecars[0] = exactMatch;
} else {
logger.warning(`Multiple sidecar files detected for '${this.file.path}'`)
}
}

if (validSidecars.length === 1) {
const json = await validSidecars[0]
.text()
.then((text) => JSON.parse(text))
Expand Down

0 comments on commit 16fd80b

Please sign in to comment.