22# coding=utf-8
33# Copyright (c) 2018 UT-BATTELLE, LLC
44# All rights reserved.
5- #
5+ #
66# Redistribution and use in source and binary forms, with or without
77# modification, are permitted provided that the following conditions are met:
8- #
8+ #
99# 1. Redistributions of source code must retain the above copyright notice, this
1010# list of conditions and the following disclaimer.
11- #
11+ #
1212# 2. Redistributions in binary form must reproduce the above copyright notice,
1313# this list of conditions and the following disclaimer in the documentation
1414# and/or other materials provided with the distribution.
15- #
15+ #
1616# 3. Neither the name of the copyright holder nor the names of its contributors
1717# may be used to endorse or promote products derived from this software without
1818# specific prior written permission.
19- #
19+ #
2020# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2121# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2222# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3939
4040
4141def parse_args (args = None ):
42- parser = argparse .ArgumentParser (description = __doc__ ,
43- formatter_class = argparse .ArgumentDefaultsHelpFormatter )
44-
45- parser .add_argument ('-e' , '--extensions' ,
46- action = 'store' ,
47- nargs = '+' ,
48- default = None ,
49- help = 'Specify the location of the JSON configuration files for the extended V&V tests to run.' )
50-
51- parser .add_argument ('-o' , '--out-dir' ,
52- default = os .path .join (os .getcwd (), "vv_" + time .strftime ("%Y-%m-%d" )),
53- help = 'Location to output the EVV webpages.' )
54-
55- parser .add_argument ('-s' , '--serve' ,
56- nargs = '?' , type = int , const = 8000 ,
57- help = ' ' .join (['Start a simple HTTP server for the output website specified' ,
58- 'by OUT_DIR on port SERVE.'
59- ])
60- )
61-
62- parser .add_argument ('-p' , '--pool-size' ,
63- nargs = '?' ,
64- type = int ,
65- default = (options .mp .cpu_count () - 1 or 1 ),
66- help = 'The number of multiprocessing processes to run '
67- 'analyses in. If zero, processes will run serially '
68- 'outside of the multiprocessing module.' )
69-
70- parser .add_argument ('--version' ,
71- action = 'version' ,
72- version = 'EVV {}' .format (evv4esm .__version__ ),
73- help = "Show EVV's version number and exit"
74- )
42+ parser = argparse .ArgumentParser (
43+ description = __doc__ , formatter_class = argparse .ArgumentDefaultsHelpFormatter
44+ )
45+
46+ parser .add_argument (
47+ "-e" ,
48+ "--extensions" ,
49+ action = "store" ,
50+ nargs = "+" ,
51+ default = None ,
52+ help = "Specify the location of the JSON configuration files for the extended V&V tests to run." ,
53+ )
54+
55+ parser .add_argument (
56+ "-o" ,
57+ "--out-dir" ,
58+ default = os .path .join (os .getcwd (), "vv_" + time .strftime ("%Y-%m-%d" )),
59+ help = "Location to output the EVV webpages." ,
60+ )
61+
62+ parser .add_argument (
63+ "-s" ,
64+ "--serve" ,
65+ nargs = "?" ,
66+ type = int ,
67+ const = 8000 ,
68+ help = " " .join (
69+ [
70+ "Start a simple HTTP server for the output website specified" ,
71+ "by OUT_DIR on port SERVE." ,
72+ ]
73+ ),
74+ )
75+
76+ parser .add_argument (
77+ "-p" ,
78+ "--pool-size" ,
79+ nargs = "?" ,
80+ type = int ,
81+ default = (options .mp .cpu_count () - 1 or 1 ),
82+ help = "The number of multiprocessing processes to run "
83+ "analyses in. If zero, processes will run serially "
84+ "outside of the multiprocessing module." ,
85+ )
86+
87+ parser .add_argument (
88+ "--version" ,
89+ action = "version" ,
90+ version = "EVV {}" .format (evv4esm .__version__ ),
91+ help = "Show EVV's version number and exit" ,
92+ )
7593
7694 args = parser .parse_args (args )
7795
7896 if args .extensions :
79- options .parse_args (['-V' ] + args .extensions + ['-o' , args .out_dir ])
80-
97+ options .parse_args (["-V" ] + args .extensions + ["-o" , args .out_dir ])
98+
8199 from evv4esm import resources
100+
82101 args .livv_resource_dir = livvkit .resource_dir
83102 livvkit .resource_dir = os .sep .join (resources .__path__ )
84103 return args
85104
86105
87106def main (cl_args = None ):
88- """ Direct execution. """
107+ """Direct execution."""
89108
90109 if cl_args is None and len (sys .argv ) > 1 :
91110 cl_args = sys .argv [1 :]
@@ -123,10 +142,14 @@ def main(cl_args=None):
123142 print (" -----------------------------------------------------------------" )
124143 print ("" )
125144 for conf in livvkit .validation_model_configs :
126- validation_config = functions .merge_dicts (validation_config ,
127- functions .read_json (conf ))
128- summary_elements .extend (scheduler .run_quiet ("validation" , validation , validation_config ,
129- group = False ))
145+ validation_config = functions .merge_dicts (
146+ validation_config , functions .read_json (conf )
147+ )
148+ summary_elements .extend (
149+ scheduler .run_quiet (
150+ "validation" , validation , validation_config , group = False
151+ )
152+ )
130153 print (" -----------------------------------------------------------------" )
131154 print (" Extensions test suite complete " )
132155 print (" -----------------------------------------------------------------" )
@@ -137,28 +160,34 @@ def main(cl_args=None):
137160 index_data .write (result ._repr_json ())
138161 print ("-------------------------------------------------------------------" )
139162 print (" Done! Results can be seen in a web browser at:" )
140- print (" " + os .path .join (livvkit .output_dir , ' index.html' ))
163+ print (" " + os .path .join (livvkit .output_dir , " index.html" ))
141164 print ("-------------------------------------------------------------------" )
142165
143166 if args .serve :
144167 import http .server as server
145168 import socketserver as socket
146169
147- httpd = socket .TCPServer (('' , args .serve ), server .SimpleHTTPRequestHandler )
170+ httpd = socket .TCPServer (("" , args .serve ), server .SimpleHTTPRequestHandler )
148171
149172 sa = httpd .socket .getsockname ()
150- print ('\n Serving HTTP on {host} port {port} (http://{host}:{port}/)' .format (host = sa [0 ], port = sa [1 ]))
151- print ('\n View the generated website by navigating to:' )
152- print ('\n http://{host}:{port}/{path}/index.html' .format (host = sa [0 ], port = sa [1 ],
153- path = os .path .relpath (args .out_dir )
154- ))
155- print ('\n Exit by pressing `ctrl+c` to send a keyboard interrupt.\n ' )
173+ print (
174+ "\n Serving HTTP on {host} port {port} (http://{host}:{port}/)" .format (
175+ host = sa [0 ], port = sa [1 ]
176+ )
177+ )
178+ print ("\n View the generated website by navigating to:" )
179+ print (
180+ "\n http://{host}:{port}/{path}/index.html" .format (
181+ host = sa [0 ], port = sa [1 ], path = os .path .relpath (args .out_dir )
182+ )
183+ )
184+ print ("\n Exit by pressing `ctrl+c` to send a keyboard interrupt.\n " )
156185 try :
157186 httpd .serve_forever ()
158187 except KeyboardInterrupt :
159- print (' \n Keyboard interrupt received, exiting.\n ' )
188+ print (" \n Keyboard interrupt received, exiting.\n " )
160189 sys .exit (0 )
161190
162191
163- if __name__ == ' __main__' :
192+ if __name__ == " __main__" :
164193 main ()
0 commit comments