diff options
| author | Joel Challis <git@zvecr.com> | 2022-04-08 20:12:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-08 20:12:32 +0100 |
| commit | 2cfbc1445cfd8986a76872a30454ddc2e98f6d63 (patch) | |
| tree | d1c489bff14fd37c502496d5459ad1f7efa475f2 /lib/python/qmk/cli/new | |
| parent | 675ce769723109c1526e25d1c08c6e5282fd088d (diff) | |
Allow new-keyboard to use development_board presets (#16785)
Diffstat (limited to 'lib/python/qmk/cli/new')
| -rw-r--r-- | lib/python/qmk/cli/new/keyboard.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py index 1cdfe53206..8d4def1bef 100644 --- a/lib/python/qmk/cli/new/keyboard.py +++ b/lib/python/qmk/cli/new/keyboard.py | |||
| @@ -14,7 +14,7 @@ from qmk.git import git_get_username | |||
| 14 | from qmk.json_schema import load_jsonschema | 14 | from qmk.json_schema import load_jsonschema |
| 15 | from qmk.path import keyboard | 15 | from qmk.path import keyboard |
| 16 | from qmk.json_encoders import InfoJSONEncoder | 16 | from qmk.json_encoders import InfoJSONEncoder |
| 17 | from qmk.json_schema import deep_update | 17 | from qmk.json_schema import deep_update, json_load |
| 18 | from qmk.constants import MCU2BOOTLOADER | 18 | from qmk.constants import MCU2BOOTLOADER |
| 19 | 19 | ||
| 20 | COMMUNITY = Path('layouts/default/') | 20 | COMMUNITY = Path('layouts/default/') |
| @@ -23,13 +23,14 @@ TEMPLATE = Path('data/templates/keyboard/') | |||
| 23 | # defaults | 23 | # defaults |
| 24 | schema = dotty(load_jsonschema('keyboard')) | 24 | schema = dotty(load_jsonschema('keyboard')) |
| 25 | mcu_types = sorted(schema["properties.processor.enum"], key=str.casefold) | 25 | mcu_types = sorted(schema["properties.processor.enum"], key=str.casefold) |
| 26 | dev_boards = sorted(schema["properties.development_board.enum"], key=str.casefold) | ||
| 26 | available_layouts = sorted([x.name for x in COMMUNITY.iterdir() if x.is_dir()]) | 27 | available_layouts = sorted([x.name for x in COMMUNITY.iterdir() if x.is_dir()]) |
| 27 | 28 | ||
| 28 | 29 | ||
| 29 | def mcu_type(mcu): | 30 | def mcu_type(mcu): |
| 30 | """Callable for argparse validation. | 31 | """Callable for argparse validation. |
| 31 | """ | 32 | """ |
| 32 | if mcu not in mcu_types: | 33 | if mcu not in (dev_boards + mcu_types): |
| 33 | raise ValueError | 34 | raise ValueError |
| 34 | return mcu | 35 | return mcu |
| 35 | 36 | ||
| @@ -176,14 +177,14 @@ https://docs.qmk.fm/#/compatible_microcontrollers | |||
| 176 | 177 | ||
| 177 | MCU? """ | 178 | MCU? """ |
| 178 | # remove any options strictly used for compatibility | 179 | # remove any options strictly used for compatibility |
| 179 | filtered_mcu = [x for x in mcu_types if not any(xs in x for xs in ['cortex', 'unknown'])] | 180 | filtered_mcu = [x for x in (dev_boards + mcu_types) if not any(xs in x for xs in ['cortex', 'unknown'])] |
| 180 | 181 | ||
| 181 | return choice(prompt, filtered_mcu, default=filtered_mcu.index("atmega32u4")) | 182 | return choice(prompt, filtered_mcu, default=filtered_mcu.index("atmega32u4")) |
| 182 | 183 | ||
| 183 | 184 | ||
| 184 | @cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name) | 185 | @cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name) |
| 185 | @cli.argument('-l', '--layout', help='Community layout to bootstrap with', arg_only=True, type=layout_type) | 186 | @cli.argument('-l', '--layout', help='Community layout to bootstrap with', arg_only=True, type=layout_type) |
| 186 | @cli.argument('-t', '--type', help='Specify the keyboard MCU type', arg_only=True, type=mcu_type) | 187 | @cli.argument('-t', '--type', help='Specify the keyboard MCU type (or "development_board" preset)', arg_only=True, type=mcu_type) |
| 187 | @cli.argument('-u', '--username', help='Specify your username (default from Git config)', dest='name') | 188 | @cli.argument('-u', '--username', help='Specify your username (default from Git config)', dest='name') |
| 188 | @cli.argument('-n', '--realname', help='Specify your real name if you want to use that. Defaults to username', arg_only=True) | 189 | @cli.argument('-n', '--realname', help='Specify your real name if you want to use that. Defaults to username', arg_only=True) |
| 189 | @cli.subcommand('Creates a new keyboard directory') | 190 | @cli.subcommand('Creates a new keyboard directory') |
| @@ -198,7 +199,6 @@ def new_keyboard(cli): | |||
| 198 | real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name) | 199 | real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name) |
| 199 | default_layout = cli.args.layout if cli.args.layout else prompt_layout() | 200 | default_layout = cli.args.layout if cli.args.layout else prompt_layout() |
| 200 | mcu = cli.args.type if cli.args.type else prompt_mcu() | 201 | mcu = cli.args.type if cli.args.type else prompt_mcu() |
| 201 | bootloader = select_default_bootloader(mcu) | ||
| 202 | 202 | ||
| 203 | if not validate_keyboard_name(kb_name): | 203 | if not validate_keyboard_name(kb_name): |
| 204 | cli.log.error('Keyboard names must contain only {fg_cyan}lowercase a-z{fg_reset}, {fg_cyan}0-9{fg_reset}, and {fg_cyan}_{fg_reset}! Please choose a different name.') | 204 | cli.log.error('Keyboard names must contain only {fg_cyan}lowercase a-z{fg_reset}, {fg_cyan}0-9{fg_reset}, and {fg_cyan}_{fg_reset}! Please choose a different name.') |
| @@ -208,6 +208,16 @@ def new_keyboard(cli): | |||
| 208 | cli.log.error(f'Keyboard {{fg_cyan}}{kb_name}{{fg_reset}} already exists! Please choose a different name.') | 208 | cli.log.error(f'Keyboard {{fg_cyan}}{kb_name}{{fg_reset}} already exists! Please choose a different name.') |
| 209 | return 1 | 209 | return 1 |
| 210 | 210 | ||
| 211 | # Preprocess any development_board presets | ||
| 212 | if mcu in dev_boards: | ||
| 213 | defaults_map = json_load(Path('data/mappings/defaults.json')) | ||
| 214 | board = defaults_map['development_board'][mcu] | ||
| 215 | |||
| 216 | mcu = board['processor'] | ||
| 217 | bootloader = board['bootloader'] | ||
| 218 | else: | ||
| 219 | bootloader = select_default_bootloader(mcu) | ||
| 220 | |||
| 211 | tokens = { # Comment here is to force multiline formatting | 221 | tokens = { # Comment here is to force multiline formatting |
| 212 | 'YEAR': str(date.today().year), | 222 | 'YEAR': str(date.today().year), |
| 213 | 'KEYBOARD': kb_name, | 223 | 'KEYBOARD': kb_name, |
