Ensure that safe_commands always run (#13199)
* ensure that safe_commands always run * import the config subcommand in bin/qmk
This commit is contained in:
parent
ae45faca26
commit
0713797c58
1
bin/qmk
1
bin/qmk
@ -35,6 +35,7 @@ def main():
|
|||||||
print('Warning: The bin/qmk script is being deprecated. Please install the QMK CLI: python3 -m pip install qmk', file=sys.stderr)
|
print('Warning: The bin/qmk script is being deprecated. Please install the QMK CLI: python3 -m pip install qmk', file=sys.stderr)
|
||||||
|
|
||||||
# Import the subcommands
|
# Import the subcommands
|
||||||
|
import milc.subcommand.config # noqa
|
||||||
import qmk.cli # noqa
|
import qmk.cli # noqa
|
||||||
|
|
||||||
# Execute
|
# Execute
|
||||||
|
@ -26,6 +26,42 @@ safe_commands = [
|
|||||||
'setup',
|
'setup',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
subcommands = [
|
||||||
|
'qmk.cli.bux',
|
||||||
|
'qmk.cli.c2json',
|
||||||
|
'qmk.cli.cformat',
|
||||||
|
'qmk.cli.chibios.confmigrate',
|
||||||
|
'qmk.cli.clean',
|
||||||
|
'qmk.cli.compile',
|
||||||
|
'qmk.cli.console',
|
||||||
|
'qmk.cli.docs',
|
||||||
|
'qmk.cli.doctor',
|
||||||
|
'qmk.cli.fileformat',
|
||||||
|
'qmk.cli.flash',
|
||||||
|
'qmk.cli.format.json',
|
||||||
|
'qmk.cli.generate.api',
|
||||||
|
'qmk.cli.generate.config_h',
|
||||||
|
'qmk.cli.generate.dfu_header',
|
||||||
|
'qmk.cli.generate.docs',
|
||||||
|
'qmk.cli.generate.info_json',
|
||||||
|
'qmk.cli.generate.keyboard_h',
|
||||||
|
'qmk.cli.generate.layouts',
|
||||||
|
'qmk.cli.generate.rgb_breathe_table',
|
||||||
|
'qmk.cli.generate.rules_mk',
|
||||||
|
'qmk.cli.hello',
|
||||||
|
'qmk.cli.info',
|
||||||
|
'qmk.cli.json2c',
|
||||||
|
'qmk.cli.lint',
|
||||||
|
'qmk.cli.list.keyboards',
|
||||||
|
'qmk.cli.list.keymaps',
|
||||||
|
'qmk.cli.kle2json',
|
||||||
|
'qmk.cli.multibuild',
|
||||||
|
'qmk.cli.new.keyboard',
|
||||||
|
'qmk.cli.new.keymap',
|
||||||
|
'qmk.cli.pyformat',
|
||||||
|
'qmk.cli.pytest',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def _run_cmd(*command):
|
def _run_cmd(*command):
|
||||||
"""Run a command in a subshell.
|
"""Run a command in a subshell.
|
||||||
@ -113,7 +149,7 @@ if sys.version_info[0] != 3 or sys.version_info[1] < 7:
|
|||||||
|
|
||||||
milc_version = __VERSION__.split('.')
|
milc_version = __VERSION__.split('.')
|
||||||
|
|
||||||
if int(milc_version[0]) < 2 and int(milc_version[1]) < 3:
|
if int(milc_version[0]) < 2 and int(milc_version[1]) < 4:
|
||||||
requirements = Path('requirements.txt').resolve()
|
requirements = Path('requirements.txt').resolve()
|
||||||
|
|
||||||
print(f'Your MILC library is too old! Please upgrade: python3 -m pip install -U -r {str(requirements)}')
|
print(f'Your MILC library is too old! Please upgrade: python3 -m pip install -U -r {str(requirements)}')
|
||||||
@ -125,7 +161,9 @@ args = sys.argv[1:]
|
|||||||
while args and args[0][0] == '-':
|
while args and args[0][0] == '-':
|
||||||
del args[0]
|
del args[0]
|
||||||
|
|
||||||
if not args or args[0] not in safe_commands:
|
safe_command = args and args[0] in safe_commands
|
||||||
|
|
||||||
|
if not safe_command:
|
||||||
if _broken_module_imports('requirements.txt'):
|
if _broken_module_imports('requirements.txt'):
|
||||||
if yesno('Would you like to install the required Python modules?'):
|
if yesno('Would you like to install the required Python modules?'):
|
||||||
_run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt')
|
_run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt')
|
||||||
@ -148,27 +186,12 @@ if not args or args[0] not in safe_commands:
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Import our subcommands
|
# Import our subcommands
|
||||||
from . import bux # noqa
|
for subcommand in subcommands:
|
||||||
from . import c2json # noqa
|
try:
|
||||||
from . import cformat # noqa
|
__import__(subcommand)
|
||||||
from . import chibios # noqa
|
|
||||||
from . import clean # noqa
|
except ModuleNotFoundError as e:
|
||||||
from . import compile # noqa
|
if safe_command:
|
||||||
from milc.subcommand import config # noqa
|
print(f'Warning: Could not import {subcommand}: {e.__class__.__name__}, {e}')
|
||||||
from . import console # noqa
|
else:
|
||||||
from . import docs # noqa
|
raise
|
||||||
from . import doctor # noqa
|
|
||||||
from . import fileformat # noqa
|
|
||||||
from . import flash # noqa
|
|
||||||
from . import format # noqa
|
|
||||||
from . import generate # noqa
|
|
||||||
from . import hello # noqa
|
|
||||||
from . import info # noqa
|
|
||||||
from . import json2c # noqa
|
|
||||||
from . import lint # noqa
|
|
||||||
from . import list # noqa
|
|
||||||
from . import kle2json # noqa
|
|
||||||
from . import multibuild # noqa
|
|
||||||
from . import new # noqa
|
|
||||||
from . import pyformat # noqa
|
|
||||||
from . import pytest # noqa
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
from . import confmigrate
|
|
@ -1 +0,0 @@
|
|||||||
from . import json
|
|
@ -1,9 +0,0 @@
|
|||||||
from . import api
|
|
||||||
from . import config_h
|
|
||||||
from . import dfu_header
|
|
||||||
from . import docs
|
|
||||||
from . import info_json
|
|
||||||
from . import keyboard_h
|
|
||||||
from . import layouts
|
|
||||||
from . import rgb_breathe_table
|
|
||||||
from . import rules_mk
|
|
@ -1,2 +0,0 @@
|
|||||||
from . import keyboards
|
|
||||||
from . import keymaps
|
|
@ -1,2 +0,0 @@
|
|||||||
from . import keyboard
|
|
||||||
from . import keymap
|
|
Loading…
Reference in New Issue
Block a user