main.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """QMK Doctor
  2. Check out the user's QMK environment and make sure it's ready to compile.
  3. """
  4. import platform
  5. from subprocess import DEVNULL
  6. from milc import cli
  7. from milc.questions import yesno
  8. from qmk import submodules
  9. from qmk.constants import QMK_FIRMWARE
  10. from .check import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo
  11. def os_tests():
  12. """Determine our OS and run platform specific tests
  13. """
  14. platform_id = platform.platform().lower()
  15. if 'darwin' in platform_id or 'macos' in platform_id:
  16. from .macos import os_test_macos
  17. return os_test_macos()
  18. elif 'linux' in platform_id:
  19. from .linux import os_test_linux
  20. return os_test_linux()
  21. elif 'windows' in platform_id:
  22. from .windows import os_test_windows
  23. return os_test_windows()
  24. else:
  25. cli.log.warning('Unsupported OS detected: %s', platform_id)
  26. return CheckStatus.WARNING
  27. @cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.')
  28. @cli.argument('-n', '--no', action='store_true', arg_only=True, help='Answer no to all questions.')
  29. @cli.subcommand('Basic QMK environment checks')
  30. def doctor(cli):
  31. """Basic QMK environment checks.
  32. This is currently very simple, it just checks that all the expected binaries are on your system.
  33. TODO(unclaimed):
  34. * [ ] Compile a trivial program with each compiler
  35. """
  36. cli.log.info('QMK Doctor is checking your environment.')
  37. cli.log.info('CLI version: %s', cli.version)
  38. cli.log.info('QMK home: {fg_cyan}%s', QMK_FIRMWARE)
  39. status = os_tests()
  40. # Make sure our QMK home is a Git repo
  41. git_ok = check_git_repo()
  42. if git_ok == CheckStatus.WARNING:
  43. cli.log.warning("QMK home does not appear to be a Git repository! (no .git folder)")
  44. status = CheckStatus.WARNING
  45. # Make sure the basic CLI tools we need are available and can be executed.
  46. bin_ok = check_binaries()
  47. if not bin_ok:
  48. if yesno('Would you like to install dependencies?', default=True):
  49. cli.run(['util/qmk_install.sh', '-y'], stdin=DEVNULL, capture_output=False)
  50. bin_ok = check_binaries()
  51. if bin_ok:
  52. cli.log.info('All dependencies are installed.')
  53. else:
  54. status = CheckStatus.ERROR
  55. # Make sure the tools are at the correct version
  56. ver_ok = check_binary_versions()
  57. if CheckStatus.ERROR in ver_ok:
  58. status = CheckStatus.ERROR
  59. elif CheckStatus.WARNING in ver_ok and status == CheckStatus.OK:
  60. status = CheckStatus.WARNING
  61. # Check out the QMK submodules
  62. sub_ok = check_submodules()
  63. if sub_ok == CheckStatus.OK:
  64. cli.log.info('Submodules are up to date.')
  65. else:
  66. if yesno('Would you like to clone the submodules?', default=True):
  67. submodules.update()
  68. sub_ok = check_submodules()
  69. if sub_ok == CheckStatus.ERROR:
  70. status = CheckStatus.ERROR
  71. elif sub_ok == CheckStatus.WARNING and status == CheckStatus.OK:
  72. status = CheckStatus.WARNING
  73. # Report a summary of our findings to the user
  74. if status == CheckStatus.OK:
  75. cli.log.info('{fg_green}QMK is ready to go')
  76. return 0
  77. elif status == CheckStatus.WARNING:
  78. cli.log.info('{fg_yellow}QMK is ready to go, but minor problems were found')
  79. return 1
  80. else:
  81. cli.log.info('{fg_red}Major problems detected, please fix these problems before proceeding.')
  82. cli.log.info('{fg_blue}Check out the FAQ (https://docs.qmk.fm/#/faq_build) or join the QMK Discord (https://discord.gg/Uq7gcHh) for help.')
  83. return 2