Merge remote-tracking branch 'origin/master' into develop
Resolved Conflicts: keyboards/kc60/rules.mk keyboards/xd96/rules.mk lib/python/qmk/cli/__init__.py
This commit is contained in:
commit
ac3b7d79e0
938 changed files with 35990 additions and 13003 deletions
|
@ -9,6 +9,7 @@ from milc import cli
|
|||
from . import c2json
|
||||
from . import cformat
|
||||
from . import chibios
|
||||
from . import clean
|
||||
from . import compile
|
||||
from . import config
|
||||
from . import docs
|
||||
|
@ -19,6 +20,7 @@ from . import hello
|
|||
from . import info
|
||||
from . import json
|
||||
from . import json2c
|
||||
from . import lint
|
||||
from . import list
|
||||
from . import kle2json
|
||||
from . import new
|
||||
|
|
16
lib/python/qmk/cli/clean.py
Normal file
16
lib/python/qmk/cli/clean.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
"""Clean the QMK firmware folder of build artifacts.
|
||||
"""
|
||||
from qmk.commands import run
|
||||
from milc import cli
|
||||
|
||||
import shutil
|
||||
|
||||
|
||||
@cli.argument('-a', '--all', arg_only=True, action='store_true', help='Remove *.hex and *.bin files in the QMK root as well.')
|
||||
@cli.subcommand('Clean the QMK firmware folder of build artifacts.')
|
||||
def clean(cli):
|
||||
"""Runs `make clean` (or `make distclean` if --all is passed)
|
||||
"""
|
||||
make_cmd = 'gmake' if shutil.which('gmake') else 'make'
|
||||
|
||||
run([make_cmd, 'distclean' if cli.args.all else 'clean'])
|
|
@ -7,6 +7,7 @@ import re
|
|||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from enum import Enum
|
||||
|
||||
from milc import cli
|
||||
from milc.questions import yesno
|
||||
|
@ -14,6 +15,13 @@ from qmk import submodules
|
|||
from qmk.constants import QMK_FIRMWARE
|
||||
from qmk.commands import run
|
||||
|
||||
|
||||
class CheckStatus(Enum):
|
||||
OK = 1
|
||||
WARNING = 2
|
||||
ERROR = 3
|
||||
|
||||
|
||||
ESSENTIAL_BINARIES = {
|
||||
'dfu-programmer': {},
|
||||
'avrdude': {},
|
||||
|
@ -33,9 +41,12 @@ def _udev_rule(vid, pid=None, *args):
|
|||
"""
|
||||
rule = ""
|
||||
if pid:
|
||||
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", TAG+="uaccess", RUN{builtin}+="uaccess"' % (vid, pid)
|
||||
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", ATTRS{idProduct}=="%s", TAG+="uaccess"' % (
|
||||
vid,
|
||||
pid,
|
||||
)
|
||||
else:
|
||||
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", TAG+="uaccess", RUN{builtin}+="uaccess"' % vid
|
||||
rule = 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="%s", TAG+="uaccess"' % vid
|
||||
if args:
|
||||
rule = ', '.join([rule, *args])
|
||||
return rule
|
||||
|
@ -69,24 +80,25 @@ def check_arm_gcc_version():
|
|||
version_number = ESSENTIAL_BINARIES['arm-none-eabi-gcc']['output'].strip()
|
||||
cli.log.info('Found arm-none-eabi-gcc version %s', version_number)
|
||||
|
||||
return True # Right now all known arm versions are ok
|
||||
return CheckStatus.OK # Right now all known arm versions are ok
|
||||
|
||||
|
||||
def check_avr_gcc_version():
|
||||
"""Returns True if the avr-gcc version is not known to cause problems.
|
||||
"""
|
||||
rc = CheckStatus.ERROR
|
||||
if 'output' in ESSENTIAL_BINARIES['avr-gcc']:
|
||||
version_number = ESSENTIAL_BINARIES['avr-gcc']['output'].strip()
|
||||
|
||||
cli.log.info('Found avr-gcc version %s', version_number)
|
||||
rc = CheckStatus.OK
|
||||
|
||||
parsed_version = parse_gcc_version(version_number)
|
||||
if parsed_version['major'] > 8:
|
||||
cli.log.error('We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
|
||||
return False
|
||||
cli.log.warning('{fg_yellow}We do not recommend avr-gcc newer than 8. Downgrading to 8.x is recommended.')
|
||||
rc = CheckStatus.WARNING
|
||||
|
||||
cli.log.info('Found avr-gcc version %s', version_number)
|
||||
return True
|
||||
|
||||
return False
|
||||
return rc
|
||||
|
||||
|
||||
def check_avrdude_version():
|
||||
|
@ -95,7 +107,7 @@ def check_avrdude_version():
|
|||
version_number = last_line.split()[2][:-1]
|
||||
cli.log.info('Found avrdude version %s', version_number)
|
||||
|
||||
return True
|
||||
return CheckStatus.OK
|
||||
|
||||
|
||||
def check_dfu_util_version():
|
||||
|
@ -104,7 +116,7 @@ def check_dfu_util_version():
|
|||
version_number = first_line.split()[1]
|
||||
cli.log.info('Found dfu-util version %s', version_number)
|
||||
|
||||
return True
|
||||
return CheckStatus.OK
|
||||
|
||||
|
||||
def check_dfu_programmer_version():
|
||||
|
@ -113,7 +125,7 @@ def check_dfu_programmer_version():
|
|||
version_number = first_line.split()[1]
|
||||
cli.log.info('Found dfu-programmer version %s', version_number)
|
||||
|
||||
return True
|
||||
return CheckStatus.OK
|
||||
|
||||
|
||||
def check_binaries():
|
||||
|
@ -131,58 +143,56 @@ def check_binaries():
|
|||
def check_submodules():
|
||||
"""Iterates through all submodules to make sure they're cloned and up to date.
|
||||
"""
|
||||
ok = True
|
||||
|
||||
for submodule in submodules.status().values():
|
||||
if submodule['status'] is None:
|
||||
cli.log.error('Submodule %s has not yet been cloned!', submodule['name'])
|
||||
ok = False
|
||||
return CheckStatus.ERROR
|
||||
elif not submodule['status']:
|
||||
cli.log.error('Submodule %s is not up to date!', submodule['name'])
|
||||
ok = False
|
||||
cli.log.warning('Submodule %s is not up to date!', submodule['name'])
|
||||
return CheckStatus.WARNING
|
||||
|
||||
return ok
|
||||
return CheckStatus.OK
|
||||
|
||||
|
||||
def check_udev_rules():
|
||||
"""Make sure the udev rules look good.
|
||||
"""
|
||||
ok = True
|
||||
rc = CheckStatus.OK
|
||||
udev_dir = Path("/etc/udev/rules.d/")
|
||||
desired_rules = {
|
||||
'atmel-dfu': {
|
||||
_udev_rule("03EB", "2FEF"), # ATmega16U2
|
||||
_udev_rule("03EB", "2FF0"), # ATmega32U2
|
||||
_udev_rule("03EB", "2FF3"), # ATmega16U4
|
||||
_udev_rule("03EB", "2FF4"), # ATmega32U4
|
||||
_udev_rule("03EB", "2FF9"), # AT90USB64
|
||||
_udev_rule("03EB", "2FFB") # AT90USB128
|
||||
_udev_rule("03eb", "2fef"), # ATmega16U2
|
||||
_udev_rule("03eb", "2ff0"), # ATmega32U2
|
||||
_udev_rule("03eb", "2ff3"), # ATmega16U4
|
||||
_udev_rule("03eb", "2ff4"), # ATmega32U4
|
||||
_udev_rule("03eb", "2ff9"), # AT90USB64
|
||||
_udev_rule("03eb", "2ffb") # AT90USB128
|
||||
},
|
||||
'kiibohd': {_udev_rule("1C11", "B007")},
|
||||
'kiibohd': {_udev_rule("1c11", "b007")},
|
||||
'stm32': {
|
||||
_udev_rule("1EAF", "0003"), # STM32duino
|
||||
_udev_rule("0483", "DF11") # STM32 DFU
|
||||
_udev_rule("1eaf", "0003"), # STM32duino
|
||||
_udev_rule("0483", "df11") # STM32 DFU
|
||||
},
|
||||
'bootloadhid': {_udev_rule("16C0", "05DF")},
|
||||
'usbasploader': {_udev_rule("16C0", "05DC")},
|
||||
'massdrop': {_udev_rule("03EB", "6124", 'ENV{ID_MM_DEVICE_IGNORE}="1"')},
|
||||
'bootloadhid': {_udev_rule("16c0", "05df")},
|
||||
'usbasploader': {_udev_rule("16c0", "05dc")},
|
||||
'massdrop': {_udev_rule("03eb", "6124", 'ENV{ID_MM_DEVICE_IGNORE}="1"')},
|
||||
'caterina': {
|
||||
# Spark Fun Electronics
|
||||
_udev_rule("1B4F", "9203", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 3V3/8MHz
|
||||
_udev_rule("1B4F", "9205", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 5V/16MHz
|
||||
_udev_rule("1B4F", "9207", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # LilyPad 3V3/8MHz (and some Pro Micro clones)
|
||||
# Pololu Electronics
|
||||
_udev_rule("1FFB", "0101", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # A-Star 32U4
|
||||
_udev_rule("1b4f", "9203", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 3V3/8MHz
|
||||
_udev_rule("1b4f", "9205", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Pro Micro 5V/16MHz
|
||||
_udev_rule("1b4f", "9207", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # LilyPad 3V3/8MHz (and some Pro Micro clones)
|
||||
# Pololu EleCTRONICS
|
||||
_udev_rule("1ffb", "0101", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # A-Star 32U4
|
||||
# Arduino SA
|
||||
_udev_rule("2341", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Leonardo
|
||||
_udev_rule("2341", "0037", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Micro
|
||||
# Adafruit Industries LLC
|
||||
_udev_rule("239A", "000C", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Feather 32U4
|
||||
_udev_rule("239A", "000D", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 3V3/8MHz
|
||||
_udev_rule("239A", "000E", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 5V/16MHz
|
||||
# dog hunter AG
|
||||
_udev_rule("2A03", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Leonardo
|
||||
_udev_rule("2A03", "0037", 'ENV{ID_MM_DEVICE_IGNORE}="1"') # Micro
|
||||
# Adafruit INDUSTRIES llC
|
||||
_udev_rule("239a", "000c", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Feather 32U4
|
||||
_udev_rule("239a", "000d", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 3V3/8MHz
|
||||
_udev_rule("239a", "000e", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # ItsyBitsy 32U4 5V/16MHz
|
||||
# dog hunter ag
|
||||
_udev_rule("2a03", "0036", 'ENV{ID_MM_DEVICE_IGNORE}="1"'), # Leonardo
|
||||
_udev_rule("2a03", "0037", 'ENV{ID_MM_DEVICE_IGNORE}="1"') # Micro
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,31 +219,43 @@ def check_udev_rules():
|
|||
|
||||
# Check if the desired rules are among the currently present rules
|
||||
for bootloader, rules in desired_rules.items():
|
||||
# For caterina, check if ModemManager is running
|
||||
if bootloader == "caterina":
|
||||
if check_modem_manager():
|
||||
ok = False
|
||||
cli.log.warn("{bg_yellow}Detected ModemManager without the necessary udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.")
|
||||
if not rules.issubset(current_rules):
|
||||
deprecated_rule = deprecated_rules.get(bootloader)
|
||||
if deprecated_rule and deprecated_rule.issubset(current_rules):
|
||||
cli.log.warn("{bg_yellow}Found old, deprecated udev rules for '%s' boards. The new rules on https://docs.qmk.fm/#/faq_build?id=linux-udev-rules offer better security with the same functionality.", bootloader)
|
||||
cli.log.warning("{fg_yellow}Found old, deprecated udev rules for '%s' boards. The new rules on https://docs.qmk.fm/#/faq_build?id=linux-udev-rules offer better security with the same functionality.", bootloader)
|
||||
else:
|
||||
cli.log.warn("{bg_yellow}Missing udev rules for '%s' boards. See https://docs.qmk.fm/#/faq_build?id=linux-udev-rules for more details.", bootloader)
|
||||
# For caterina, check if ModemManager is running
|
||||
if bootloader == "caterina":
|
||||
if check_modem_manager():
|
||||
rc = CheckStatus.WARNING
|
||||
cli.log.warning("{fg_yellow}Detected ModemManager without the necessary udev rules. Please either disable it or set the appropriate udev rules if you are using a Pro Micro.")
|
||||
rc = CheckStatus.WARNING
|
||||
cli.log.warning("{fg_yellow}Missing or outdated udev rules for '%s' boards. Run 'sudo cp %s/util/udev/50-qmk.rules /etc/udev/rules.d/'.", bootloader, QMK_FIRMWARE)
|
||||
|
||||
return ok
|
||||
else:
|
||||
cli.log.warning("{fg_yellow}'%s' does not exist. Skipping udev rule checking...", udev_dir)
|
||||
|
||||
return rc
|
||||
|
||||
|
||||
def check_systemd():
|
||||
"""Check if it's a systemd system
|
||||
"""
|
||||
return bool(shutil.which("systemctl"))
|
||||
|
||||
|
||||
def check_modem_manager():
|
||||
"""Returns True if ModemManager is running.
|
||||
|
||||
"""
|
||||
if shutil.which("systemctl"):
|
||||
if check_systemd():
|
||||
mm_check = run(["systemctl", "--quiet", "is-active", "ModemManager.service"], timeout=10)
|
||||
if mm_check.returncode == 0:
|
||||
return True
|
||||
|
||||
else:
|
||||
cli.log.warn("Can't find systemctl to check for ModemManager.")
|
||||
"""(TODO): Add check for non-systemd systems
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
def is_executable(command):
|
||||
|
@ -263,12 +285,8 @@ def os_test_linux():
|
|||
"""Run the Linux specific tests.
|
||||
"""
|
||||
cli.log.info("Detected {fg_cyan}Linux.")
|
||||
ok = True
|
||||
|
||||
if not check_udev_rules():
|
||||
ok = False
|
||||
|
||||
return ok
|
||||
return check_udev_rules()
|
||||
|
||||
|
||||
def os_test_macos():
|
||||
|
@ -276,7 +294,7 @@ def os_test_macos():
|
|||
"""
|
||||
cli.log.info("Detected {fg_cyan}macOS.")
|
||||
|
||||
return True
|
||||
return CheckStatus.OK
|
||||
|
||||
|
||||
def os_test_windows():
|
||||
|
@ -284,7 +302,7 @@ def os_test_windows():
|
|||
"""
|
||||
cli.log.info("Detected {fg_cyan}Windows.")
|
||||
|
||||
return True
|
||||
return CheckStatus.OK
|
||||
|
||||
|
||||
@cli.argument('-y', '--yes', action='store_true', arg_only=True, help='Answer yes to all questions.')
|
||||
|
@ -299,23 +317,20 @@ def doctor(cli):
|
|||
* [ ] Compile a trivial program with each compiler
|
||||
"""
|
||||
cli.log.info('QMK Doctor is checking your environment.')
|
||||
ok = True
|
||||
status = CheckStatus.OK
|
||||
|
||||
# Determine our OS and run platform specific tests
|
||||
platform_id = platform.platform().lower()
|
||||
|
||||
if 'darwin' in platform_id or 'macos' in platform_id:
|
||||
if not os_test_macos():
|
||||
ok = False
|
||||
status = os_test_macos()
|
||||
elif 'linux' in platform_id:
|
||||
if not os_test_linux():
|
||||
ok = False
|
||||
status = os_test_linux()
|
||||
elif 'windows' in platform_id:
|
||||
if not os_test_windows():
|
||||
ok = False
|
||||
status = os_test_windows()
|
||||
else:
|
||||
cli.log.error('Unsupported OS detected: %s', platform_id)
|
||||
ok = False
|
||||
cli.log.warning('Unsupported OS detected: %s', platform_id)
|
||||
status = CheckStatus.WARNING
|
||||
|
||||
cli.log.info('QMK home: {fg_cyan}%s', QMK_FIRMWARE)
|
||||
|
||||
|
@ -330,31 +345,41 @@ def doctor(cli):
|
|||
if bin_ok:
|
||||
cli.log.info('All dependencies are installed.')
|
||||
else:
|
||||
ok = False
|
||||
status = CheckStatus.ERROR
|
||||
|
||||
# Make sure the tools are at the correct version
|
||||
ver_ok = []
|
||||
for check in (check_arm_gcc_version, check_avr_gcc_version, check_avrdude_version, check_dfu_util_version, check_dfu_programmer_version):
|
||||
if not check():
|
||||
ok = False
|
||||
ver_ok.append(check())
|
||||
|
||||
if CheckStatus.ERROR in ver_ok:
|
||||
status = CheckStatus.ERROR
|
||||
elif CheckStatus.WARNING in ver_ok and status == CheckStatus.OK:
|
||||
status = CheckStatus.WARNING
|
||||
|
||||
# Check out the QMK submodules
|
||||
sub_ok = check_submodules()
|
||||
|
||||
if sub_ok:
|
||||
if sub_ok == CheckStatus.OK:
|
||||
cli.log.info('Submodules are up to date.')
|
||||
else:
|
||||
if yesno('Would you like to clone the submodules?', default=True):
|
||||
submodules.update()
|
||||
sub_ok = check_submodules()
|
||||
|
||||
if not sub_ok:
|
||||
ok = False
|
||||
if CheckStatus.ERROR in sub_ok:
|
||||
status = CheckStatus.ERROR
|
||||
elif CheckStatus.WARNING in sub_ok and status == CheckStatus.OK:
|
||||
status = CheckStatus.WARNING
|
||||
|
||||
# Report a summary of our findings to the user
|
||||
if ok:
|
||||
if status == CheckStatus.OK:
|
||||
cli.log.info('{fg_green}QMK is ready to go')
|
||||
return 0
|
||||
elif status == CheckStatus.WARNING:
|
||||
cli.log.info('{fg_yellow}QMK is ready to go, but minor problems were found')
|
||||
return 1
|
||||
else:
|
||||
cli.log.info('{fg_yellow}Problems detected, please fix these problems before proceeding.')
|
||||
# FIXME(skullydazed/unclaimed): Link to a document about troubleshooting, or discord or something
|
||||
|
||||
return ok
|
||||
cli.log.info('{fg_red}Major problems detected, please fix these problems before proceeding.')
|
||||
cli.log.info('{fg_blue}Check out the FAQ (https://docs.qmk.fm/#/faq_build) or join the QMK Discord (https://discord.gg/Uq7gcHh) for help.')
|
||||
return 2
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
from . import api
|
||||
from . import docs
|
||||
|
|
37
lib/python/qmk/cli/generate/docs.py
Normal file
37
lib/python/qmk/cli/generate/docs.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
"""Build QMK documentation locally
|
||||
"""
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
from milc import cli
|
||||
|
||||
DOCS_PATH = Path('docs/')
|
||||
BUILD_PATH = Path('.build/docs/')
|
||||
|
||||
|
||||
@cli.subcommand('Build QMK documentation.', hidden=False if cli.config.user.developer else True)
|
||||
def generate_docs(cli):
|
||||
"""Invoke the docs generation process
|
||||
|
||||
TODO(unclaimed):
|
||||
* [ ] Add a real build step... something static docs
|
||||
"""
|
||||
|
||||
if BUILD_PATH.exists():
|
||||
shutil.rmtree(BUILD_PATH)
|
||||
|
||||
shutil.copytree(DOCS_PATH, BUILD_PATH)
|
||||
|
||||
# When not verbose we want to hide all output
|
||||
args = {'check': True}
|
||||
if not cli.args.verbose:
|
||||
args.update({'stdout': subprocess.DEVNULL, 'stderr': subprocess.STDOUT})
|
||||
|
||||
cli.log.info('Generating internal docs...')
|
||||
|
||||
# Generate internal docs
|
||||
subprocess.run(['doxygen', 'Doxyfile'], **args)
|
||||
subprocess.run(['moxygen', '-q', '-a', '-g', '-o', BUILD_PATH / 'internals_%s.md', 'doxygen/xml'], **args)
|
||||
|
||||
cli.log.info('Successfully generated internal docs to %s.', BUILD_PATH)
|
|
@ -3,6 +3,7 @@
|
|||
Compile an info.json for a particular keyboard and pretty-print it.
|
||||
"""
|
||||
import json
|
||||
import platform
|
||||
|
||||
from milc import cli
|
||||
|
||||
|
@ -12,6 +13,8 @@ from qmk.keymap import locate_keymap
|
|||
from qmk.info import info_json
|
||||
from qmk.path import is_keyboard
|
||||
|
||||
platform_id = platform.platform().lower()
|
||||
|
||||
ROW_LETTERS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop'
|
||||
COL_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijilmnopqrstuvwxyz'
|
||||
|
||||
|
@ -36,13 +39,13 @@ def show_keymap(kb_info_json, title_caps=True):
|
|||
else:
|
||||
cli.echo('{fg_cyan}layer_%s{fg_reset}:', layer_num)
|
||||
|
||||
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], layer))
|
||||
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, layer))
|
||||
|
||||
|
||||
def show_layouts(kb_info_json, title_caps=True):
|
||||
"""Render the layouts with info.json labels.
|
||||
"""
|
||||
for layout_name, layout_art in render_layouts(kb_info_json).items():
|
||||
for layout_name, layout_art in render_layouts(kb_info_json, cli.config.info.ascii).items():
|
||||
title = layout_name.title() if title_caps else layout_name
|
||||
cli.echo('{fg_cyan}%s{fg_reset}:', title)
|
||||
print(layout_art) # Avoid passing dirty data to cli.echo()
|
||||
|
@ -69,7 +72,7 @@ def show_matrix(kb_info_json, title_caps=True):
|
|||
else:
|
||||
cli.echo('{fg_blue}matrix_%s{fg_reset}:', layout_name)
|
||||
|
||||
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], labels))
|
||||
print(render_layout(kb_info_json['layouts'][layout_name]['layout'], cli.config.info.ascii, labels))
|
||||
|
||||
|
||||
def print_friendly_output(kb_info_json):
|
||||
|
@ -124,6 +127,7 @@ def print_text_output(kb_info_json):
|
|||
@cli.argument('-l', '--layouts', action='store_true', help='Render the layouts.')
|
||||
@cli.argument('-m', '--matrix', action='store_true', help='Render the layouts with matrix information.')
|
||||
@cli.argument('-f', '--format', default='friendly', arg_only=True, help='Format to display the data in (friendly, text, json) (Default: friendly).')
|
||||
@cli.argument('--ascii', action='store_true', default='windows' in platform_id, help='Render layout box drawings in ASCII only.')
|
||||
@cli.subcommand('Keyboard information.')
|
||||
@automagic_keyboard
|
||||
@automagic_keymap
|
||||
|
@ -132,7 +136,7 @@ def info(cli):
|
|||
"""
|
||||
# Determine our keyboard(s)
|
||||
if not cli.config.info.keyboard:
|
||||
cli.log.error('Missing paramater: --keyboard')
|
||||
cli.log.error('Missing parameter: --keyboard')
|
||||
cli.subcommands['info'].print_help()
|
||||
return False
|
||||
|
||||
|
|
70
lib/python/qmk/cli/lint.py
Normal file
70
lib/python/qmk/cli/lint.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
"""Command to look over a keyboard/keymap and check for common mistakes.
|
||||
"""
|
||||
from milc import cli
|
||||
|
||||
from qmk.decorators import automagic_keyboard, automagic_keymap
|
||||
from qmk.info import info_json
|
||||
from qmk.keymap import locate_keymap
|
||||
from qmk.path import is_keyboard, keyboard
|
||||
|
||||
|
||||
@cli.argument('--strict', action='store_true', help='Treat warnings as errors.')
|
||||
@cli.argument('-kb', '--keyboard', help='The keyboard to check.')
|
||||
@cli.argument('-km', '--keymap', help='The keymap to check.')
|
||||
@cli.subcommand('Check keyboard and keymap for common mistakes.')
|
||||
@automagic_keyboard
|
||||
@automagic_keymap
|
||||
def lint(cli):
|
||||
"""Check keyboard and keymap for common mistakes.
|
||||
"""
|
||||
if not cli.config.lint.keyboard:
|
||||
cli.log.error('Missing required argument: --keyboard')
|
||||
cli.print_help()
|
||||
return False
|
||||
|
||||
if not is_keyboard(cli.config.lint.keyboard):
|
||||
cli.log.error('No such keyboard: %s', cli.config.lint.keyboard)
|
||||
return False
|
||||
|
||||
# Gather data about the keyboard.
|
||||
ok = True
|
||||
keyboard_path = keyboard(cli.config.lint.keyboard)
|
||||
keyboard_info = info_json(cli.config.lint.keyboard)
|
||||
readme_path = keyboard_path / 'readme.md'
|
||||
|
||||
# Check for errors in the info.json
|
||||
if keyboard_info['parse_errors']:
|
||||
ok = False
|
||||
cli.log.error('Errors found when generating info.json.')
|
||||
|
||||
if cli.config.lint.strict and keyboard_info['parse_warnings']:
|
||||
ok = False
|
||||
cli.log.error('Warnings found when generating info.json (Strict mode enabled.)')
|
||||
|
||||
# Check for a readme.md and warn if it doesn't exist
|
||||
if not readme_path.exists():
|
||||
ok = False
|
||||
cli.log.error('Missing %s', readme_path)
|
||||
|
||||
# Keymap specific checks
|
||||
if cli.config.lint.keymap:
|
||||
keymap_path = locate_keymap(cli.config.lint.keyboard, cli.config.lint.keymap)
|
||||
|
||||
if not keymap_path:
|
||||
ok = False
|
||||
cli.log.error("Can't find %s keymap for %s keyboard.", cli.config.lint.keymap, cli.config.lint.keyboard)
|
||||
else:
|
||||
keymap_readme = keymap_path.parent / 'readme.md'
|
||||
if not keymap_readme.exists():
|
||||
cli.log.warning('Missing %s', keymap_readme)
|
||||
|
||||
if cli.config.lint.strict:
|
||||
ok = False
|
||||
|
||||
# Check and report the overall status
|
||||
if ok:
|
||||
cli.log.info('Lint check passed!')
|
||||
return True
|
||||
|
||||
cli.log.error('Lint check failed!')
|
||||
return False
|
|
@ -28,6 +28,8 @@ def info_json(keyboard):
|
|||
'keyboard_folder': str(keyboard),
|
||||
'keymaps': {},
|
||||
'layouts': {},
|
||||
'parse_errors': [],
|
||||
'parse_warnings': [],
|
||||
'maintainer': 'qmk',
|
||||
}
|
||||
|
||||
|
@ -36,7 +38,7 @@ def info_json(keyboard):
|
|||
info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
|
||||
|
||||
# Populate layout data
|
||||
for layout_name, layout_json in _find_all_layouts(keyboard, rules).items():
|
||||
for layout_name, layout_json in _find_all_layouts(info_data, keyboard, rules).items():
|
||||
if not layout_name.startswith('LAYOUT_kc'):
|
||||
info_data['layouts'][layout_name] = layout_json
|
||||
|
||||
|
@ -104,14 +106,16 @@ def _extract_rules_mk(info_data):
|
|||
mcu = rules.get('MCU')
|
||||
|
||||
if mcu in CHIBIOS_PROCESSORS:
|
||||
arm_processor_rules(info_data, rules)
|
||||
elif mcu in LUFA_PROCESSORS + VUSB_PROCESSORS:
|
||||
avr_processor_rules(info_data, rules)
|
||||
else:
|
||||
cli.log.warning("%s: Unknown MCU: %s" % (info_data['keyboard_folder'], mcu))
|
||||
unknown_processor_rules(info_data, rules)
|
||||
return arm_processor_rules(info_data, rules)
|
||||
|
||||
return info_data
|
||||
elif mcu in LUFA_PROCESSORS + VUSB_PROCESSORS:
|
||||
return avr_processor_rules(info_data, rules)
|
||||
|
||||
msg = "Unknown MCU: " + str(mcu)
|
||||
|
||||
_log_warning(info_data, msg)
|
||||
|
||||
return unknown_processor_rules(info_data, rules)
|
||||
|
||||
|
||||
def _search_keyboard_h(path):
|
||||
|
@ -127,7 +131,7 @@ def _search_keyboard_h(path):
|
|||
return layouts
|
||||
|
||||
|
||||
def _find_all_layouts(keyboard, rules):
|
||||
def _find_all_layouts(info_data, keyboard, rules):
|
||||
"""Looks for layout macros associated with this keyboard.
|
||||
"""
|
||||
layouts = _search_keyboard_h(Path(keyboard))
|
||||
|
@ -135,7 +139,7 @@ def _find_all_layouts(keyboard, rules):
|
|||
if not layouts:
|
||||
# If we didn't find any layouts above we widen our search. This is error
|
||||
# prone which is why we want to encourage people to follow the standard above.
|
||||
cli.log.warning('%s: Falling back to searching for KEYMAP/LAYOUT macros.' % (keyboard))
|
||||
_log_warning(info_data, 'Falling back to searching for KEYMAP/LAYOUT macros.')
|
||||
for file in glob('keyboards/%s/*.h' % keyboard):
|
||||
if file.endswith('.h'):
|
||||
these_layouts = find_layouts(file)
|
||||
|
@ -153,11 +157,25 @@ def _find_all_layouts(keyboard, rules):
|
|||
supported_layouts.remove(layout_name)
|
||||
|
||||
if supported_layouts:
|
||||
cli.log.error('%s: Missing LAYOUT() macro for %s' % (keyboard, ', '.join(supported_layouts)))
|
||||
_log_error(info_data, 'Missing LAYOUT() macro for %s' % (', '.join(supported_layouts)))
|
||||
|
||||
return layouts
|
||||
|
||||
|
||||
def _log_error(info_data, message):
|
||||
"""Send an error message to both JSON and the log.
|
||||
"""
|
||||
info_data['parse_errors'].append(message)
|
||||
cli.log.error('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message)
|
||||
|
||||
|
||||
def _log_warning(info_data, message):
|
||||
"""Send a warning message to both JSON and the log.
|
||||
"""
|
||||
info_data['parse_warnings'].append(message)
|
||||
cli.log.warning('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message)
|
||||
|
||||
|
||||
def arm_processor_rules(info_data, rules):
|
||||
"""Setup the default info for an ARM board.
|
||||
"""
|
||||
|
@ -216,7 +234,7 @@ def merge_info_jsons(keyboard, info_data):
|
|||
new_info_data = json.load(info_fd)
|
||||
|
||||
if not isinstance(new_info_data, dict):
|
||||
cli.log.error("Invalid file %s, root object should be a dictionary.", str(info_file))
|
||||
_log_error(info_data, "Invalid file %s, root object should be a dictionary.", str(info_file))
|
||||
continue
|
||||
|
||||
# Copy whitelisted keys into `info_data`
|
||||
|
@ -230,7 +248,8 @@ def merge_info_jsons(keyboard, info_data):
|
|||
# Only pull in layouts we have a macro for
|
||||
if layout_name in info_data['layouts']:
|
||||
if info_data['layouts'][layout_name]['key_count'] != len(json_layout['layout']):
|
||||
cli.log.error('%s: %s: Number of elements in info.json does not match! info.json:%s != %s:%s', info_data['keyboard_folder'], layout_name, len(json_layout['layout']), layout_name, len(info_data['layouts'][layout_name]['layout']))
|
||||
msg = '%s: Number of elements in info.json does not match! info.json:%s != %s:%s'
|
||||
_log_error(info_data, msg % (layout_name, len(json_layout['layout']), layout_name, len(info_data['layouts'][layout_name]['layout'])))
|
||||
else:
|
||||
for i, key in enumerate(info_data['layouts'][layout_name]['layout']):
|
||||
key.update(json_layout['layout'][i])
|
||||
|
|
|
@ -9,6 +9,25 @@ from glob import glob
|
|||
from qmk.c_parse import parse_config_h_file
|
||||
from qmk.makefile import parse_rules_mk_file
|
||||
|
||||
BOX_DRAWING_CHARACTERS = {
|
||||
"unicode": {
|
||||
"tl": "┌",
|
||||
"tr": "┐",
|
||||
"bl": "└",
|
||||
"br": "┘",
|
||||
"v": "│",
|
||||
"h": "─",
|
||||
},
|
||||
"ascii": {
|
||||
"tl": " ",
|
||||
"tr": " ",
|
||||
"bl": "|",
|
||||
"br": "|",
|
||||
"v": "|",
|
||||
"h": "_",
|
||||
},
|
||||
}
|
||||
|
||||
base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep
|
||||
|
||||
|
||||
|
@ -72,10 +91,12 @@ def rules_mk(keyboard):
|
|||
return rules
|
||||
|
||||
|
||||
def render_layout(layout_data, key_labels=None):
|
||||
def render_layout(layout_data, render_ascii, key_labels=None):
|
||||
"""Renders a single layout.
|
||||
"""
|
||||
textpad = [array('u', ' ' * 200) for x in range(50)]
|
||||
style = 'ascii' if render_ascii else 'unicode'
|
||||
box_chars = BOX_DRAWING_CHARACTERS[style]
|
||||
|
||||
for key in layout_data:
|
||||
x = ceil(key.get('x', 0) * 4)
|
||||
|
@ -97,13 +118,13 @@ def render_layout(layout_data, key_labels=None):
|
|||
label = label[:label_len]
|
||||
|
||||
label_blank = ' ' * label_len
|
||||
label_border = '─' * label_len
|
||||
label_border = box_chars['h'] * label_len
|
||||
label_middle = label + ' '*label_leftover # noqa: yapf insists there be no whitespace around *
|
||||
|
||||
top_line = array('u', '┌' + label_border + '┐')
|
||||
lab_line = array('u', '│' + label_middle + '│')
|
||||
mid_line = array('u', '│' + label_blank + '│')
|
||||
bot_line = array('u', '└' + label_border + "┘")
|
||||
top_line = array('u', box_chars['tl'] + label_border + box_chars['tr'])
|
||||
lab_line = array('u', box_chars['v'] + label_middle + box_chars['v'])
|
||||
mid_line = array('u', box_chars['v'] + label_blank + box_chars['v'])
|
||||
bot_line = array('u', box_chars['bl'] + label_border + box_chars['br'])
|
||||
|
||||
textpad[y][x:x + w] = top_line
|
||||
textpad[y + 1][x:x + w] = lab_line
|
||||
|
@ -119,13 +140,13 @@ def render_layout(layout_data, key_labels=None):
|
|||
return '\n'.join(lines)
|
||||
|
||||
|
||||
def render_layouts(info_json):
|
||||
def render_layouts(info_json, render_ascii):
|
||||
"""Renders all the layouts from an `info_json` structure.
|
||||
"""
|
||||
layouts = {}
|
||||
|
||||
for layout in info_json['layouts']:
|
||||
layout_data = info_json['layouts'][layout]['layout']
|
||||
layouts[layout] = render_layout(layout_data)
|
||||
layouts[layout] = render_layout(layout_data, render_ascii)
|
||||
|
||||
return layouts
|
||||
|
|
|
@ -28,15 +28,21 @@ def under_qmk_firmware():
|
|||
return None
|
||||
|
||||
|
||||
def keymap(keyboard):
|
||||
def keyboard(keyboard_name):
|
||||
"""Returns the path to a keyboard's directory relative to the qmk root.
|
||||
"""
|
||||
return Path('keyboards') / keyboard_name
|
||||
|
||||
|
||||
def keymap(keyboard_name):
|
||||
"""Locate the correct directory for storing a keymap.
|
||||
|
||||
Args:
|
||||
|
||||
keyboard
|
||||
keyboard_name
|
||||
The name of the keyboard. Example: clueboard/66/rev3
|
||||
"""
|
||||
keyboard_folder = Path('keyboards') / keyboard
|
||||
keyboard_folder = keyboard(keyboard_name)
|
||||
|
||||
for i in range(MAX_KEYBOARD_SUBFOLDERS):
|
||||
if (keyboard_folder / 'keymaps').exists():
|
||||
|
@ -45,7 +51,7 @@ def keymap(keyboard):
|
|||
keyboard_folder = keyboard_folder.parent
|
||||
|
||||
logging.error('Could not find the keymaps directory!')
|
||||
raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard)
|
||||
raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard_name)
|
||||
|
||||
|
||||
def normpath(path):
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import platform
|
||||
|
||||
from subprocess import STDOUT, PIPE
|
||||
|
||||
from qmk.commands import run
|
||||
|
||||
is_windows = 'windows' in platform.platform().lower()
|
||||
|
||||
|
||||
def check_subcommand(command, *args):
|
||||
cmd = ['bin/qmk', command] + list(args)
|
||||
|
@ -9,14 +13,14 @@ def check_subcommand(command, *args):
|
|||
return result
|
||||
|
||||
|
||||
def check_returncode(result, expected=0):
|
||||
def check_returncode(result, expected=[0]):
|
||||
"""Print stdout if `result.returncode` does not match `expected`.
|
||||
"""
|
||||
if result.returncode != expected:
|
||||
if result.returncode not in expected:
|
||||
print('`%s` stdout:' % ' '.join(result.args))
|
||||
print(result.stdout)
|
||||
print('returncode:', result.returncode)
|
||||
assert result.returncode == expected
|
||||
assert result.returncode in expected
|
||||
|
||||
|
||||
def test_cformat():
|
||||
|
@ -41,7 +45,7 @@ def test_flash():
|
|||
|
||||
def test_flash_bootloaders():
|
||||
result = check_subcommand('flash', '-b')
|
||||
check_returncode(result, 1)
|
||||
check_returncode(result, [1])
|
||||
|
||||
|
||||
def test_config():
|
||||
|
@ -58,7 +62,7 @@ def test_kle2json():
|
|||
|
||||
def test_doctor():
|
||||
result = check_subcommand('doctor', '-n')
|
||||
check_returncode(result)
|
||||
check_returncode(result, [0, 1])
|
||||
assert 'QMK Doctor is checking your environment.' in result.stdout
|
||||
assert 'QMK is ready to go' in result.stdout
|
||||
|
||||
|
@ -85,43 +89,43 @@ def test_list_keyboards():
|
|||
|
||||
def test_list_keymaps():
|
||||
result = check_subcommand('list-keymaps', '-kb', 'handwired/onekey/pytest')
|
||||
check_returncode(result, 0)
|
||||
check_returncode(result)
|
||||
assert 'default' and 'test' in result.stdout
|
||||
|
||||
|
||||
def test_list_keymaps_long():
|
||||
result = check_subcommand('list-keymaps', '--keyboard', 'handwired/onekey/pytest')
|
||||
check_returncode(result, 0)
|
||||
check_returncode(result)
|
||||
assert 'default' and 'test' in result.stdout
|
||||
|
||||
|
||||
def test_list_keymaps_kb_only():
|
||||
result = check_subcommand('list-keymaps', '-kb', 'niu_mini')
|
||||
check_returncode(result, 0)
|
||||
check_returncode(result)
|
||||
assert 'default' and 'via' in result.stdout
|
||||
|
||||
|
||||
def test_list_keymaps_vendor_kb():
|
||||
result = check_subcommand('list-keymaps', '-kb', 'ai03/lunar')
|
||||
check_returncode(result, 0)
|
||||
check_returncode(result)
|
||||
assert 'default' and 'via' in result.stdout
|
||||
|
||||
|
||||
def test_list_keymaps_vendor_kb_rev():
|
||||
result = check_subcommand('list-keymaps', '-kb', 'kbdfans/kbd67/mkiirgb/v2')
|
||||
check_returncode(result, 0)
|
||||
check_returncode(result)
|
||||
assert 'default' and 'via' in result.stdout
|
||||
|
||||
|
||||
def test_list_keymaps_no_keyboard_found():
|
||||
result = check_subcommand('list-keymaps', '-kb', 'asdfghjkl')
|
||||
check_returncode(result, 1)
|
||||
check_returncode(result, [1])
|
||||
assert 'does not exist' in result.stdout
|
||||
|
||||
|
||||
def test_json2c():
|
||||
result = check_subcommand('json2c', 'keyboards/handwired/onekey/keymaps/default_json/keymap.json')
|
||||
check_returncode(result, 0)
|
||||
check_returncode(result)
|
||||
assert result.stdout == '#include QMK_KEYBOARD_H\nconst uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {\t[0] = LAYOUT_ortho_1x1(KC_A)};\n\n'
|
||||
|
||||
|
||||
|
@ -148,7 +152,11 @@ def test_info_keymap_render():
|
|||
check_returncode(result)
|
||||
assert 'Keyboard Name: handwired/onekey/pytest' in result.stdout
|
||||
assert 'Processor: STM32F303' in result.stdout
|
||||
assert '│A │' in result.stdout
|
||||
|
||||
if is_windows:
|
||||
assert '|A |' in result.stdout
|
||||
else:
|
||||
assert '│A │' in result.stdout
|
||||
|
||||
|
||||
def test_info_matrix_render():
|
||||
|
@ -157,7 +165,12 @@ def test_info_matrix_render():
|
|||
assert 'Keyboard Name: handwired/onekey/pytest' in result.stdout
|
||||
assert 'Processor: STM32F303' in result.stdout
|
||||
assert 'LAYOUT_ortho_1x1' in result.stdout
|
||||
assert '│0A│' in result.stdout
|
||||
|
||||
if is_windows:
|
||||
assert '|0A|' in result.stdout
|
||||
else:
|
||||
assert '│0A│' in result.stdout
|
||||
|
||||
assert 'Matrix for "LAYOUT_ortho_1x1"' in result.stdout
|
||||
|
||||
|
||||
|
@ -171,3 +184,9 @@ def test_c2json_nocpp():
|
|||
result = check_subcommand("c2json", "--no-cpp", "-kb", "handwired/onekey/pytest", "-km", "default", "keyboards/handwired/onekey/keymaps/pytest_nocpp/keymap.c")
|
||||
check_returncode(result)
|
||||
assert result.stdout.strip() == '{"keyboard": "handwired/onekey/pytest", "documentation": "This file is a keymap.json file for handwired/onekey/pytest", "keymap": "default", "layout": "LAYOUT", "layers": [["KC_ENTER"]]}'
|
||||
|
||||
|
||||
def test_clean():
|
||||
result = check_subcommand('clean', '-a')
|
||||
check_returncode(result)
|
||||
assert result.stdout.count('done') == 2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue