diff options
Diffstat (limited to 'bin/qmk')
| -rwxr-xr-x | bin/qmk | 62 |
1 files changed, 43 insertions, 19 deletions
| @@ -4,34 +4,58 @@ | |||
| 4 | import os | 4 | import os |
| 5 | import sys | 5 | import sys |
| 6 | from importlib.util import find_spec | 6 | from importlib.util import find_spec |
| 7 | from time import strftime | ||
| 8 | from pathlib import Path | ||
| 7 | 9 | ||
| 8 | # Add the QMK python libs to our path | 10 | # Add the QMK python libs to our path |
| 9 | script_dir = os.path.dirname(os.path.realpath(__file__)) | 11 | script_dir = Path(os.path.realpath(__file__)).parent |
| 10 | qmk_dir = os.path.abspath(os.path.join(script_dir, '..')) | 12 | qmk_dir = script_dir.parent |
| 11 | python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python')) | 13 | python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve() |
| 12 | sys.path.append(python_lib_dir) | 14 | sys.path.append(str(python_lib_dir)) |
| 15 | |||
| 16 | # QMK CLI user config file | ||
| 17 | config_file = Path(Path.home() / '.config/qmk/qmk.ini') | ||
| 13 | 18 | ||
| 14 | # Make sure our modules have been setup | ||
| 15 | with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd: | ||
| 16 | for line in fd.readlines(): | ||
| 17 | line = line.strip().replace('<', '=').replace('>', '=') | ||
| 18 | 19 | ||
| 19 | if line[0] == '#': | 20 | def _check_modules(requirements): |
| 20 | continue | 21 | """ Check if the modules in the given requirements.txt are available. |
| 22 | """ | ||
| 23 | with Path(qmk_dir / requirements).open() as fd: | ||
| 24 | for line in fd.readlines(): | ||
| 25 | line = line.strip().replace('<', '=').replace('>', '=') | ||
| 21 | 26 | ||
| 22 | if '#' in line: | 27 | if line[0] == '#': |
| 23 | line = line.split('#')[0] | 28 | continue |
| 24 | 29 | ||
| 25 | module = line.split('=')[0] if '=' in line else line | 30 | if '#' in line: |
| 31 | line = line.split('#')[0] | ||
| 32 | |||
| 33 | module = dict() | ||
| 34 | module['name'] = module['import'] = line.split('=')[0] if '=' in line else line | ||
| 26 | 35 | ||
| 27 | if module in ['pep8-naming']: | ||
| 28 | # Not every module is importable by its own name. | 36 | # Not every module is importable by its own name. |
| 29 | continue | 37 | if module['name'] == "pep8-naming": |
| 38 | module['import'] = "pep8ext_naming" | ||
| 30 | 39 | ||
| 31 | if not find_spec(module): | 40 | if not find_spec(module['import']): |
| 32 | print('Could not find module %s!' % module) | 41 | print('Could not find module %s!' % module['name']) |
| 33 | print('Please run `pip3 install -r requirements.txt` to install the python dependencies.') | 42 | if developer: |
| 34 | exit(255) | 43 | print('Please run `pip3 install -r requirements-dev.txt` to install the python development dependencies or turn off developer mode with `qmk config user.developer=None`.') |
| 44 | print() | ||
| 45 | else: | ||
| 46 | print('Please run `pip3 install -r requirements.txt` to install the python dependencies.') | ||
| 47 | print() | ||
| 48 | exit(255) | ||
| 49 | |||
| 50 | |||
| 51 | developer = False | ||
| 52 | # Make sure our modules have been setup | ||
| 53 | _check_modules('requirements.txt') | ||
| 54 | |||
| 55 | # For developers additional modules are needed | ||
| 56 | if config_file.exists() and 'developer = True' in config_file.read_text(): | ||
| 57 | developer = True | ||
| 58 | _check_modules('requirements-dev.txt') | ||
| 35 | 59 | ||
| 36 | # Setup the CLI | 60 | # Setup the CLI |
| 37 | import milc # noqa | 61 | import milc # noqa |
