opensteno_qmk/bin/qmk
Erovia c89c084146
CLI: More MSYS2 fixes (#8577)
* CLI: More MSYS2 fixes

Now I can fully setup and work with qmk_firmware on an MSYS2
installation without any errors or exceptions.

* Apply suggestions from code review

Co-Authored-By: skullydazed <skullydazed@users.noreply.github.com>

* Some improvements

* Remove unnecessary import

* Remove slow, unused code

Getting the version from GIT was slow on both Windows and Docker.
Until we find a better, faster way, this is removed.

* remove unused imports

* Implement @vomindoraan's suggestions

* refine how we pick the shell to use

* Apply @fauxpark's suggestions

fauxpark investigated the topic of shells in MSYS2 a bit and we come to the conclusion that the safest bet was to just use the user's shell.
Anything more just opens up more edge-cases than it solves.

Co-Authored-By: Ryan <fauxpark@gmail.com>

* Use `platform_id` in doctor

This will bring it in line with the new code.

Co-authored-by: skullydazed <skullydazed@users.noreply.github.com>
Co-authored-by: skullY <skullydazed@gmail.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
2020-03-29 14:29:44 +02:00

76 lines
1.9 KiB
Python
Executable file

#!/usr/bin/env python3
"""CLI wrapper for running QMK commands.
"""
import os
import sys
from importlib.util import find_spec
# Add the QMK python libs to our path
script_dir = os.path.dirname(os.path.realpath(__file__))
qmk_dir = os.path.abspath(os.path.join(script_dir, '..'))
python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python'))
sys.path.append(python_lib_dir)
# Make sure our modules have been setup
with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd:
for line in fd.readlines():
line = line.strip().replace('<', '=').replace('>', '=')
if line[0] == '#':
continue
if '#' in line:
line = line.split('#')[0]
module = line.split('=')[0] if '=' in line else line
if module in ['pep8-naming']:
# Not every module is importable by its own name.
continue
if not find_spec(module):
print('Could not find module %s!' % module)
print('Please run `pip3 install -r requirements.txt` to install the python dependencies.')
exit(255)
# Setup the CLI
import milc # noqa
milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
@milc.cli.entrypoint('QMK Helper Script')
def qmk_main(cli):
"""The function that gets run when no subcommand is provided.
"""
cli.print_help()
def main():
"""Setup our environment and then call the CLI entrypoint.
"""
# Change to the root of our checkout
os.environ['ORIG_CWD'] = os.getcwd()
os.chdir(qmk_dir)
# Import the subcommands
import qmk.cli # noqa
# Execute
return_code = milc.cli()
if return_code is False:
exit(1)
elif return_code is not True and isinstance(return_code, int):
if return_code < 0 or return_code > 255:
milc.cli.log.error('Invalid return_code: %d', return_code)
exit(255)
exit(return_code)
exit(0)
if __name__ == '__main__':
main()