Add setup, clone, and env to the list of commands we allow even with broken modules (#12868)

This commit is contained in:
Zach White 2021-05-12 09:40:58 -07:00 committed by GitHub
parent 3a1ce81d29
commit 6da60d4a5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,21 @@ from milc import cli, __VERSION__
from milc.questions import yesno from milc.questions import yesno
import_names = {
# A mapping of package name to importable name
'pep8-naming': 'pep8ext_naming',
'pyusb': 'usb.core',
}
safe_commands = [
# A list of subcommands we always run, even when the module imports fail
'clone',
'config',
'env',
'setup',
]
def _run_cmd(*command): def _run_cmd(*command):
"""Run a command in a subshell. """Run a command in a subshell.
""" """
@ -50,10 +65,8 @@ def _find_broken_requirements(requirements):
module_import = module_name.replace('-', '_') module_import = module_name.replace('-', '_')
# Not every module is importable by its own name. # Not every module is importable by its own name.
if module_name == "pep8-naming": if module_name in import_names:
module_import = "pep8ext_naming" module_import = import_names[module_name]
elif module_name == 'pyusb':
module_import = 'usb.core'
if not find_spec(module_import): if not find_spec(module_import):
broken_modules.append(module_name) broken_modules.append(module_name)
@ -109,32 +122,31 @@ if int(milc_version[0]) < 2 and int(milc_version[1]) < 3:
# Check to make sure we have all our dependencies # Check to make sure we have all our dependencies
msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.' msg_install = 'Please run `python3 -m pip install -r %s` to install required python dependencies.'
args = sys.argv[1:]
while args and args[0][0] == '-':
del args[0]
if _broken_module_imports('requirements.txt'): if not args or args[0] not in safe_commands:
if yesno('Would you like to install the required Python modules?'): if _broken_module_imports('requirements.txt'):
_run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt') if yesno('Would you like to install the required Python modules?'):
else: _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt')
print() else:
print(msg_install % (str(Path('requirements.txt').resolve()),)) print()
print() print(msg_install % (str(Path('requirements.txt').resolve()),))
exit(1) print()
exit(1)
if cli.config.user.developer: if cli.config.user.developer and _broken_module_imports('requirements-dev.txt'):
args = sys.argv[1:] if yesno('Would you like to install the required developer Python modules?'):
while args and args[0][0] == '-': _run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt')
del args[0] elif yesno('Would you like to disable developer mode?'):
if not args or args[0] != 'config': _run_cmd(sys.argv[0], 'config', 'user.developer=None')
if _broken_module_imports('requirements-dev.txt'): else:
if yesno('Would you like to install the required developer Python modules?'): print()
_run_cmd(sys.executable, '-m', 'pip', 'install', '-r', 'requirements-dev.txt') print(msg_install % (str(Path('requirements-dev.txt').resolve()),))
elif yesno('Would you like to disable developer mode?'): print('You can also turn off developer mode: qmk config user.developer=None')
_run_cmd(sys.argv[0], 'config', 'user.developer=None') print()
else: exit(1)
print()
print(msg_install % (str(Path('requirements-dev.txt').resolve()),))
print('You can also turn off developer mode: qmk config user.developer=None')
print()
exit(1)
# Import our subcommands # Import our subcommands
from . import c2json # noqa from . import c2json # noqa