diff options
author | Zach White <skullydazed@gmail.com> | 2021-02-27 12:00:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-27 12:00:50 -0800 |
commit | 1581ea48dcd48d0d3f42cc09b388c468aedec45d (patch) | |
tree | 2d028036a4bf80c2e47b952931544f95ba2174e9 /lib/python/qmk/cli | |
parent | 23ed6c4ec0bfb27612da8a7b78d1b484acc23f3f (diff) |
Fix develop (#12039)
Fixes file encoding errors on Windows, and layouts not correctly merging into info.json.
* force utf8 encoding
* correctly merge layouts and layout aliases
* show what aliases point to
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r-- | lib/python/qmk/cli/chibios/confmigrate.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/layouts.py | 4 | ||||
-rwxr-xr-x | lib/python/qmk/cli/info.py | 7 | ||||
-rwxr-xr-x | lib/python/qmk/cli/kle2json.py | 2 |
4 files changed, 14 insertions, 7 deletions
diff --git a/lib/python/qmk/cli/chibios/confmigrate.py b/lib/python/qmk/cli/chibios/confmigrate.py index 3e348b2b07..89995931a4 100644 --- a/lib/python/qmk/cli/chibios/confmigrate.py +++ b/lib/python/qmk/cli/chibios/confmigrate.py @@ -40,7 +40,7 @@ file_header = """\ def collect_defines(filepath): - with open(filepath, 'r') as f: + with open(filepath, 'r', encoding='utf-8') as f: content = f.read() define_search = re.compile(r'(?m)^#\s*define\s+(?:.*\\\r?\n)*.*$', re.MULTILINE) value_search = re.compile(r'^#\s*define\s+(?P<name>[a-zA-Z0-9_]+(\([^\)]*\))?)\s*(?P<value>.*)', re.DOTALL) @@ -146,17 +146,17 @@ def chibios_confmigrate(cli): if cli.args.input.name == "chconf.h" and ("CHCONF_H" in input_defs["dict"] or "_CHCONF_H_" in input_defs["dict"] or cli.args.force): migrate_chconf_h(to_override, outfile=sys.stdout) if cli.args.overwrite: - with open(cli.args.input, "w") as out_file: + with open(cli.args.input, "w", encoding='utf-8') as out_file: migrate_chconf_h(to_override, outfile=out_file) elif cli.args.input.name == "halconf.h" and ("HALCONF_H" in input_defs["dict"] or "_HALCONF_H_" in input_defs["dict"] or cli.args.force): migrate_halconf_h(to_override, outfile=sys.stdout) if cli.args.overwrite: - with open(cli.args.input, "w") as out_file: + with open(cli.args.input, "w", encoding='utf-8') as out_file: migrate_halconf_h(to_override, outfile=out_file) elif cli.args.input.name == "mcuconf.h" and ("MCUCONF_H" in input_defs["dict"] or "_MCUCONF_H_" in input_defs["dict"] or cli.args.force): migrate_mcuconf_h(to_override, outfile=sys.stdout) if cli.args.overwrite: - with open(cli.args.input, "w") as out_file: + with open(cli.args.input, "w", encoding='utf-8') as out_file: migrate_mcuconf_h(to_override, outfile=out_file) diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py index b7baae0651..15b289522e 100755 --- a/lib/python/qmk/cli/generate/layouts.py +++ b/lib/python/qmk/cli/generate/layouts.py @@ -82,6 +82,10 @@ def generate_layouts(cli): layouts_h_lines.append(rows) layouts_h_lines.append('}') + for alias, target in kb_info_json.get('layout_aliases', {}).items(): + layouts_h_lines.append('') + layouts_h_lines.append('#define %s %s' % (alias, target)) + # Show the results layouts_h = '\n'.join(layouts_h_lines) + '\n' diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 87d7253d4b..a7ce8abf03 100755 --- a/lib/python/qmk/cli/info.py +++ b/lib/python/qmk/cli/info.py @@ -29,7 +29,7 @@ def show_keymap(kb_info_json, title_caps=True): else: cli.echo('{fg_blue}keymap_%s{fg_reset}:', cli.config.info.keymap) - keymap_data = json.load(keymap_path.open()) + keymap_data = json.load(keymap_path.open(encoding='utf-8')) layout_name = keymap_data['layout'] for layer_num, layer in enumerate(keymap_data['layers']): @@ -57,7 +57,7 @@ def show_matrix(kb_info_json, title_caps=True): # Build our label list labels = [] for key in layout['layout']: - if key['matrix']: + if 'matrix' in key: row = ROW_LETTERS[key['matrix'][0]] col = COL_LETTERS[key['matrix'][1]] @@ -91,6 +91,9 @@ def print_friendly_output(kb_info_json): cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height'])) cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) + if 'layout_aliases' in kb_info_json: + aliases = [f'{key}={value}' for key, value in kb_info_json['layout_aliases'].items()] + cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),)) if cli.config.info.layouts: show_layouts(kb_info_json, True) diff --git a/lib/python/qmk/cli/kle2json.py b/lib/python/qmk/cli/kle2json.py index 66d504bfc2..3bb7443582 100755 --- a/lib/python/qmk/cli/kle2json.py +++ b/lib/python/qmk/cli/kle2json.py @@ -27,7 +27,7 @@ def kle2json(cli): cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) return False out_path = file_path.parent - raw_code = file_path.open().read() + raw_code = file_path.read_text(encoding='utf-8') # Check if info.json exists, allow overwrite with force if Path(out_path, "info.json").exists() and not cli.args.force: cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', out_path) |