diff options
Diffstat (limited to 'lib/python/qmk/cli')
| -rw-r--r-- | lib/python/qmk/cli/docs.py | 41 | ||||
| -rw-r--r-- | lib/python/qmk/cli/generate/docs.py | 42 | ||||
| -rw-r--r-- | lib/python/qmk/cli/new/keyboard.py | 2 |
3 files changed, 30 insertions, 55 deletions
diff --git a/lib/python/qmk/cli/docs.py b/lib/python/qmk/cli/docs.py index c24b914bc1..d28dddf194 100644 --- a/lib/python/qmk/cli/docs.py +++ b/lib/python/qmk/cli/docs.py | |||
| @@ -1,44 +1,27 @@ | |||
| 1 | """Serve QMK documentation locally | 1 | """Serve QMK documentation locally |
| 2 | """ | 2 | """ |
| 3 | import http.server | ||
| 4 | import os | ||
| 5 | import shutil | 3 | import shutil |
| 6 | import webbrowser | 4 | from qmk.docs import prepare_docs_build_area, run_docs_command |
| 7 | 5 | ||
| 8 | from milc import cli | 6 | from milc import cli |
| 9 | 7 | ||
| 10 | 8 | ||
| 11 | @cli.argument('-p', '--port', default=8936, type=int, help='Port number to use.') | ||
| 12 | @cli.argument('-b', '--browser', action='store_true', help='Open the docs in the default browser.') | ||
| 13 | @cli.subcommand('Run a local webserver for QMK documentation.', hidden=False if cli.config.user.developer else True) | 9 | @cli.subcommand('Run a local webserver for QMK documentation.', hidden=False if cli.config.user.developer else True) |
| 14 | def docs(cli): | 10 | def docs(cli): |
| 15 | """Spin up a local HTTP server for the QMK docs. | 11 | """Spin up a local HTTP server for the QMK docs. |
| 16 | """ | 12 | """ |
| 17 | os.chdir('docs') | ||
| 18 | 13 | ||
| 19 | # If docsify-cli is installed, run that instead so we get live reload | 14 | if not shutil.which('doxygen'): |
| 20 | if shutil.which('docsify'): | 15 | cli.log.error('doxygen is not installed. Please install it and try again.') |
| 21 | command = ['docsify', 'serve', '--port', f'{cli.config.docs.port}', '--open' if cli.config.docs.browser else ''] | 16 | return |
| 22 | 17 | ||
| 23 | cli.log.info(f"Running {{fg_cyan}}{str.join(' ', command)}{{fg_reset}}") | 18 | if not shutil.which('yarn'): |
| 24 | cli.log.info("Press Control+C to exit.") | 19 | cli.log.error('yarn is not installed. Please install it and try again.') |
| 20 | return | ||
| 25 | 21 | ||
| 26 | try: | 22 | if not prepare_docs_build_area(is_production=False): |
| 27 | cli.run(command, capture_output=False) | 23 | return False |
| 28 | except KeyboardInterrupt: | ||
| 29 | cli.log.info("Stopping HTTP server...") | ||
| 30 | else: | ||
| 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 | 24 | ||
| 36 | if cli.config.docs.browser: | 25 | if not cli.config.general.verbose: |
| 37 | webbrowser.open(f'http://localhost:{cli.config.docs.port}') | 26 | cli.log.info('Serving docs at http://localhost:5173/ (Ctrl+C to stop)') |
| 38 | 27 | run_docs_command('run', 'docs:dev') | |
| 39 | try: | ||
| 40 | httpd.serve_forever() | ||
| 41 | except KeyboardInterrupt: | ||
| 42 | cli.log.info("Stopping HTTP server...") | ||
| 43 | finally: | ||
| 44 | httpd.shutdown() | ||
diff --git a/lib/python/qmk/cli/generate/docs.py b/lib/python/qmk/cli/generate/docs.py index eb3099e138..5821d43b86 100644 --- a/lib/python/qmk/cli/generate/docs.py +++ b/lib/python/qmk/cli/generate/docs.py | |||
| @@ -1,18 +1,12 @@ | |||
| 1 | """Build QMK documentation locally | 1 | """Build QMK documentation locally |
| 2 | """ | 2 | """ |
| 3 | import shutil | 3 | import shutil |
| 4 | from pathlib import Path | 4 | from qmk.docs import prepare_docs_build_area, run_docs_command, BUILD_DOCS_PATH |
| 5 | from subprocess import DEVNULL | ||
| 6 | 5 | ||
| 7 | from milc import cli | 6 | from milc import cli |
| 8 | 7 | ||
| 9 | DOCS_PATH = Path('docs/') | ||
| 10 | BUILD_PATH = Path('.build/') | ||
| 11 | BUILD_DOCS_PATH = BUILD_PATH / 'docs' | ||
| 12 | DOXYGEN_PATH = BUILD_PATH / 'doxygen' | ||
| 13 | MOXYGEN_PATH = BUILD_DOCS_PATH / 'internals' | ||
| 14 | |||
| 15 | 8 | ||
| 9 | @cli.argument('-s', '--serve', arg_only=True, action='store_true', help="Serves the generated docs once built.") | ||
| 16 | @cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True) | 10 | @cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True) |
| 17 | def generate_docs(cli): | 11 | def generate_docs(cli): |
| 18 | """Invoke the docs generation process | 12 | """Invoke the docs generation process |
| @@ -21,24 +15,22 @@ def generate_docs(cli): | |||
| 21 | * [ ] Add a real build step... something static docs | 15 | * [ ] Add a real build step... something static docs |
| 22 | """ | 16 | """ |
| 23 | 17 | ||
| 24 | if BUILD_DOCS_PATH.exists(): | 18 | if not shutil.which('doxygen'): |
| 25 | shutil.rmtree(BUILD_DOCS_PATH) | 19 | cli.log.error('doxygen is not installed. Please install it and try again.') |
| 26 | if DOXYGEN_PATH.exists(): | 20 | return |
| 27 | shutil.rmtree(DOXYGEN_PATH) | ||
| 28 | |||
| 29 | shutil.copytree(DOCS_PATH, BUILD_DOCS_PATH) | ||
| 30 | 21 | ||
| 31 | # When not verbose we want to hide all output | 22 | if not shutil.which('yarn'): |
| 32 | args = { | 23 | cli.log.error('yarn is not installed. Please install it and try again.') |
| 33 | 'capture_output': False if cli.config.general.verbose else True, | 24 | return |
| 34 | 'check': True, | ||
| 35 | 'stdin': DEVNULL, | ||
| 36 | } | ||
| 37 | 25 | ||
| 38 | cli.log.info('Generating docs...') | 26 | if not prepare_docs_build_area(is_production=True): |
| 39 | 27 | return False | |
| 40 | # Generate internal docs | ||
| 41 | cli.run(['doxygen', 'Doxyfile'], **args) | ||
| 42 | cli.run(['moxygen', '-q', '-g', '-o', MOXYGEN_PATH / '%s.md', DOXYGEN_PATH / 'xml'], **args) | ||
| 43 | 28 | ||
| 29 | cli.log.info('Building vitepress docs') | ||
| 30 | run_docs_command('run', 'docs:build') | ||
| 44 | cli.log.info('Successfully generated docs to %s.', BUILD_DOCS_PATH) | 31 | cli.log.info('Successfully generated docs to %s.', BUILD_DOCS_PATH) |
| 32 | |||
| 33 | if cli.args.serve: | ||
| 34 | if not cli.config.general.verbose: | ||
| 35 | cli.log.info('Serving docs at http://localhost:4173/ (Ctrl+C to stop)') | ||
| 36 | run_docs_command('run', 'docs:preview') | ||
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py index 37bf2923d6..56bd05e1e3 100644 --- a/lib/python/qmk/cli/new/keyboard.py +++ b/lib/python/qmk/cli/new/keyboard.py | |||
| @@ -133,7 +133,7 @@ def _question(*args, **kwargs): | |||
| 133 | def prompt_keyboard(): | 133 | def prompt_keyboard(): |
| 134 | prompt = """{fg_yellow}Name Your Keyboard Project{style_reset_all} | 134 | prompt = """{fg_yellow}Name Your Keyboard Project{style_reset_all} |
| 135 | For more infomation, see: | 135 | For more infomation, see: |
| 136 | https://docs.qmk.fm/#/hardware_keyboard_guidelines?id=naming-your-keyboardproject | 136 | https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project |
| 137 | 137 | ||
| 138 | Keyboard Name? """ | 138 | Keyboard Name? """ |
| 139 | 139 | ||
