diff options
Diffstat (limited to 'lib/python/qmk')
-rw-r--r-- | lib/python/qmk/build_targets.py | 22 | ||||
-rw-r--r-- | lib/python/qmk/cli/__init__.py | 3 | ||||
-rw-r--r-- | lib/python/qmk/cli/doctor/check.py | 26 | ||||
-rw-r--r-- | lib/python/qmk/cli/generate/keycodes_tests.py | 39 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/make_dependencies.py | 4 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/rules_mk.py | 2 | ||||
-rw-r--r-- | lib/python/qmk/cli/lint.py | 13 | ||||
-rw-r--r-- | lib/python/qmk/commands.py | 3 | ||||
-rwxr-xr-x | lib/python/qmk/json_encoders.py | 8 | ||||
-rw-r--r-- | lib/python/qmk/keymap.py | 11 |
10 files changed, 59 insertions, 72 deletions
diff --git a/lib/python/qmk/build_targets.py b/lib/python/qmk/build_targets.py index e2df029490..df5a5ffb42 100644 --- a/lib/python/qmk/build_targets.py +++ b/lib/python/qmk/build_targets.py @@ -11,7 +11,7 @@ from qmk.commands import find_make, get_make_parallel_args, parse_configurator_j from qmk.keyboard import keyboard_folder from qmk.info import keymap_json from qmk.keymap import locate_keymap -from qmk.path import is_under_qmk_firmware, is_under_qmk_userspace +from qmk.path import is_under_qmk_firmware, is_under_qmk_userspace, unix_style_path # These must be kept in the order in which they're applied to $(TARGET) in the makefiles in order to ensure consistency. TARGET_FILENAME_MODIFIERS = ['FORCE_LAYOUT', 'CONVERT_TO'] @@ -204,11 +204,11 @@ class KeyboardKeymapBuildTarget(BuildTarget): if is_under_qmk_userspace(keymap_location) and not is_under_qmk_firmware(keymap_location): keymap_directory = keymap_location.parent compile_args.extend([ - f'MAIN_KEYMAP_PATH_1={keymap_directory}', - f'MAIN_KEYMAP_PATH_2={keymap_directory}', - f'MAIN_KEYMAP_PATH_3={keymap_directory}', - f'MAIN_KEYMAP_PATH_4={keymap_directory}', - f'MAIN_KEYMAP_PATH_5={keymap_directory}', + f'MAIN_KEYMAP_PATH_1={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_2={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_3={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_4={unix_style_path(keymap_directory)}', + f'MAIN_KEYMAP_PATH_5={unix_style_path(keymap_directory)}', ]) return compile_args @@ -267,11 +267,11 @@ class JsonKeymapBuildTarget(BuildTarget): generated_files_path = intermediate_output / 'src' keymap_json = generated_files_path / 'keymap.json' compile_args.extend([ - f'MAIN_KEYMAP_PATH_1={intermediate_output}', - f'MAIN_KEYMAP_PATH_2={intermediate_output}', - f'MAIN_KEYMAP_PATH_3={intermediate_output}', - f'MAIN_KEYMAP_PATH_4={intermediate_output}', - f'MAIN_KEYMAP_PATH_5={intermediate_output}', + f'MAIN_KEYMAP_PATH_1={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_2={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_3={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_4={unix_style_path(intermediate_output)}', + f'MAIN_KEYMAP_PATH_5={unix_style_path(intermediate_output)}', f'KEYMAP_JSON={keymap_json}', f'KEYMAP_PATH={generated_files_path}', ]) diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 3f2ba9ce3c..26905ec134 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py @@ -58,7 +58,6 @@ subcommands = [ 'qmk.cli.generate.keyboard_c', 'qmk.cli.generate.keyboard_h', 'qmk.cli.generate.keycodes', - 'qmk.cli.generate.keycodes_tests', 'qmk.cli.generate.keymap_h', 'qmk.cli.generate.make_dependencies', 'qmk.cli.generate.rgb_breathe_table', @@ -215,7 +214,7 @@ if sys.version_info[0] != 3 or sys.version_info[1] < 9: milc_version = __VERSION__.split('.') -if int(milc_version[0]) < 2 and int(milc_version[1]) < 4: +if int(milc_version[0]) < 2 and int(milc_version[1]) < 9: requirements = Path('requirements.txt').resolve() _eprint(f'Your MILC library is too old! Please upgrade: python3 -m pip install -U -r {str(requirements)}') diff --git a/lib/python/qmk/cli/doctor/check.py b/lib/python/qmk/cli/doctor/check.py index 2804a1d7df..51b0f0c80a 100644 --- a/lib/python/qmk/cli/doctor/check.py +++ b/lib/python/qmk/cli/doctor/check.py @@ -54,10 +54,13 @@ def _check_arm_gcc_installation(): """Returns OK if the arm-none-eabi-gcc is fully installed and can produce binaries. """ with TemporaryDirectory() as temp_dir: - temp_file = Path(temp_dir) / 'test.elf' + temp_in = Path(temp_dir) / 'test.c' + temp_out = Path(temp_dir) / 'test.elf' - args = ['arm-none-eabi-gcc', '-mcpu=cortex-m0', '-mthumb', '-mno-thumb-interwork', '--specs=nosys.specs', '--specs=nano.specs', '-x', 'c', '-o', str(temp_file), '-'] - result = cli.run(args, stdin=None, stdout=None, stderr=None, input='#include <newlib.h>\nint main() { return __NEWLIB__ * __NEWLIB_MINOR__ * __NEWLIB_PATCHLEVEL__; }') + temp_in.write_text('#include <newlib.h>\nint main() { return __NEWLIB__ * __NEWLIB_MINOR__ * __NEWLIB_PATCHLEVEL__; }', encoding='utf-8') + + args = ['arm-none-eabi-gcc', '-mcpu=cortex-m0', '-mthumb', '-mno-thumb-interwork', '--specs=nosys.specs', '--specs=nano.specs', '-x', 'c', '-o', str(temp_out), str(temp_in)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully compiled using arm-none-eabi-gcc') else: @@ -65,8 +68,8 @@ def _check_arm_gcc_installation(): cli.log.error(f'Command: {" ".join(args)}') return CheckStatus.ERROR - args = ['arm-none-eabi-size', str(temp_file)] - result = cli.run(args, stdin=None, stdout=None, stderr=None) + args = ['arm-none-eabi-size', str(temp_out)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully tested arm-none-eabi-binutils using arm-none-eabi-size') else: @@ -91,10 +94,13 @@ def _check_avr_gcc_installation(): """Returns OK if the avr-gcc is fully installed and can produce binaries. """ with TemporaryDirectory() as temp_dir: - temp_file = Path(temp_dir) / 'test.elf' + temp_in = Path(temp_dir) / 'test.c' + temp_out = Path(temp_dir) / 'test.elf' + + temp_in.write_text('int main() { return 0; }', encoding='utf-8') - args = ['avr-gcc', '-mmcu=atmega32u4', '-x', 'c', '-o', str(temp_file), '-'] - result = cli.run(args, stdin=None, stdout=None, stderr=None, input='int main() { return 0; }') + args = ['avr-gcc', '-mmcu=atmega32u4', '-x', 'c', '-o', str(temp_out), str(temp_in)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully compiled using avr-gcc') else: @@ -102,8 +108,8 @@ def _check_avr_gcc_installation(): cli.log.error(f'Command: {" ".join(args)}') return CheckStatus.ERROR - args = ['avr-size', str(temp_file)] - result = cli.run(args, stdin=None, stdout=None, stderr=None) + args = ['avr-size', str(temp_out)] + result = cli.run(args, stdout=None, stderr=None) if result.returncode == 0: cli.log.info('Successfully tested avr-binutils using avr-size') else: diff --git a/lib/python/qmk/cli/generate/keycodes_tests.py b/lib/python/qmk/cli/generate/keycodes_tests.py deleted file mode 100644 index 453b4693a7..0000000000 --- a/lib/python/qmk/cli/generate/keycodes_tests.py +++ /dev/null @@ -1,39 +0,0 @@ -"""Used by the make system to generate a keycode lookup table from keycodes_{version}.json -""" -from milc import cli - -from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE -from qmk.commands import dump_lines -from qmk.path import normpath -from qmk.keycodes import load_spec - - -def _generate_defines(lines, keycodes): - lines.append('') - lines.append('std::map<uint16_t, std::string> KEYCODE_ID_TABLE = {') - for key, value in keycodes["keycodes"].items(): - lines.append(f' {{{value.get("key")}, "{value.get("key")}"}},') - lines.append('};') - - [email protected]('-v', '--version', arg_only=True, required=True, help='Version of keycodes to generate.') [email protected]('-o', '--output', arg_only=True, type=normpath, help='File to write to') [email protected]('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") [email protected]('Used by the make system to generate a keycode lookup table from keycodes_{version}.json', hidden=True) -def generate_keycodes_tests(cli): - """Generates a keycode to identifier lookup table for unit test output. - """ - - # Build the keycodes.h file. - keycodes_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '// clang-format off'] - keycodes_h_lines.append('extern "C" {\n#include <keycode.h>\n}') - keycodes_h_lines.append('#include <map>') - keycodes_h_lines.append('#include <string>') - keycodes_h_lines.append('#include <cstdint>') - - keycodes = load_spec(cli.args.version) - - _generate_defines(keycodes_h_lines, keycodes) - - # Show the results - dump_lines(cli.args.output, keycodes_h_lines, cli.args.quiet) diff --git a/lib/python/qmk/cli/generate/make_dependencies.py b/lib/python/qmk/cli/generate/make_dependencies.py index 331132a20f..9548187888 100755 --- a/lib/python/qmk/cli/generate/make_dependencies.py +++ b/lib/python/qmk/cli/generate/make_dependencies.py @@ -8,7 +8,7 @@ from argcomplete.completers import FilesCompleter from qmk.commands import dump_lines from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.keymap import keymap_completer, locate_keymap -from qmk.path import normpath, FileType +from qmk.path import normpath, FileType, unix_style_path @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), completer=FilesCompleter('.json'), help='A configurator export JSON.') @@ -53,4 +53,4 @@ def generate_make_dependencies(cli): for file in interesting_files: check_files.append(Path('users') / cli.args.keymap / file) - dump_lines(cli.args.output, [f'generated-files: $(wildcard {found})\n' for found in check_files]) + dump_lines(cli.args.output, [f'generated-files: $(wildcard {unix_style_path(found)})\n' for found in check_files]) diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index ef4101d77f..01d71d277f 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -72,6 +72,8 @@ def generate_modules_rules(keyboard, filename): lines.append(f'COMMUNITY_MODULE_PATHS += {module_path}') lines.append(f'VPATH += {module_path}') lines.append(f'SRC += $(wildcard {module_path}/{module_path.name}.c)') + lines.append(f'MODULE_NAME_{module_path.name.upper()} := {module_path.name}') + lines.append(f'MODULE_PATH_{module_path.name.upper()} := {module_path}') lines.append(f'-include {module_path}/rules.mk') module_jsons = load_module_jsons(modules) diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py index bcf905f579..e2c76e4465 100644 --- a/lib/python/qmk/cli/lint.py +++ b/lib/python/qmk/cli/lint.py @@ -26,7 +26,7 @@ def _list_defaultish_keymaps(kb): defaultish.extend(INVALID_KM_NAMES) keymaps = set() - for x in list_keymaps(kb): + for x in list_keymaps(kb, include_userspace=False): if x in defaultish or x.startswith('default'): keymaps.add(x) @@ -171,6 +171,14 @@ def _handle_invalid_features(kb, info): return ok +def _handle_invalid_config(kb, info): + """Check for invalid keyboard level config + """ + if info.get('url') == "": + cli.log.warning(f'{kb}: Invalid keyboard level config detected - Optional field "url" should not be empty.') + return True + + def _chibios_conf_includenext_check(target): """Check the ChibiOS conf.h for the correct inclusion of the next conf.h """ @@ -255,6 +263,9 @@ def keyboard_check(kb): # noqa C901 if not _handle_invalid_features(kb, kb_info): ok = False + if not _handle_invalid_config(kb, kb_info): + ok = False + invalid_files = git_get_ignored_files(f'keyboards/{kb}/') for file in invalid_files: if 'keymap' in file: diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py index 0e1876ca7a..ac1455967d 100644 --- a/lib/python/qmk/commands.py +++ b/lib/python/qmk/commands.py @@ -12,6 +12,7 @@ from qmk.constants import QMK_USERSPACE, HAS_QMK_USERSPACE from qmk.json_schema import json_load, validate from qmk.keyboard import keyboard_alias_definitions from qmk.util import maybe_exit +from qmk.path import unix_style_path def find_make(): @@ -85,7 +86,7 @@ def build_environment(args): envs = parse_env_vars(args) if HAS_QMK_USERSPACE: - envs['QMK_USERSPACE'] = Path(QMK_USERSPACE).resolve() + envs['QMK_USERSPACE'] = unix_style_path(Path(QMK_USERSPACE).resolve()) return envs diff --git a/lib/python/qmk/json_encoders.py b/lib/python/qmk/json_encoders.py index e83a381d52..e8bcf48996 100755 --- a/lib/python/qmk/json_encoders.py +++ b/lib/python/qmk/json_encoders.py @@ -250,12 +250,14 @@ class CommunityModuleJSONEncoder(QMKJSONEncoder): return '00module_name' if key == 'maintainer': return '01maintainer' + if key == 'license': + return '02license' if key == 'url': - return '02url' + return '03url' if key == 'features': - return '03features' + return '04features' if key == 'keycodes': - return '04keycodes' + return '05keycodes' elif self.indentation_level == 3: # keycodes if key == 'key': return '00key' diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 8e36461722..b7138aa4a1 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py @@ -399,7 +399,7 @@ def is_keymap_target(keyboard, keymap): return False -def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False): +def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=False, include_userspace=True): """List the available keymaps for a keyboard. Args: @@ -418,14 +418,19 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa fullpath When set to True the full path of the keymap relative to the `qmk_firmware` root will be provided. + include_userspace + When set to True, also search userspace for available keymaps + Returns: a sorted list of valid keymap names. """ names = set() + has_userspace = HAS_QMK_USERSPACE and include_userspace + # walk up the directory tree until keyboards_dir # and collect all directories' name with keymap.c file in it - for search_dir in [QMK_FIRMWARE, QMK_USERSPACE] if HAS_QMK_USERSPACE else [QMK_FIRMWARE]: + for search_dir in [QMK_FIRMWARE, QMK_USERSPACE] if has_userspace else [QMK_FIRMWARE]: keyboards_dir = search_dir / Path('keyboards') kb_path = keyboards_dir / keyboard @@ -443,7 +448,7 @@ def list_keymaps(keyboard, c=True, json=True, additional_files=None, fullpath=Fa info = info_json(keyboard) community_parents = list(Path('layouts').glob('*/')) - if HAS_QMK_USERSPACE and (Path(QMK_USERSPACE) / "layouts").exists(): + if has_userspace and (Path(QMK_USERSPACE) / "layouts").exists(): community_parents.append(Path(QMK_USERSPACE) / "layouts") for community_parent in community_parents: |