logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

docs.py (1943B)


  1. """Handlers for the QMK documentation generator (docusaurus).
  2. """
  3. import shutil
  4. from pathlib import Path
  5. from subprocess import DEVNULL
  6. from os import chdir, environ, makedirs, pathsep
  7. from milc import cli
  8. from qmk.constants import QMK_FIRMWARE
  9. DOCS_PATH = QMK_FIRMWARE / 'docs'
  10. BUILDDEFS_PATH = QMK_FIRMWARE / 'builddefs' / 'docsgen'
  11. BUILD_PATH = QMK_FIRMWARE / '.build'
  12. CACHE_PATH = BUILD_PATH / 'cache'
  13. NODE_MODULES_PATH = BUILD_PATH / 'node_modules'
  14. BUILD_DOCS_PATH = BUILD_PATH / 'docs'
  15. DOXYGEN_PATH = BUILD_DOCS_PATH / 'static' / 'doxygen'
  16. def run_docs_command(verb, cmd_args=None):
  17. environ['PATH'] += pathsep + str(NODE_MODULES_PATH / '.bin')
  18. args = {'capture_output': False, 'check': True}
  19. docs_env = environ.copy()
  20. if cli.config.general.verbose:
  21. docs_env['DEBUG'] = 'vitepress:*,vite:*'
  22. args['env'] = docs_env
  23. arg_list = ['yarn', verb]
  24. if cmd_args:
  25. arg_list.extend(cmd_args)
  26. chdir(BUILDDEFS_PATH)
  27. cli.run(arg_list, **args)
  28. def prepare_docs_build_area(is_production):
  29. if is_production:
  30. # Set up a symlink for docs to be inside builddefs -- vitepress can't handle source files in parent directories
  31. try:
  32. docs_link = Path(BUILDDEFS_PATH / 'docs')
  33. if not docs_link.exists():
  34. docs_link.symlink_to(DOCS_PATH)
  35. except NotImplementedError:
  36. cli.log.error('Symlinks are not supported on this platform.')
  37. return False
  38. if BUILD_DOCS_PATH.exists():
  39. shutil.rmtree(BUILD_DOCS_PATH)
  40. # When not verbose we want to hide all output
  41. args = {'capture_output': False if cli.config.general.verbose else True, 'check': True, 'stdin': DEVNULL}
  42. makedirs(DOXYGEN_PATH)
  43. cli.log.info('Generating doxygen docs at %s', DOXYGEN_PATH)
  44. cli.run(['doxygen', 'Doxyfile'], **args)
  45. cli.log.info('Installing vitepress dependencies')
  46. run_docs_command('install')
  47. return True