aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/doctor/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/doctor/main.py')
-rwxr-xr-xlib/python/qmk/cli/doctor/main.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/doctor/main.py b/lib/python/qmk/cli/doctor/main.py
new file mode 100755
index 000000000..45b0203b6
--- /dev/null
+++ b/lib/python/qmk/cli/doctor/main.py
@@ -0,0 +1,103 @@
1"""QMK Doctor
2
3Check out the user's QMK environment and make sure it's ready to compile.
4"""
5import platform
6from subprocess import DEVNULL
7
8from milc import cli
9from milc.questions import yesno
10
11from qmk import submodules
12from qmk.constants import QMK_FIRMWARE
13from .check import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo
14
15
16def os_tests():
17 """Determine our OS and run platform specific tests
18 """
19 platform_id = platform.platform().lower()
20
21 if 'darwin' in platform_id or 'macos' in platform_id:
22 from .macos import os_test_macos
23 return os_test_macos()
24 elif 'linux' in platform_id:
25 from .linux import os_test_linux
26 return os_test_linux()
27 elif 'windows' in platform_id:
28 from .windows import os_test_windows
29 return os_test_windows()
30 else:
31 cli.log.warning('Unsupported OS detected: %s', platform_id)
32 return CheckStatus.WARNING
33
34
35@cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.')
36@cli.argument('-n', '--no', action='store_true', arg_only=True, help='Answer no to all questions.')
37@cli.subcommand('Basic QMK environment checks')
38def doctor(cli):
39 """Basic QMK environment checks.
40
41 This is currently very simple, it just checks that all the expected binaries are on your system.
42
43 TODO(unclaimed):
44 * [ ] Compile a trivial program with each compiler
45 """
46 cli.log.info('QMK Doctor is checking your environment.')
47 cli.log.info('QMK home: {fg_cyan}%s', QMK_FIRMWARE)
48
49 status = os_tests()
50
51 # Make sure our QMK home is a Git repo
52 git_ok = check_git_repo()
53
54 if git_ok == CheckStatus.WARNING:
55 cli.log.warning("QMK home does not appear to be a Git repository! (no .git folder)")
56 status = CheckStatus.WARNING
57
58 # Make sure the basic CLI tools we need are available and can be executed.
59 bin_ok = check_binaries()
60
61 if not bin_ok:
62 if yesno('Would you like to install dependencies?', default=True):
63 cli.run(['util/qmk_install.sh', '-y'], stdin=DEVNULL, capture_output=False)
64 bin_ok = check_binaries()
65
66 if bin_ok:
67 cli.log.info('All dependencies are installed.')
68 else:
69 status = CheckStatus.ERROR
70
71 # Make sure the tools are at the correct version
72 ver_ok = check_binary_versions()
73 if CheckStatus.ERROR in ver_ok:
74 status = CheckStatus.ERROR
75 elif CheckStatus.WARNING in ver_ok and status == CheckStatus.OK:
76 status = CheckStatus.WARNING
77
78 # Check out the QMK submodules
79 sub_ok = check_submodules()
80
81 if sub_ok == CheckStatus.OK:
82 cli.log.info('Submodules are up to date.')
83 else:
84 if yesno('Would you like to clone the submodules?', default=True):
85 submodules.update()
86 sub_ok = check_submodules()
87
88 if sub_ok == CheckStatus.ERROR:
89 status = CheckStatus.ERROR
90 elif sub_ok == CheckStatus.WARNING and status == CheckStatus.OK:
91 status = CheckStatus.WARNING
92
93 # Report a summary of our findings to the user
94 if status == CheckStatus.OK:
95 cli.log.info('{fg_green}QMK is ready to go')
96 return 0
97 elif status == CheckStatus.WARNING:
98 cli.log.info('{fg_yellow}QMK is ready to go, but minor problems were found')
99 return 1
100 else:
101 cli.log.info('{fg_red}Major problems detected, please fix these problems before proceeding.')
102 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.')
103 return 2