CLI: Add development mode support
Hide development specific options and don't require dev modules unless `user.developer` is set to `True`.
This commit is contained in:
46
bin/qmk
46
bin/qmk
@@ -4,15 +4,23 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from importlib.util import find_spec
|
from importlib.util import find_spec
|
||||||
|
from time import strftime
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# Add the QMK python libs to our path
|
# Add the QMK python libs to our path
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = Path(os.path.realpath(__file__)).parent
|
||||||
qmk_dir = os.path.abspath(os.path.join(script_dir, '..'))
|
qmk_dir = script_dir.parent
|
||||||
python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python'))
|
python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
|
||||||
sys.path.append(python_lib_dir)
|
sys.path.append(str(python_lib_dir))
|
||||||
|
|
||||||
# Make sure our modules have been setup
|
# QMK CLI user config file
|
||||||
with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd:
|
config_file = Path(Path.home() / '.config/qmk/qmk.ini')
|
||||||
|
|
||||||
|
|
||||||
|
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():
|
for line in fd.readlines():
|
||||||
line = line.strip().replace('<', '=').replace('>', '=')
|
line = line.strip().replace('<', '=').replace('>', '=')
|
||||||
|
|
||||||
@@ -22,17 +30,33 @@ with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd:
|
|||||||
if '#' in line:
|
if '#' in line:
|
||||||
line = line.split('#')[0]
|
line = line.split('#')[0]
|
||||||
|
|
||||||
module = line.split('=')[0] if '=' in line else line
|
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.
|
# Not every module is importable by its own name.
|
||||||
continue
|
if module['name'] == "pep8-naming":
|
||||||
|
module['import'] = "pep8ext_naming"
|
||||||
|
|
||||||
if not find_spec(module):
|
if not find_spec(module['import']):
|
||||||
print('Could not find module %s!', module)
|
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('Please run `pip3 install -r requirements.txt` to install the python dependencies.')
|
||||||
|
print()
|
||||||
exit(255)
|
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
|
# Setup the CLI
|
||||||
import milc # noqa
|
import milc # noqa
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from milc import cli
|
|||||||
|
|
||||||
|
|
||||||
@cli.argument('-n', '--name', default='World', help='Name to greet.')
|
@cli.argument('-n', '--name', default='World', help='Name to greet.')
|
||||||
@cli.subcommand('QMK Hello World.')
|
@cli.subcommand('QMK Hello World.', hidden=False if cli.config.user.developer else True)
|
||||||
def hello(cli):
|
def hello(cli):
|
||||||
"""Log a friendly greeting.
|
"""Log a friendly greeting.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from milc import cli
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
@cli.subcommand("Format python code according to QMK's style.")
|
@cli.subcommand("Format python code according to QMK's style.", hidden=False if cli.config.user.developer else True)
|
||||||
def pyformat(cli):
|
def pyformat(cli):
|
||||||
"""Format python code according to QMK's style.
|
"""Format python code according to QMK's style.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import subprocess
|
|||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
|
|
||||||
@cli.subcommand('QMK Python Unit Tests')
|
@cli.subcommand('QMK Python Unit Tests', hidden=False if cli.config.user.developer else True)
|
||||||
def pytest(cli):
|
def pytest(cli):
|
||||||
"""Run several linting/testing commands.
|
"""Run several linting/testing commands.
|
||||||
"""
|
"""
|
||||||
|
|||||||
4
requirements-dev.txt
Normal file
4
requirements-dev.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Python development requirements
|
||||||
|
nose2
|
||||||
|
flake8
|
||||||
|
pep8-naming
|
||||||
@@ -4,6 +4,3 @@ appdirs
|
|||||||
argcomplete
|
argcomplete
|
||||||
colorama
|
colorama
|
||||||
hjson
|
hjson
|
||||||
nose2
|
|
||||||
flake8
|
|
||||||
pep8-naming
|
|
||||||
|
|||||||
Reference in New Issue
Block a user