summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli/__init__.py')
-rw-r--r--lib/python/qmk/cli/__init__.py70
1 files changed, 42 insertions, 28 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index d07790d118..48812ae4ba 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -12,6 +12,20 @@ from subprocess import run
12from milc import cli, __VERSION__ 12from milc import cli, __VERSION__
13from milc.questions import yesno 13from milc.questions import yesno
14 14
15import_names = {
16 # A mapping of package name to importable name
17 'pep8-naming': 'pep8ext_naming',
18 'pyusb': 'usb.core',
19}
20
21safe_commands = [
22 # A list of subcommands we always run, even when the module imports fail
23 'clone',
24 'config',
25 'env',
26 'setup',
27]
28
15 29
16def _run_cmd(*command): 30def _run_cmd(*command):
17 """Run a command in a subshell. 31 """Run a command in a subshell.
@@ -50,8 +64,8 @@ def _find_broken_requirements(requirements):
50 module_import = module_name.replace('-', '_') 64 module_import = module_name.replace('-', '_')
51 65
52 # Not every module is importable by its own name. 66 # Not every module is importable by its own name.
53 if module_name == "pep8-naming": 67 if module_name in import_names:
54 module_import = "pep8ext_naming" 68 module_import = import_names[module_name]
55 69
56 if not find_spec(module_import): 70 if not find_spec(module_import):
57 broken_modules.append(module_name) 71 broken_modules.append(module_name)
@@ -107,32 +121,31 @@ if int(milc_version[0]) < 2 and int(milc_version[1]) < 3:
107 121
108# Check to make sure we have all our dependencies 122# Check to make sure we have all our dependencies
109msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.' 123msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.'
110 124args = sys.argv[1:]
111if _broken_module_imports('requirements.txt'): 125while args and args[0][0] == '-':
112 if yesno('Would you like to install the required Python modules?'): 126 del args[0]
113 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt') 127
114 else: 128if not args or args[0] not in safe_commands:
115 print() 129 if _broken_module_imports('requirements.txt'):
116 print(msg_install % (str(Path('requirements.txt').resolve()),)) 130 if yesno('Would you like to install the required Python modules?'):
117 print() 131 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt')
118 exit(1) 132 else:
119 133 print()
120if cli.config.user.developer: 134 print(msg_install % (str(Path('requirements.txt').resolve()),))
121 args = sys.argv[1:] 135 print()
122 while args and args[0][0] == '-': 136 exit(1)
123 del args[0] 137
124 if not args or args[0] != 'config': 138 if cli.config.user.developer and _broken_module_imports('requirements-dev.txt'):
125 if _broken_module_imports('requirements-dev.txt'): 139 if yesno('Would you like to install the required developer Python modules?'):
126 if yesno('Would you like to install the required developer Python modules?'): 140 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt')
127 _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt') 141 elif yesno('Would you like to disable developer mode?'):
128 elif yesno('Would you like to disable developer mode?'): 142 _run_cmd(sys.argv[0], 'config', 'user.developer=None')
129 _run_cmd(sys.argv[0], 'config', 'user.developer=None') 143 else:
130 else: 144 print()
131 print() 145 print(msg_install % (str(Path('requirements-dev.txt').resolve()),))
132 print(msg_install % (str(Path('requirements-dev.txt').resolve()),)) 146 print('You can also turn off developer mode: qmk config user.developer=None')
133 print('You can also turn off developer mode: qmk config user.developer=None') 147 print()
134 print() 148 exit(1)
135 exit(1)
136 149
137# Import our subcommands 150# Import our subcommands
138from . import bux # noqa 151from . import bux # noqa
@@ -142,6 +155,7 @@ from . import chibios # noqa
142from . import clean # noqa 155from . import clean # noqa
143from . import compile # noqa 156from . import compile # noqa
144from milc.subcommand import config # noqa 157from milc.subcommand import config # noqa
158from . import console # noqa
145from . import docs # noqa 159from . import docs # noqa
146from . import doctor # noqa 160from . import doctor # noqa
147from . import fileformat # noqa 161from . import fileformat # noqa