/ serve_docs
serve_docs
 1  #!/usr/bin/env python3
 2  """Serve MILC documentation locally
 3  
 4  You can use this to preview your documentation changes live.
 5  
 6  Note: You may need to shift-reload twice to clear all caches for some changes.
 7  """
 8  import http.server
 9  import os
10  
11  from milc import cli
12  
13  
14  @cli.argument('-p', '--port', default=8023, type=int, help='Port number to use.')
15  @cli.entrypoint('Run a local webserver for MILC documentation.')
16  def docs(cli):
17      """Spin up a local HTTPServer instance for the MILC docs.
18      """
19      os.chdir('docs')
20  
21      with http.server.HTTPServer(('', cli.config.general.port), http.server.SimpleHTTPRequestHandler) as httpd:
22          cli.log.info("Serving MILC docs at http://localhost:%d/", cli.config.general.port)
23          cli.log.info("Press Control+C to exit.")
24  
25          try:
26              httpd.serve_forever()
27          except KeyboardInterrupt:
28              cli.log.info("Stopping HTTP server...")
29          finally:
30              httpd.shutdown()
31  
32  
33  if __name__ == '__main__':
34      cli()