1
+ # ruff: noqa: D100
2
+ # ruff: noqa: D103
3
+
1
4
try :
2
5
import typer
3
6
except ImportError :
4
7
print ('⚠️ CLI dependencies are not installed. Install "bids_validator[cli]"' )
5
8
raise SystemExit (1 ) from None
6
9
7
10
import sys
8
- from typing_extensions import Annotated
9
- import importlib .metadata
11
+ from typing import Annotated
10
12
11
13
from bids_validator import BIDSValidator
12
14
from bids_validator .types .files import FileTree
@@ -32,6 +34,7 @@ def walk(tree: FileTree):
32
34
else :
33
35
yield child
34
36
37
+
35
38
def validate (tree : FileTree ):
36
39
"""Check if the file path is BIDS compliant.
37
40
@@ -44,22 +47,24 @@ def validate(tree: FileTree):
44
47
validator = BIDSValidator ()
45
48
46
49
for file in walk (tree ):
47
- # The output of the FileTree.relative_path method always drops the initial for the path which
48
- # makes it fail the validator.is_bids check. Not sure if it's a Windows specific thing.
50
+ # The output of the FileTree.relative_path method always drops the initial for the path
51
+ # which makes it fail the validator.is_bids check. THis may be a Windows specific thing.
49
52
# This line adds it back.
50
53
path = f'/{ file .relative_path } '
51
54
52
55
if not validator .is_bids (path ):
53
56
print (f'{ path } is not a valid bids filename' )
54
57
58
+
55
59
def show_version ():
56
- """Show bids-validator version
57
- """
60
+ """Show bids-validator version."""
58
61
from . import __version__
62
+
59
63
print (f'bids-validator { __version__ } (Python { sys .version .split ()[0 ]} )' )
60
64
65
+
61
66
def version_callback (value : bool ):
62
- """Callback for CLI version flag
67
+ """Run the callback for CLI version flag.
63
68
64
69
Parameters
65
70
----------
@@ -70,27 +75,29 @@ def version_callback(value: bool):
70
75
------
71
76
typer.Exit
72
77
Exit without any errors
78
+
73
79
"""
74
80
if value :
75
81
show_version ()
76
82
raise typer .Exit ()
77
83
84
+
78
85
@app .command ()
79
86
def main (
80
87
bids_path : str ,
81
- verbose : Annotated [bool , typer .Option (
82
- "--verbose" , "-v" ,
83
- help = "Show verbose output"
84
- )] = False ,
85
- version : Annotated [ bool , typer . Option (
86
- "-- version" ,
87
- help = "Show version" ,
88
- callback = version_callback ,
89
- is_eager = True ,
90
- ) ] = False
88
+ verbose : Annotated [bool , typer .Option ('--verbose' , '-v' , help = 'Show verbose output' )] = False ,
89
+ version : Annotated [
90
+ bool ,
91
+ typer . Option (
92
+ '--version' ,
93
+ help = 'Show version' ,
94
+ callback = version_callback ,
95
+ is_eager = True ,
96
+ ) ,
97
+ ] = False ,
91
98
) -> None :
92
-
93
- if verbose : show_version ()
99
+ if verbose :
100
+ show_version ()
94
101
95
102
root_path = FileTree .read_from_filesystem (bids_path )
96
103
0 commit comments