File: serve_docs

package info (click to toggle)
python-milc 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: python: 1,868; sh: 55; makefile: 3
file content (34 lines) | stat: -rwxr-xr-x 982 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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()