aboutsummaryrefslogtreecommitdiff
path: root/bin/qmk
diff options
context:
space:
mode:
Diffstat (limited to 'bin/qmk')
-rwxr-xr-xbin/qmk62
1 files changed, 43 insertions, 19 deletions
diff --git a/bin/qmk b/bin/qmk
index 7592eefd9..e4fb057ff 100755
--- a/bin/qmk
+++ b/bin/qmk
@@ -4,34 +4,58 @@
4import os 4import os
5import sys 5import sys
6from importlib.util import find_spec 6from importlib.util import find_spec
7from time import strftime
8from pathlib import Path
7 9
8# Add the QMK python libs to our path 10# Add the QMK python libs to our path
9script_dir = os.path.dirname(os.path.realpath(__file__)) 11script_dir = Path(os.path.realpath(__file__)).parent
10qmk_dir = os.path.abspath(os.path.join(script_dir, '..')) 12qmk_dir = script_dir.parent
11python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python')) 13python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
12sys.path.append(python_lib_dir) 14sys.path.append(str(python_lib_dir))
15
16# QMK CLI user config file
17config_file = Path(Path.home() / '.config/qmk/qmk.ini')
13 18
14# Make sure our modules have been setup
15with 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] == '#': 20def _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
51developer = False
52# Make sure our modules have been setup
53_check_modules('requirements.txt')
54
55# For developers additional modules are needed
56if 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
37import milc # noqa 61import milc # noqa