1414def main ():
1515 parser = argparse .ArgumentParser ()
1616 parser .add_argument (
17- ' --config-file' ,
18- help = ' the path to conf.py' ,
17+ " --config-file" ,
18+ help = " the path to conf.py" ,
1919 )
2020 subparsers = parser .add_subparsers (
21- title = ' commands' ,
22- description = ' valid commands' ,
23- dest = ' command' ,
21+ title = " commands" ,
22+ description = " valid commands" ,
23+ dest = " command" ,
2424 )
2525
2626 do_render = subparsers .add_parser (
27- ' render' ,
28- help = ' render a template to stdout' ,
27+ " render" ,
28+ help = " render a template to stdout" ,
2929 )
3030 do_render .add_argument (
31- ' --option' ,
32- '-o' ,
33- action = ' append' ,
31+ " --option" ,
32+ "-o" ,
33+ action = " append" ,
3434 default = [],
35- help = ' options given as key:value passed through to loader and template'
35+ help = " options given as key:value passed through to loader and template" ,
3636 )
3737 do_render .add_argument (
38- ' template' ,
39- help = ' the path to the template file' ,
38+ " template" ,
39+ help = " the path to the template file" ,
4040 )
4141 do_render .add_argument (
42- ' source' ,
43- help = ' the path to the data file' ,
42+ " source" ,
43+ help = " the path to the data file" ,
4444 )
4545 do_render .set_defaults (func = render )
4646
4747 do_dump = subparsers .add_parser (
48- ' dump' ,
49- help = ' dump the data to stdout without a template' ,
48+ " dump" ,
49+ help = " dump the data to stdout without a template" ,
5050 )
5151 do_dump .add_argument (
52- ' --option' ,
53- '-o' ,
54- action = ' append' ,
52+ " --option" ,
53+ "-o" ,
54+ action = " append" ,
5555 default = [],
56- help = ' options given as key:value passed through to loader and template'
56+ help = " options given as key:value passed through to loader and template" ,
5757 )
5858 do_dump .add_argument (
59- ' source' ,
60- help = ' the path to the data file' ,
59+ " source" ,
60+ help = " the path to the data file" ,
6161 )
6262 do_dump .set_defaults (func = dump )
6363
@@ -69,7 +69,7 @@ def main():
6969
7070 conf = {}
7171 if args .config_file :
72- with io .open (args .config_file , 'r' , encoding = ' utf-8-sig' ) as f :
72+ with io .open (args .config_file , "r" , encoding = " utf-8-sig" ) as f :
7373 config_body = f .read ()
7474 exec (config_body , conf )
7575
@@ -82,58 +82,58 @@ def _parse_options(options):
8282 # treat the option as a flag.
8383 results = {}
8484 for opt in options :
85- if ':' in opt :
86- k , _ , v = opt .partition (':' )
85+ if ":" in opt :
86+ k , _ , v = opt .partition (":" )
8787 else :
8888 k = opt
8989 v = True
90- results [k .replace ('-' , '_' )] = v
90+ results [k .replace ("-" , "_" )] = v
9191 return results
9292
9393
9494def render (args , conf ):
9595 conf .update (_parse_options (args .option ))
96- conf .update ({
97- "source" : args .source ,
98- "template" : args .template ,
99- "absolute_resolved_path" : os .path .abspath (args .source )
100- })
96+ conf .update (
97+ {
98+ "source" : args .source ,
99+ "template" : args .template ,
100+ "absolute_resolved_path" : os .path .abspath (args .source ),
101+ }
102+ )
101103
102104 load = loaders .loader_for_source (args .source )
103105 if load is None :
104- print (' Could not find loader for {}' .format (args .source ))
106+ print (" Could not find loader for {}" .format (args .source ))
105107 return 1
106108
107- with io .open (args .template , 'r' , encoding = ' utf-8-sig' ) as f :
109+ with io .open (args .template , "r" , encoding = " utf-8-sig" ) as f :
108110 template_body = f .read ()
109111
110112 template = jinja2 .Template (template_body )
111113 with load (** conf ) as data :
112114 rendered = template .render (
113115 make_list_table = helpers .make_list_table ,
114- make_list_table_from_mappings = helpers .
115- make_list_table_from_mappings ,
116+ make_list_table_from_mappings = helpers .make_list_table_from_mappings ,
116117 data = data ,
117- ** conf
118+ ** conf ,
118119 )
119120 print (rendered )
120121
121122
122123def dump (args , conf ):
123124 conf .update (_parse_options (args .option ))
124- conf .update ({
125- "source" : args .source ,
126- "absolute_resolved_path" : os .path .abspath (args .source )
127- })
125+ conf .update (
126+ {"source" : args .source , "absolute_resolved_path" : os .path .abspath (args .source )}
127+ )
128128
129129 load = loaders .loader_for_source (args .source )
130130 if load is None :
131- print (' Could not find loader for {}' .format (args .source ))
131+ print (" Could not find loader for {}" .format (args .source ))
132132 return 1
133133
134134 with load (** conf ) as data :
135135 pprint .pprint (data )
136136
137137
138- if __name__ == ' __main__' :
138+ if __name__ == " __main__" :
139139 main ()
0 commit comments