#!/usr/bin/env python3 """Serve MILC documentation locally You can use this to preview your documentation changes live. Note: You may need to shift-reload twice to clear all caches for some changes. """ import http.server import os from milc import cli @cli.argument('-p', '--port', default=8023, type=int, help='Port number to use.') @cli.entrypoint('Run a local webserver for MILC documentation.') def docs(cli): """Spin up a local HTTPServer instance for the MILC docs. """ os.chdir('docs') with http.server.HTTPServer(('', cli.config.general.port), http.server.SimpleHTTPRequestHandler) as httpd: cli.log.info("Serving MILC docs at http://localhost:%d/", cli.config.general.port) cli.log.info("Press Control+C to exit.") try: httpd.serve_forever() except KeyboardInterrupt: cli.log.info("Stopping HTTP server...") finally: httpd.shutdown() if __name__ == '__main__': cli()