diff options
author | skullydazed <skullydazed@users.noreply.github.com> | 2020-03-13 15:47:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 15:47:04 -0700 |
commit | f81b0e35a6a25a9a6e633dc65a4900bed2458cfb (patch) | |
tree | 707e06f6cd2caeda4278cfd9751ee77bf15aa055 /lib/python/qmk/cli/compile.py | |
parent | 5e98eaaaff8fde1ce25b9bad6c00a982718cb467 (diff) | |
download | qmk_firmware-f81b0e35a6a25a9a6e633dc65a4900bed2458cfb.tar.gz qmk_firmware-f81b0e35a6a25a9a6e633dc65a4900bed2458cfb.zip |
Add decorators for determining keyboard and keymap based on current directory (#8191)
* Use pathlib everywhere we can
* Improvements based on @erovia's feedback
* rework qmk compile and qmk flash to use pathlib
* style
* Remove the subcommand_name argument from find_keyboard_keymap()
* add experimental decorators
* Create decorators for finding keyboard and keymap based on current directory.
Decorators were inspired by @Erovia's brilliant work on the proof of concept.
Diffstat (limited to 'lib/python/qmk/cli/compile.py')
-rwxr-xr-x | lib/python/qmk/cli/compile.py | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/python/qmk/cli/compile.py b/lib/python/qmk/cli/compile.py index 3068c97d8..6480d624b 100755 --- a/lib/python/qmk/cli/compile.py +++ b/lib/python/qmk/cli/compile.py | |||
@@ -8,13 +8,17 @@ from argparse import FileType | |||
8 | from milc import cli | 8 | from milc import cli |
9 | 9 | ||
10 | import qmk.path | 10 | import qmk.path |
11 | from qmk.commands import compile_configurator_json, create_make_command, find_keyboard_keymap, parse_configurator_json | 11 | from qmk.decorators import automagic_keyboard, automagic_keymap |
12 | from qmk.commands import compile_configurator_json, create_make_command, parse_configurator_json | ||
12 | 13 | ||
13 | 14 | ||
14 | @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), help='The configurator export to compile') | 15 | @cli.argument('filename', nargs='?', arg_only=True, type=FileType('r'), help='The configurator export to compile') |
15 | @cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') | 16 | @cli.argument('-kb', '--keyboard', help='The keyboard to build a firmware for. Ignored when a configurator export is supplied.') |
16 | @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') | 17 | @cli.argument('-km', '--keymap', help='The keymap to build a firmware for. Ignored when a configurator export is supplied.') |
18 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't actually build, just show the make command to be run.") | ||
17 | @cli.subcommand('Compile a QMK Firmware.') | 19 | @cli.subcommand('Compile a QMK Firmware.') |
20 | @automagic_keyboard | ||
21 | @automagic_keymap | ||
18 | def compile(cli): | 22 | def compile(cli): |
19 | """Compile a QMK Firmware. | 23 | """Compile a QMK Firmware. |
20 | 24 | ||
@@ -22,8 +26,10 @@ def compile(cli): | |||
22 | 26 | ||
23 | If a keyboard and keymap are provided this command will build a firmware based on that. | 27 | If a keyboard and keymap are provided this command will build a firmware based on that. |
24 | """ | 28 | """ |
29 | command = None | ||
30 | |||
25 | if cli.args.filename: | 31 | if cli.args.filename: |
26 | # If a configurator JSON was provided skip straight to compiling it | 32 | # If a configurator JSON was provided generate a keymap and compile it |
27 | # FIXME(skullydazed): add code to check and warn if the keymap already exists when compiling a json keymap. | 33 | # FIXME(skullydazed): add code to check and warn if the keymap already exists when compiling a json keymap. |
28 | user_keymap = parse_configurator_json(cli.args.filename) | 34 | user_keymap = parse_configurator_json(cli.args.filename) |
29 | keymap_path = qmk.path.keymap(user_keymap['keyboard']) | 35 | keymap_path = qmk.path.keymap(user_keymap['keyboard']) |
@@ -32,16 +38,23 @@ def compile(cli): | |||
32 | cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap']) | 38 | cli.log.info('Wrote keymap to {fg_cyan}%s/%s/keymap.c', keymap_path, user_keymap['keymap']) |
33 | 39 | ||
34 | else: | 40 | else: |
35 | # Perform the action the user specified | 41 | if cli.config.compile.keyboard and cli.config.compile.keymap: |
36 | user_keyboard, user_keymap = find_keyboard_keymap() | ||
37 | if user_keyboard and user_keymap: | ||
38 | # Generate the make command for a specific keyboard/keymap. | 42 | # Generate the make command for a specific keyboard/keymap. |
39 | command = create_make_command(user_keyboard, user_keymap) | 43 | command = create_make_command(cli.config.compile.keyboard, cli.config.compile.keymap) |
44 | |||
45 | elif not cli.config.compile.keyboard: | ||
46 | cli.log.error('Could not determine keyboard!') | ||
47 | elif not cli.config.compile.keymap: | ||
48 | cli.log.error('Could not determine keymap!') | ||
40 | 49 | ||
41 | else: | 50 | # Compile the firmware, if we're able to |
42 | cli.log.error('You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.') | 51 | if command: |
43 | cli.echo('usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]') | 52 | cli.log.info('Compiling keymap with {fg_cyan}%s', ' '.join(command)) |
44 | return False | 53 | if not cli.args.dry_run: |
54 | cli.echo('\n') | ||
55 | subprocess.run(command) | ||
45 | 56 | ||
46 | cli.log.info('Compiling keymap with {fg_cyan}%s\n\n', ' '.join(command)) | 57 | else: |
47 | subprocess.run(command) | 58 | cli.log.error('You must supply a configurator export, both `--keyboard` and `--keymap`, or be in a directory for a keyboard or keymap.') |
59 | cli.echo('usage: qmk compile [-h] [-b] [-kb KEYBOARD] [-km KEYMAP] [filename]') | ||
60 | return False | ||