diff options
author | QMK Bot <hello@qmk.fm> | 2021-11-04 21:03:11 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2021-11-04 21:03:11 +0000 |
commit | 45a8176e325130775b51058199e69aa8f06c88cc (patch) | |
tree | 34288bbd92020090183fa7561a6d8c8201ad9354 /lib/python/qmk | |
parent | d4bbecb308ced0af9453cc17f11b180d9a934c53 (diff) | |
parent | 6437045166cafab14f2fbe5fcae44f6b066adbc5 (diff) | |
download | qmk_firmware-45a8176e325130775b51058199e69aa8f06c88cc.tar.gz qmk_firmware-45a8176e325130775b51058199e69aa8f06c88cc.zip |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk')
-rw-r--r-- | lib/python/qmk/cli/docs.py | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/python/qmk/cli/docs.py b/lib/python/qmk/cli/docs.py index d8f9b045a..c24b914bc 100644 --- a/lib/python/qmk/cli/docs.py +++ b/lib/python/qmk/cli/docs.py | |||
@@ -2,6 +2,7 @@ | |||
2 | """ | 2 | """ |
3 | import http.server | 3 | import http.server |
4 | import os | 4 | import os |
5 | import shutil | ||
5 | import webbrowser | 6 | import webbrowser |
6 | 7 | ||
7 | from milc import cli | 8 | from milc import cli |
@@ -11,20 +12,33 @@ from milc import cli | |||
11 | @cli.argument('-b', '--browser', action='store_true', help='Open the docs in the default browser.') | 12 | @cli.argument('-b', '--browser', action='store_true', help='Open the docs in the default browser.') |
12 | @cli.subcommand('Run a local webserver for QMK documentation.', hidden=False if cli.config.user.developer else True) | 13 | @cli.subcommand('Run a local webserver for QMK documentation.', hidden=False if cli.config.user.developer else True) |
13 | def docs(cli): | 14 | def docs(cli): |
14 | """Spin up a local HTTPServer instance for the QMK docs. | 15 | """Spin up a local HTTP server for the QMK docs. |
15 | """ | 16 | """ |
16 | os.chdir('docs') | 17 | os.chdir('docs') |
17 | 18 | ||
18 | with http.server.HTTPServer(('', cli.config.docs.port), http.server.SimpleHTTPRequestHandler) as httpd: | 19 | # If docsify-cli is installed, run that instead so we get live reload |
19 | cli.log.info(f"Serving QMK docs at http://localhost:{cli.config.docs.port}/") | 20 | if shutil.which('docsify'): |
20 | cli.log.info("Press Control+C to exit.") | 21 | command = ['docsify', 'serve', '--port', f'{cli.config.docs.port}', '--open' if cli.config.docs.browser else ''] |
21 | 22 | ||
22 | if cli.config.docs.browser: | 23 | cli.log.info(f"Running {{fg_cyan}}{str.join(' ', command)}{{fg_reset}}") |
23 | webbrowser.open(f'http://localhost:{cli.config.docs.port}') | 24 | cli.log.info("Press Control+C to exit.") |
24 | 25 | ||
25 | try: | 26 | try: |
26 | httpd.serve_forever() | 27 | cli.run(command, capture_output=False) |
27 | except KeyboardInterrupt: | 28 | except KeyboardInterrupt: |
28 | cli.log.info("Stopping HTTP server...") | 29 | cli.log.info("Stopping HTTP server...") |
29 | finally: | 30 | else: |
30 | httpd.shutdown() | 31 | # Fall back to Python HTTPServer |
32 | with http.server.HTTPServer(('', cli.config.docs.port), http.server.SimpleHTTPRequestHandler) as httpd: | ||
33 | cli.log.info(f"Serving QMK docs at http://localhost:{cli.config.docs.port}/") | ||
34 | cli.log.info("Press Control+C to exit.") | ||
35 | |||
36 | if cli.config.docs.browser: | ||
37 | webbrowser.open(f'http://localhost:{cli.config.docs.port}') | ||
38 | |||
39 | try: | ||
40 | httpd.serve_forever() | ||
41 | except KeyboardInterrupt: | ||
42 | cli.log.info("Stopping HTTP server...") | ||
43 | finally: | ||
44 | httpd.shutdown() | ||