summaryrefslogtreecommitdiff
path: root/bin/qmk
diff options
context:
space:
mode:
authorErovia <erovia@users.noreply.github.com>2019-11-27 21:27:06 +0100
committerskullydazed <skullydazed@users.noreply.github.com>2020-04-08 09:31:14 -0700
commitc61f016fa491502920941fd03cdab6453d126e67 (patch)
tree1f8f6b4cbaf2b158604d47f01dc42fc69cac365a /bin/qmk
parentea7e40bae17897fbc613e0965d076a7a25b14ea6 (diff)
downloadqmk_firmware-c61f016fa491502920941fd03cdab6453d126e67.tar.gz
qmk_firmware-c61f016fa491502920941fd03cdab6453d126e67.zip
CLI: Add development mode support
Hide development specific options and don't require dev modules unless `user.developer` is set to `True`.
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 7592eefd93..e4fb057ff2 100755
--- a/bin/qmk
+++ b/bin/qmk
@@ -4,34 +4,58 @@
import os
import sys
from importlib.util import find_spec
+from time import strftime
+from pathlib import Path
# 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)
+script_dir = Path(os.path.realpath(__file__)).parent
+qmk_dir = script_dir.parent
+python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
+sys.path.append(str(python_lib_dir))
+
+# QMK CLI user config file
+config_file = Path(Path.home() / '.config/qmk/qmk.ini')
-# 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
+def _check_modules(requirements):
+ """ Check if the modules in the given requirements.txt are available.
+ """
+ with Path(qmk_dir / requirements).open() as fd:
+ for line in fd.readlines():
+ line = line.strip().replace('<', '=').replace('>', '=')
- if '#' in line:
- line = line.split('#')[0]
+ if line[0] == '#':
+ continue
- module = line.split('=')[0] if '=' in line else line
+ if '#' in line:
+ line = line.split('#')[0]
+
+ module = dict()
+ module['name'] = module['import'] = line.split('=')[0] if '=' in line else line
- if module in ['pep8-naming']:
# Not every module is importable by its own name.
- continue
+ if module['name'] == "pep8-naming":
+ module['import'] = "pep8ext_naming"
- 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)
+ if not find_spec(module['import']):
+ print('Could not find module %s!' % module['name'])
+ if developer:
+ 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`.')
+ print()
+ else:
+ print('Please run `pip3 install -r requirements.txt` to install the python dependencies.')
+ print()
+ exit(255)
+
+
+developer = False
+# Make sure our modules have been setup
+_check_modules('requirements.txt')
+
+# For developers additional modules are needed
+if config_file.exists() and 'developer = True' in config_file.read_text():
+ developer = True
+ _check_modules('requirements-dev.txt')
# Setup the CLI
import milc # noqa