23
23
from sphinx_autobuild .utils import find_free_port , open_browser , show
24
24
25
25
26
- def main ():
26
+ def main (argv = () ):
27
27
"""Actual application logic."""
28
28
colorama .init ()
29
29
30
- args , build_args = _parse_args (sys . argv [ 1 :] )
30
+ args , build_args = _parse_args (list ( argv ) )
31
31
32
32
src_dir = args .sourcedir
33
33
out_dir = args .outdir
@@ -47,20 +47,12 @@ def main():
47
47
)
48
48
49
49
watch_dirs = [src_dir ] + args .additional_watched_dirs
50
+ ignore_dirs = args .ignore + [out_dir , args .warnings_file , args .doctree_dir ]
50
51
ignore_handler = IgnoreFilter (
51
- [p for p in args . ignore + [ out_dir , args . warnings_file , args . doctree_dir ] if p ],
52
+ [p for p in ignore_dirs if p ],
52
53
args .re_ignore ,
53
54
)
54
- watcher = RebuildServer (watch_dirs , ignore_handler , change_callback = builder )
55
-
56
- app = Starlette (
57
- routes = [
58
- WebSocketRoute ("/websocket-reload" , watcher , name = "reload" ),
59
- Mount ("/" , app = StaticFiles (directory = out_dir , html = True ), name = "static" ),
60
- ],
61
- middleware = [Middleware (JavascriptInjectorMiddleware , ws_url = url_host )],
62
- lifespan = watcher .lifespan ,
63
- )
55
+ app = _create_app (watch_dirs , ignore_handler , builder , out_dir , url_host )
64
56
65
57
if not args .no_initial_build :
66
58
show (context = "Starting initial build" )
@@ -76,6 +68,19 @@ def main():
76
68
show (context = "Server ceasing operations. Cheerio!" )
77
69
78
70
71
+ def _create_app (watch_dirs , ignore_handler , builder , out_dir , url_host ):
72
+ watcher = RebuildServer (watch_dirs , ignore_handler , change_callback = builder )
73
+
74
+ return Starlette (
75
+ routes = [
76
+ WebSocketRoute ("/websocket-reload" , watcher , name = "reload" ),
77
+ Mount ("/" , app = StaticFiles (directory = out_dir , html = True ), name = "static" ),
78
+ ],
79
+ middleware = [Middleware (JavascriptInjectorMiddleware , ws_url = url_host )],
80
+ lifespan = watcher .lifespan ,
81
+ )
82
+
83
+
79
84
def _parse_args (argv ):
80
85
# Parse once with the Sphinx parser to emit errors
81
86
# and capture the ``-d`` and ``-w`` options.
@@ -197,4 +202,4 @@ def _add_autobuild_arguments(parser):
197
202
198
203
199
204
if __name__ == "__main__" :
200
- main ()
205
+ main (sys . argv [ 1 :] )
0 commit comments