diff options
Diffstat (limited to 'lib/python')
-rwxr-xr-x | lib/python/qmk/cli/doctor/__init__.py | 5 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/check.py (renamed from lib/python/qmk/os_helpers/__init__.py) | 18 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/linux.py (renamed from lib/python/qmk/os_helpers/linux/__init__.py) | 26 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/macos.py | 13 | ||||
-rwxr-xr-x | lib/python/qmk/cli/doctor/main.py (renamed from lib/python/qmk/cli/doctor.py) | 43 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/windows.py | 14 |
6 files changed, 70 insertions, 49 deletions
diff --git a/lib/python/qmk/cli/doctor/__init__.py b/lib/python/qmk/cli/doctor/__init__.py new file mode 100755 index 000000000..272e04202 --- /dev/null +++ b/lib/python/qmk/cli/doctor/__init__.py | |||
@@ -0,0 +1,5 @@ | |||
1 | """QMK Doctor | ||
2 | |||
3 | Check out the user's QMK environment and make sure it's ready to compile. | ||
4 | """ | ||
5 | from .main import doctor | ||
diff --git a/lib/python/qmk/os_helpers/__init__.py b/lib/python/qmk/cli/doctor/check.py index 3e98db3c3..a0bbb2816 100644 --- a/lib/python/qmk/os_helpers/__init__.py +++ b/lib/python/qmk/cli/doctor/check.py | |||
@@ -1,4 +1,4 @@ | |||
1 | """OS-agnostic helper functions | 1 | """Check for specific programs. |
2 | """ | 2 | """ |
3 | from enum import Enum | 3 | from enum import Enum |
4 | import re | 4 | import re |
@@ -30,7 +30,7 @@ ESSENTIAL_BINARIES = { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | 32 | ||
33 | def parse_gcc_version(version): | 33 | def _parse_gcc_version(version): |
34 | m = re.match(r"(\d+)(?:\.(\d+))?(?:\.(\d+))?", version) | 34 | m = re.match(r"(\d+)(?:\.(\d+))?(?:\.(\d+))?", version) |
35 | 35 | ||
36 | return { | 36 | return { |
@@ -40,7 +40,7 @@ def parse_gcc_version(version): | |||
40 | } | 40 | } |
41 | 41 | ||
42 | 42 | ||
43 | def check_arm_gcc_version(): | 43 | def _check_arm_gcc_version(): |
44 | """Returns True if the arm-none-eabi-gcc version is not known to cause problems. | 44 | """Returns True if the arm-none-eabi-gcc version is not known to cause problems. |
45 | """ | 45 | """ |
46 | if 'output' in ESSENTIAL_BINARIES['arm-none-eabi-gcc']: | 46 | if 'output' in ESSENTIAL_BINARIES['arm-none-eabi-gcc']: |
@@ -50,7 +50,7 @@ def check_arm_gcc_version(): | |||
50 | return CheckStatus.OK # Right now all known arm versions are ok | 50 | return CheckStatus.OK # Right now all known arm versions are ok |
51 | 51 | ||
52 | 52 | ||
53 | def check_avr_gcc_version(): | 53 | def _check_avr_gcc_version(): |
54 | """Returns True if the avr-gcc version is not known to cause problems. | 54 | """Returns True if the avr-gcc version is not known to cause problems. |
55 | """ | 55 | """ |
56 | rc = CheckStatus.ERROR | 56 | rc = CheckStatus.ERROR |
@@ -60,7 +60,7 @@ def check_avr_gcc_version(): | |||
60 | cli.log.info('Found avr-gcc version %s', version_number) | 60 | cli.log.info('Found avr-gcc version %s', version_number) |
61 | rc = CheckStatus.OK | 61 | rc = CheckStatus.OK |
62 | 62 | ||
63 | parsed_version = parse_gcc_version(version_number) | 63 | parsed_version = _parse_gcc_version(version_number) |
64 | if parsed_version['major'] > 8: | 64 | if parsed_version['major'] > 8: |
65 | cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.') | 65 | cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.') |
66 | rc = CheckStatus.WARNING | 66 | rc = CheckStatus.WARNING |
@@ -68,7 +68,7 @@ def check_avr_gcc_version(): | |||
68 | return rc | 68 | return rc |
69 | 69 | ||
70 | 70 | ||
71 | def check_avrdude_version(): | 71 | def _check_avrdude_version(): |
72 | if 'output' in ESSENTIAL_BINARIES['avrdude']: | 72 | if 'output' in ESSENTIAL_BINARIES['avrdude']: |
73 | last_line = ESSENTIAL_BINARIES['avrdude']['output'].split('\n')[-2] | 73 | last_line = ESSENTIAL_BINARIES['avrdude']['output'].split('\n')[-2] |
74 | version_number = last_line.split()[2][:-1] | 74 | version_number = last_line.split()[2][:-1] |
@@ -77,7 +77,7 @@ def check_avrdude_version(): | |||
77 | return CheckStatus.OK | 77 | return CheckStatus.OK |
78 | 78 | ||
79 | 79 | ||
80 | def check_dfu_util_version(): | 80 | def _check_dfu_util_version(): |
81 | if 'output' in ESSENTIAL_BINARIES['dfu-util']: | 81 | if 'output' in ESSENTIAL_BINARIES['dfu-util']: |
82 | first_line = ESSENTIAL_BINARIES['dfu-util']['output'].split('\n')[0] | 82 | first_line = ESSENTIAL_BINARIES['dfu-util']['output'].split('\n')[0] |
83 | version_number = first_line.split()[1] | 83 | version_number = first_line.split()[1] |
@@ -86,7 +86,7 @@ def check_dfu_util_version(): | |||
86 | return CheckStatus.OK | 86 | return CheckStatus.OK |
87 | 87 | ||
88 | 88 | ||
89 | def check_dfu_programmer_version(): | 89 | def _check_dfu_programmer_version(): |
90 | if 'output' in ESSENTIAL_BINARIES['dfu-programmer']: | 90 | if 'output' in ESSENTIAL_BINARIES['dfu-programmer']: |
91 | first_line = ESSENTIAL_BINARIES['dfu-programmer']['output'].split('\n')[0] | 91 | first_line = ESSENTIAL_BINARIES['dfu-programmer']['output'].split('\n')[0] |
92 | version_number = first_line.split()[1] | 92 | version_number = first_line.split()[1] |
@@ -111,7 +111,7 @@ def check_binary_versions(): | |||
111 | """Check the versions of ESSENTIAL_BINARIES | 111 | """Check the versions of ESSENTIAL_BINARIES |
112 | """ | 112 | """ |
113 | versions = [] | 113 | versions = [] |
114 | for check in (check_arm_gcc_version, check_avr_gcc_version, check_avrdude_version, check_dfu_util_version, check_dfu_programmer_version): | 114 | for check in (_check_arm_gcc_version, _check_avr_gcc_version, _check_avrdude_version, _check_dfu_util_version, _check_dfu_programmer_version): |
115 | versions.append(check()) | 115 | versions.append(check()) |
116 | return versions | 116 | return versions |
117 | 117 | ||
diff --git a/lib/python/qmk/os_helpers/linux/__init__.py b/lib/python/qmk/cli/doctor/linux.py index 008654ab0..c0b77216a 100644 --- a/lib/python/qmk/os_helpers/linux/__init__.py +++ b/lib/python/qmk/cli/doctor/linux.py | |||
@@ -1,11 +1,13 @@ | |||
1 | """OS-specific functions for: Linux | 1 | """OS-specific functions for: Linux |
2 | """ | 2 | """ |
3 | from pathlib import Path | 3 | import platform |
4 | import shutil | 4 | import shutil |
5 | from pathlib import Path | ||
5 | 6 | ||
6 | from milc import cli | 7 | from milc import cli |
8 | |||
7 | from qmk.constants import QMK_FIRMWARE | 9 | from qmk.constants import QMK_FIRMWARE |
8 | from qmk.os_helpers import CheckStatus | 10 | from .check import CheckStatus |
9 | 11 | ||
10 | 12 | ||
11 | def _udev_rule(vid, pid=None, *args): | 13 | def _udev_rule(vid, pid=None, *args): |
@@ -138,3 +140,23 @@ def check_modem_manager(): | |||
138 | """(TODO): Add check for non-systemd systems | 140 | """(TODO): Add check for non-systemd systems |
139 | """ | 141 | """ |
140 | return False | 142 | return False |
143 | |||
144 | |||
145 | def os_test_linux(): | ||
146 | """Run the Linux specific tests. | ||
147 | """ | ||
148 | # Don't bother with udev on WSL, for now | ||
149 | if 'microsoft' in platform.uname().release.lower(): | ||
150 | cli.log.info("Detected {fg_cyan}Linux (WSL){fg_reset}.") | ||
151 | |||
152 | # https://github.com/microsoft/WSL/issues/4197 | ||
153 | if QMK_FIRMWARE.as_posix().startswith("/mnt"): | ||
154 | cli.log.warning("I/O performance on /mnt may be extremely slow.") | ||
155 | return CheckStatus.WARNING | ||
156 | |||
157 | return CheckStatus.OK | ||
158 | else: | ||
159 | cli.log.info("Detected {fg_cyan}Linux{fg_reset}.") | ||
160 | from .linux import check_udev_rules | ||
161 | |||
162 | return check_udev_rules() | ||
diff --git a/lib/python/qmk/cli/doctor/macos.py b/lib/python/qmk/cli/doctor/macos.py new file mode 100644 index 000000000..00fb27285 --- /dev/null +++ b/lib/python/qmk/cli/doctor/macos.py | |||
@@ -0,0 +1,13 @@ | |||
1 | import platform | ||
2 | |||
3 | from milc import cli | ||
4 | |||
5 | from .check import CheckStatus | ||
6 | |||
7 | |||
8 | def os_test_macos(): | ||
9 | """Run the Mac specific tests. | ||
10 | """ | ||
11 | cli.log.info("Detected {fg_cyan}macOS %s{fg_reset}.", platform.mac_ver()[0]) | ||
12 | |||
13 | return CheckStatus.OK | ||
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor/main.py index 9e1057062..45b0203b6 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor/main.py | |||
@@ -7,9 +7,10 @@ from subprocess import DEVNULL | |||
7 | 7 | ||
8 | from milc import cli | 8 | from milc import cli |
9 | from milc.questions import yesno | 9 | from milc.questions import yesno |
10 | |||
10 | from qmk import submodules | 11 | from qmk import submodules |
11 | from qmk.constants import QMK_FIRMWARE | 12 | from qmk.constants import QMK_FIRMWARE |
12 | from qmk.os_helpers import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo | 13 | from .check import CheckStatus, check_binaries, check_binary_versions, check_submodules, check_git_repo |
13 | 14 | ||
14 | 15 | ||
15 | def os_tests(): | 16 | def os_tests(): |
@@ -18,53 +19,19 @@ def os_tests(): | |||
18 | platform_id = platform.platform().lower() | 19 | platform_id = platform.platform().lower() |
19 | 20 | ||
20 | if 'darwin' in platform_id or 'macos' in platform_id: | 21 | if 'darwin' in platform_id or 'macos' in platform_id: |
22 | from .macos import os_test_macos | ||
21 | return os_test_macos() | 23 | return os_test_macos() |
22 | elif 'linux' in platform_id: | 24 | elif 'linux' in platform_id: |
25 | from .linux import os_test_linux | ||
23 | return os_test_linux() | 26 | return os_test_linux() |
24 | elif 'windows' in platform_id: | 27 | elif 'windows' in platform_id: |
28 | from .windows import os_test_windows | ||
25 | return os_test_windows() | 29 | return os_test_windows() |
26 | else: | 30 | else: |
27 | cli.log.warning('Unsupported OS detected: %s', platform_id) | 31 | cli.log.warning('Unsupported OS detected: %s', platform_id) |
28 | return CheckStatus.WARNING | 32 | return CheckStatus.WARNING |
29 | 33 | ||
30 | 34 | ||
31 | def os_test_linux(): | ||
32 | """Run the Linux specific tests. | ||
33 | """ | ||
34 | # Don't bother with udev on WSL, for now | ||
35 | if 'microsoft' in platform.uname().release.lower(): | ||
36 | cli.log.info("Detected {fg_cyan}Linux (WSL){fg_reset}.") | ||
37 | |||
38 | # https://github.com/microsoft/WSL/issues/4197 | ||
39 | if QMK_FIRMWARE.as_posix().startswith("/mnt"): | ||
40 | cli.log.warning("I/O performance on /mnt may be extremely slow.") | ||
41 | return CheckStatus.WARNING | ||
42 | |||
43 | return CheckStatus.OK | ||
44 | else: | ||
45 | cli.log.info("Detected {fg_cyan}Linux{fg_reset}.") | ||
46 | from qmk.os_helpers.linux import check_udev_rules | ||
47 | |||
48 | return check_udev_rules() | ||
49 | |||
50 | |||
51 | def os_test_macos(): | ||
52 | """Run the Mac specific tests. | ||
53 | """ | ||
54 | cli.log.info("Detected {fg_cyan}macOS %s{fg_reset}.", platform.mac_ver()[0]) | ||
55 | |||
56 | return CheckStatus.OK | ||
57 | |||
58 | |||
59 | def os_test_windows(): | ||
60 | """Run the Windows specific tests. | ||
61 | """ | ||
62 | win32_ver = platform.win32_ver() | ||
63 | cli.log.info("Detected {fg_cyan}Windows %s (%s){fg_reset}.", win32_ver[0], win32_ver[1]) | ||
64 | |||
65 | return CheckStatus.OK | ||
66 | |||
67 | |||
68 | @cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.') | 35 | @cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.') |
69 | @cli.argument('-n', '--no', action='store_true', arg_only=True, help='Answer no to all questions.') | 36 | @cli.argument('-n', '--no', action='store_true', arg_only=True, help='Answer no to all questions.') |
70 | @cli.subcommand('Basic QMK environment checks') | 37 | @cli.subcommand('Basic QMK environment checks') |
diff --git a/lib/python/qmk/cli/doctor/windows.py b/lib/python/qmk/cli/doctor/windows.py new file mode 100644 index 000000000..381ab36fd --- /dev/null +++ b/lib/python/qmk/cli/doctor/windows.py | |||
@@ -0,0 +1,14 @@ | |||
1 | import platform | ||
2 | |||
3 | from milc import cli | ||
4 | |||
5 | from .check import CheckStatus | ||
6 | |||
7 | |||
8 | def os_test_windows(): | ||
9 | """Run the Windows specific tests. | ||
10 | """ | ||
11 | win32_ver = platform.win32_ver() | ||
12 | cli.log.info("Detected {fg_cyan}Windows %s (%s){fg_reset}.", win32_ver[0], win32_ver[1]) | ||
13 | |||
14 | return CheckStatus.OK | ||