1515from yarl import URL
1616
1717
18- SETTINGS : Path = Path (' docs/userguide/settings.rst' )
18+ SETTINGS : Path = Path (" docs/userguide/settings.rst" )
1919
20- app = faust .App (' verify_defaults' )
20+ app = faust .App (" verify_defaults" )
2121
2222ignore_settings : Set [str ] = {
23- 'id' ,
24- ' tabledir' ,
25- ' reply_to' ,
26- ' broker_consumer' ,
27- ' broker_producer' ,
23+ "id" ,
24+ " tabledir" ,
25+ " reply_to" ,
26+ " broker_consumer" ,
27+ " broker_producer" ,
2828}
2929
3030builtin_locals : Dict [str , Any ] = {
31- ' aiohttp' : aiohttp ,
32- ' app' : app ,
33- ' datetime' : datetime ,
34- ' datadir' : app .conf .datadir ,
35- ' faust' : faust ,
36- ' logging' : logging ,
37- ' mode' : mode ,
38- ' socket' : socket ,
39- ' timedelta' : timedelta ,
40- ' web_host' : socket .gethostname (),
41- ' web_port' : 6066 ,
42- ' VERSION' : faust .__version__ ,
43- ' uuid' : uuid ,
44- ' URL' : URL ,
31+ " aiohttp" : aiohttp ,
32+ " app" : app ,
33+ " datetime" : datetime ,
34+ " datadir" : app .conf .datadir ,
35+ " faust" : faust ,
36+ " logging" : logging ,
37+ " mode" : mode ,
38+ " socket" : socket ,
39+ " timedelta" : timedelta ,
40+ " web_host" : socket .gethostname (),
41+ " web_port" : 6066 ,
42+ " VERSION" : faust .__version__ ,
43+ " uuid" : uuid ,
44+ " URL" : URL ,
4545}
4646
47- RE_REF = re .compile (r' ^:(\w+):`' )
47+ RE_REF = re .compile (r" ^:(\w+):`" )
4848
4949
5050class Error (NamedTuple ):
@@ -63,7 +63,7 @@ def verify_settings(rst_path: Path) -> Iterator[Error]:
6363 actual = actual .value
6464 if actual != default :
6565 yield Error (
66- reason = ' mismatch' ,
66+ reason = " mismatch" ,
6767 setting = setting_name ,
6868 default = default ,
6969 actual = actual ,
@@ -74,53 +74,54 @@ def report_errors(errors: Iterator[Error]) -> int:
7474 num_errors : int = 0
7575 for num_errors , e in enumerate (errors , start = 1 ):
7676 if num_errors == 1 :
77- carp (f' { sys .argv [0 ]} : Errors in docs/userguide/settings.rst:' )
78- carp (f' + Setting { e .reason } { e .setting } :' )
79- carp (f' documentation: { e .default !r} ' )
80- carp (f' actual: { e .actual !r} ' )
77+ carp (f" { sys .argv [0 ]} : Errors in docs/userguide/settings.rst:" )
78+ carp (f" + Setting { e .reason } { e .setting } :" )
79+ carp (f" documentation: { e .default !r} " )
80+ carp (f" actual: { e .actual !r} " )
8181 if num_errors :
82- carp (f' Found { num_errors } error(s).' , file = sys .stderr )
82+ carp (f" Found { num_errors } error(s)." , file = sys .stderr )
8383 else :
84- print (f' { sys .argv [0 ]} : All OK :-)' , file = sys .stdout )
84+ print (f" { sys .argv [0 ]} : All OK :-)" , file = sys .stdout )
8585 return num_errors
8686
8787
8888def carp (msg , * , file : IO = sys .stderr , ** kwargs : Any ) -> None :
8989 print (msg , file = file , ** kwargs )
9090
9191
92- def find_settings_in_rst (rst_path : Path ,
93- locals : Dict [str , Any ] = None ,
94- builtin_locals : Dict [str , Any ] = builtin_locals ,
95- ignore_settings : Set [str ] = ignore_settings ):
92+ def find_settings_in_rst (
93+ rst_path : Path ,
94+ locals : Dict [str , Any ] = None ,
95+ builtin_locals : Dict [str , Any ] = builtin_locals ,
96+ ignore_settings : Set [str ] = ignore_settings ,
97+ ):
9698 setting : str = None
9799 default : Any = None
98- app = faust .App (' _verify_doc_defaults' )
100+ app = faust .App (" _verify_doc_defaults" )
99101 _globals = dict (globals ())
100102 # Add setting default to globals
101103 # so that defaults referencing another setting work.
102104 # E.g.:
103105 # :default: :setting:`broker_api_version`
104- _globals .update ({
105- name : getattr (app .conf , name )
106- for name in app .conf .setting_names ()
107- })
106+ _globals .update (
107+ {name : getattr (app .conf , name ) for name in app .conf .setting_names ()}
108+ )
108109 local_ns : Dict [str , Any ] = {** builtin_locals , ** (locals or {})}
109110 for line in rst_path .read_text ().splitlines ():
110- if line .startswith (' .. setting::' ):
111+ if line .startswith (" .. setting::" ):
111112 if setting and not default and setting not in ignore_settings :
112- raise Exception (f' No default value for { setting } ' )
113- setting = line .split ('::' )[- 1 ].strip ()
114- elif ' :default:' in line :
115- if '``' in line :
116- line , sep , rest = line .rpartition ('``' )
117- default = line .split (' :default:' )[- 1 ].strip ()
118- default = default .strip ('`' )
119- default = RE_REF .sub ('' , default )
113+ raise Exception (f" No default value for { setting } " )
114+ setting = line .split ("::" )[- 1 ].strip ()
115+ elif " :default:" in line :
116+ if "``" in line :
117+ line , sep , rest = line .rpartition ("``" )
118+ default = line .split (" :default:" )[- 1 ].strip ()
119+ default = default .strip ("`" )
120+ default = RE_REF .sub ("" , default )
120121 default_value = eval (default , _globals , local_ns )
121122 if setting not in ignore_settings :
122123 yield setting , default_value
123124
124125
125- if __name__ == ' __main__' :
126+ if __name__ == " __main__" :
126127 sys .exit (report_errors (verify_settings (SETTINGS )))
0 commit comments