aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-05-12 09:40:58 -0700
committerGitHub <noreply@github.com>2021-05-12 09:40:58 -0700
commit6da60d4a5d75d88da36385c5e14ff00c5055214d (patch)
tree672edb9792541370d64bf41627a8f74667edddc7
parent3a1ce81d29efc50f57d5112b85241094721a6231 (diff)
downloadqmk_firmware-6da60d4a5d75d88da36385c5e14ff00c5055214d.tar.gz
qmk_firmware-6da60d4a5d75d88da36385c5e14ff00c5055214d.zip
Add setup, clone, and env to the list of commands we allow even with broken modules (#12868)
-rw-r--r--lib/python/qmk/cli/__init__.py72
1 files changed, 42 insertions, 30 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 1fe065720..3face93a5 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -13,6 +13,21 @@ from milc import cli, __VERSION__
13from milc.questions import yesno 13from milc.questions import yesno
14 14
15 15
16import_names = {
17 # A mapping of package name to importable name
18 'pep8-naming': 'pep8ext_naming',
19 'pyusb': 'usb.core',
20}
21
22safe_commands = [
23 # A list of subcommands we always run, even when the module imports fail
24 'clone',
25 'config',
26 'env',
27 'setup',
28]
29
30
16def _run_cmd(*command): 31def _run_cmd(*command):
17 """Run a command in a subshell. 32 """Run a command in a subshell.
18 """ 33 """
@@ -50,10 +65,8 @@ def _find_broken_requirements(requirements):
50 module_import = module_name.replace('-', '_') 65 module_import = module_name.replace('-', '_')
51 66
52 # Not every module is importable by its own name. 67 # Not every module is importable by its own name.
53 if module_name == "pep8-naming": 68 if module_name in import_names:
54 module_import = "pep8ext_naming" 69 module_import = import_names[module_name]
55 elif module_name == 'pyusb':
56 module_import = 'usb.core'
57 70
58 if not find_spec(module_import): 71 if not find_spec(module_import):
59 broken_modules.append(module_name) 72 broken_modules.append(module_name)
@@ -109,32 +122,31 @@ if int(milc_version[0]) < 2 and int(milc_version[1]) < 3:
109 122
110# Check to make sure we have all our dependencies 123# Check to make sure we have all our dependencies
111msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.' 124msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.'
112 125args = sys.argv[1:]
113if _broken_module_imports('requirements.txt'): 126while args and args[0][0] == '-':
114 if yesno('Would you like to install the required Python modules?'): 127 del args[0]
115 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt') 128
116 else: 129if not args or args[0] not in safe_commands:
117 print() 130 if _broken_module_imports('requirements.txt'):
118 print(msg_install % (str(Path('requirements.txt').resolve()),)) 131 if yesno('Would you like to install the required Python modules?'):
119 print() 132 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt')
120 exit(1) 133 else:
121 134 print()
122if cli.config.user.developer: 135 print(msg_install % (str(Path('requirements.txt').resolve()),))
123 args = sys.argv[1:] 136 print()
124 while args and args[0][0] == '-': 137 exit(1)
125 del args[0] 138
126 if not args or args[0] != 'config': 139 if cli.config.user.developer and _broken_module_imports('requirements-dev.txt'):
127 if _broken_module_imports('requirements-dev.txt'): 140 if yesno('Would you like to install the required developer Python modules?'):
128 if yesno('Would you like to install the required developer Python modules?'): 141 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt')
129 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt') 142 elif yesno('Would you like to disable developer mode?'):
130 elif yesno('Would you like to disable developer mode?'): 143 _run_cmd(sys.argv[0], 'config', 'user.developer=None')
131 _run_cmd(sys.argv[0], 'config', 'user.developer=None') 144 else:
132 else: 145 print()
133 print() 146 print(msg_install % (str(Path('requirements-dev.txt').resolve()),))
134 print(msg_install % (str(Path('requirements-dev.txt').resolve()),)) 147 print('You can also turn off developer mode: qmk config user.developer=None')
135 print('You can also turn off developer mode: qmk config user.developer=None') 148 print()
136 print() 149 exit(1)
137 exit(1)
138 150
139# Import our subcommands 151# Import our subcommands
140from . import c2json # noqa 152from . import c2json # noqa