44import re
55import sys
66from itertools import chain
7+ from pathlib import Path
78
89import click
910
1819@click .group ()
1920@click .option ("-v" , "--verbose" , count = True )
2021@click .option ("-q" , "--quiet" , count = True )
21- def cli (verbose , quiet ) :
22+ def cli (verbose : int , quiet : int ) -> None :
2223 """BIDS Schema Tools"""
2324 verbose = verbose - quiet
2425 configure_logger (get_logger (level = logging .WARNING - verbose * 10 ))
2526
2627
2728@cli .command ()
28- @click .option ("--schema" )
29+ @click .option ("--schema" , "-s" , "schema_path" , type = click . Path (), help = "Path to the BIDS schema" )
2930@click .option ("--output" , default = "-" )
3031@click .pass_context
31- def export (ctx , schema , output ) :
32+ def export (ctx : click . Context , schema_path : Path | None , output : Path | str ) -> None :
3233 """Export BIDS schema to JSON document"""
33- schema = load_schema (schema )
34+ schema = load_schema (schema_path )
3435 text = schema .to_json ()
3536 if output == "-" :
3637 lgr .debug ("Writing to stdout" )
@@ -45,7 +46,7 @@ def export(ctx, schema, output):
4546@cli .command ()
4647@click .option ("--output" , default = "-" )
4748@click .pass_context
48- def export_metaschema (ctx , output ) :
49+ def export_metaschema (ctx : click . Context , output : Path | str ) -> None :
4950 """Export BIDS schema to JSON document"""
5051 from .data import load
5152
@@ -59,7 +60,7 @@ def export_metaschema(ctx, output):
5960
6061
6162@cli .command ("pre-receive-hook" )
62- @click .option ("--schema" , "-s" , type = click .Path (), help = "Path to the BIDS schema" )
63+ @click .option ("--schema" , "-s" , "schema_path" , type = click .Path (), help = "Path to the BIDS schema" )
6364@click .option (
6465 "--input" , "-i" , "input_" , default = "-" , type = click .Path (), help = "Input file (default: stdin)"
6566)
@@ -71,7 +72,7 @@ def export_metaschema(ctx, output):
7172 type = click .Path (),
7273 help = "Output file (default: stdout)" ,
7374)
74- def pre_receive_hook (schema , input_ , output ) :
75+ def pre_receive_hook (schema_path : Path | None , input_ : Path | str , output : Path | str ) -> None :
7576 """Validate filenames from a list of files against the BIDS schema
7677
7778 The expected input takes the following form:
@@ -101,7 +102,7 @@ def pre_receive_hook(schema, input_, output):
101102
102103 This is intended to be used in a git pre-receive hook.
103104 """
104- schema = load_schema (schema )
105+ schema = load_schema (schema_path )
105106
106107 # Slurp inputs for now; we can think about streaming later
107108 if input_ == "-" :
@@ -151,12 +152,12 @@ def pre_receive_hook(schema, input_, output):
151152
152153 regexes = [rule ["regex" ] for rule in all_rules ]
153154
154- output = sys .stdout if output == "-" else open (output , "w" )
155+ out_stream = sys .stdout if output == "-" else open (output , "w" )
155156
156157 rc = 0
157158 any_files = False
158159 valid_files = 0
159- with output :
160+ with out_stream :
160161 for filename in stream :
161162 if not any_files :
162163 lgr .debug ("Validating files, first file: %s" , filename )
@@ -167,7 +168,7 @@ def pre_receive_hook(schema, input_, output):
167168 ):
168169 continue
169170 if not any (re .match (regex , filename ) for regex in regexes ):
170- print (filename , file = output )
171+ print (filename , file = out_stream )
171172 rc = 1
172173 else :
173174 valid_files += 1
0 commit comments