summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/new
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2024-06-30 03:39:49 +0100
committerGitHub <noreply@github.com>2024-06-30 03:39:49 +0100
commit3ffe8d917a7c43e56b11ada82ac57b86003719a3 (patch)
tree11b361a1cf7946247643c04cec0127fc34939df5 /lib/python/qmk/cli/new
parent12379dc1ebd5bb1257eed5f7400510ee535d5d50 (diff)
Fix 'qmk new-keyboard' processing of development_board (#23996)
Diffstat (limited to 'lib/python/qmk/cli/new')
-rw-r--r--lib/python/qmk/cli/new/keyboard.py34
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py
index 56bd05e1e3..b84b130f8e 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
14from qmk.json_schema import load_jsonschema 14from qmk.json_schema import load_jsonschema
15from qmk.path import keyboard 15from qmk.path import keyboard
16from qmk.json_encoders import InfoJSONEncoder 16from qmk.json_encoders import InfoJSONEncoder
17from qmk.json_schema import deep_update, json_load 17from qmk.json_schema import deep_update
18from qmk.constants import MCU2BOOTLOADER, QMK_FIRMWARE 18from qmk.constants import MCU2BOOTLOADER, QMK_FIRMWARE
19 19
20COMMUNITY = Path('layouts/default/') 20COMMUNITY = Path('layouts/default/')
@@ -78,7 +78,7 @@ def replace_string(src, token, value):
78 src.write_text(src.read_text().replace(token, value)) 78 src.write_text(src.read_text().replace(token, value))
79 79
80 80
81def augment_community_info(src, dest): 81def augment_community_info(config, src, dest):
82 """Splice in any additional data into info.json 82 """Splice in any additional data into info.json
83 """ 83 """
84 info = json.loads(src.read_text()) 84 info = json.loads(src.read_text())
@@ -86,6 +86,7 @@ def augment_community_info(src, dest):
86 86
87 # merge community with template 87 # merge community with template
88 deep_update(info, template) 88 deep_update(info, template)
89 deep_update(info, config)
89 90
90 # avoid assumptions on macro name by using the first available 91 # avoid assumptions on macro name by using the first available
91 first_layout = next(iter(info["layouts"].values()))["layout"] 92 first_layout = next(iter(info["layouts"].values()))["layout"]
@@ -105,7 +106,7 @@ def augment_community_info(src, dest):
105 for item in first_layout: 106 for item in first_layout:
106 item["matrix"] = [int(item["y"]), int(item["x"])] 107 item["matrix"] = [int(item["y"]), int(item["x"])]
107 108
108 # finally write out the updated info.json 109 # finally write out the updated json
109 dest.write_text(json.dumps(info, cls=InfoJSONEncoder, sort_keys=True)) 110 dest.write_text(json.dumps(info, cls=InfoJSONEncoder, sort_keys=True))
110 111
111 112
@@ -212,15 +213,12 @@ def new_keyboard(cli):
212 default_layout = cli.args.layout if cli.args.layout else prompt_layout() 213 default_layout = cli.args.layout if cli.args.layout else prompt_layout()
213 mcu = cli.args.type if cli.args.type else prompt_mcu() 214 mcu = cli.args.type if cli.args.type else prompt_mcu()
214 215
215 # Preprocess any development_board presets 216 config = {}
216 if mcu in dev_boards: 217 if mcu in dev_boards:
217 defaults_map = json_load(Path('data/mappings/defaults.hjson')) 218 config['development_board'] = mcu
218 board = defaults_map['development_board'][mcu]
219
220 mcu = board['processor']
221 bootloader = board['bootloader']
222 else: 219 else:
223 bootloader = select_default_bootloader(mcu) 220 config['processor'] = mcu
221 config['bootloader'] = select_default_bootloader(mcu)
224 222
225 detach_layout = False 223 detach_layout = False
226 if default_layout == 'none of the above': 224 if default_layout == 'none of the above':
@@ -231,17 +229,9 @@ def new_keyboard(cli):
231 'YEAR': str(date.today().year), 229 'YEAR': str(date.today().year),
232 'KEYBOARD': kb_name, 230 'KEYBOARD': kb_name,
233 'USER_NAME': user_name, 231 'USER_NAME': user_name,
234 'REAL_NAME': real_name, 232 'REAL_NAME': real_name
235 'LAYOUT': default_layout,
236 'MCU': mcu,
237 'BOOTLOADER': bootloader
238 } 233 }
239 234
240 if cli.config.general.verbose:
241 cli.log.info("Creating keyboard with:")
242 for key, value in tokens.items():
243 cli.echo(f" {key.ljust(10)}: {value}")
244
245 # begin with making the deepest folder in the tree 235 # begin with making the deepest folder in the tree
246 keymaps_path = keyboard(kb_name) / 'keymaps/' 236 keymaps_path = keyboard(kb_name) / 'keymaps/'
247 keymaps_path.mkdir(parents=True) 237 keymaps_path.mkdir(parents=True)
@@ -256,7 +246,7 @@ def new_keyboard(cli):
256 246
257 # merge in infos 247 # merge in infos
258 community_info = Path(COMMUNITY / f'{default_layout}/info.json') 248 community_info = Path(COMMUNITY / f'{default_layout}/info.json')
259 augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json') 249 augment_community_info(config, community_info, keyboard(kb_name) / 'keyboard.json')
260 250
261 # detach community layout and rename to just "LAYOUT" 251 # detach community layout and rename to just "LAYOUT"
262 if detach_layout: 252 if detach_layout:
@@ -265,5 +255,5 @@ def new_keyboard(cli):
265 255
266 cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}') 256 cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
267 cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.") 257 cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
268 cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}},') 258 cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}}.')
269 cli.log.info("{{fg_yellow}}Now update the config files to match the hardware!{{fg_reset}}") 259 cli.log.info("{fg_yellow}Now update the config files to match the hardware!{fg_reset}")