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) | |
download | qmk_firmware-1581ea48dcd48d0d3f42cc09b388c468aedec45d.tar.gz qmk_firmware-1581ea48dcd48d0d3f42cc09b388c468aedec45d.zip |
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 3e348b2b0..89995931a 100644 --- a/lib/python/qmk/cli/chibios/confmigrate.py +++ b/lib/python/qmk/cli/chibios/confmigrate.py | |||
@@ -40,7 +40,7 @@ file_header = """\ | |||
40 | 40 | ||
41 | 41 | ||
42 | def collect_defines(filepath): | 42 | def collect_defines(filepath): |
43 | with open(filepath, 'r') as f: | 43 | with open(filepath, 'r', encoding='utf-8') as f: |
44 | content = f.read() | 44 | content = f.read() |
45 | define_search = re.compile(r'(?m)^#\s*define\s+(?:.*\\\r?\n)*.*$', re.MULTILINE) | 45 | define_search = re.compile(r'(?m)^#\s*define\s+(?:.*\\\r?\n)*.*$', re.MULTILINE) |
46 | value_search = re.compile(r'^#\s*define\s+(?P<name>[a-zA-Z0-9_]+(\([^\)]*\))?)\s*(?P<value>.*)', re.DOTALL) | 46 | 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): | |||
146 | 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): | 146 | 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): |
147 | migrate_chconf_h(to_override, outfile=sys.stdout) | 147 | migrate_chconf_h(to_override, outfile=sys.stdout) |
148 | if cli.args.overwrite: | 148 | if cli.args.overwrite: |
149 | with open(cli.args.input, "w") as out_file: | 149 | with open(cli.args.input, "w", encoding='utf-8') as out_file: |
150 | migrate_chconf_h(to_override, outfile=out_file) | 150 | migrate_chconf_h(to_override, outfile=out_file) |
151 | 151 | ||
152 | 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): | 152 | 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): |
153 | migrate_halconf_h(to_override, outfile=sys.stdout) | 153 | migrate_halconf_h(to_override, outfile=sys.stdout) |
154 | if cli.args.overwrite: | 154 | if cli.args.overwrite: |
155 | with open(cli.args.input, "w") as out_file: | 155 | with open(cli.args.input, "w", encoding='utf-8') as out_file: |
156 | migrate_halconf_h(to_override, outfile=out_file) | 156 | migrate_halconf_h(to_override, outfile=out_file) |
157 | 157 | ||
158 | 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): | 158 | 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): |
159 | migrate_mcuconf_h(to_override, outfile=sys.stdout) | 159 | migrate_mcuconf_h(to_override, outfile=sys.stdout) |
160 | if cli.args.overwrite: | 160 | if cli.args.overwrite: |
161 | with open(cli.args.input, "w") as out_file: | 161 | with open(cli.args.input, "w", encoding='utf-8') as out_file: |
162 | migrate_mcuconf_h(to_override, outfile=out_file) | 162 | 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 b7baae065..15b289522 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): | |||
82 | layouts_h_lines.append(rows) | 82 | layouts_h_lines.append(rows) |
83 | layouts_h_lines.append('}') | 83 | layouts_h_lines.append('}') |
84 | 84 | ||
85 | for alias, target in kb_info_json.get('layout_aliases', {}).items(): | ||
86 | layouts_h_lines.append('') | ||
87 | layouts_h_lines.append('#define %s %s' % (alias, target)) | ||
88 | |||
85 | # Show the results | 89 | # Show the results |
86 | layouts_h = '\n'.join(layouts_h_lines) + '\n' | 90 | layouts_h = '\n'.join(layouts_h_lines) + '\n' |
87 | 91 | ||
diff --git a/lib/python/qmk/cli/info.py b/lib/python/qmk/cli/info.py index 87d7253d4..a7ce8abf0 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): | |||
29 | else: | 29 | else: |
30 | cli.echo('{fg_blue}keymap_%s{fg_reset}:', cli.config.info.keymap) | 30 | cli.echo('{fg_blue}keymap_%s{fg_reset}:', cli.config.info.keymap) |
31 | 31 | ||
32 | keymap_data = json.load(keymap_path.open()) | 32 | keymap_data = json.load(keymap_path.open(encoding='utf-8')) |
33 | layout_name = keymap_data['layout'] | 33 | layout_name = keymap_data['layout'] |
34 | 34 | ||
35 | for layer_num, layer in enumerate(keymap_data['layers']): | 35 | for layer_num, layer in enumerate(keymap_data['layers']): |
@@ -57,7 +57,7 @@ def show_matrix(kb_info_json, title_caps=True): | |||
57 | # Build our label list | 57 | # Build our label list |
58 | labels = [] | 58 | labels = [] |
59 | for key in layout['layout']: | 59 | for key in layout['layout']: |
60 | if key['matrix']: | 60 | if 'matrix' in key: |
61 | row = ROW_LETTERS[key['matrix'][0]] | 61 | row = ROW_LETTERS[key['matrix'][0]] |
62 | col = COL_LETTERS[key['matrix'][1]] | 62 | col = COL_LETTERS[key['matrix'][1]] |
63 | 63 | ||
@@ -91,6 +91,9 @@ def print_friendly_output(kb_info_json): | |||
91 | cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height'])) | 91 | cli.echo('{fg_blue}Size{fg_reset}: %s x %s' % (kb_info_json['width'], kb_info_json['height'])) |
92 | cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) | 92 | cli.echo('{fg_blue}Processor{fg_reset}: %s', kb_info_json.get('processor', 'Unknown')) |
93 | cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) | 93 | cli.echo('{fg_blue}Bootloader{fg_reset}: %s', kb_info_json.get('bootloader', 'Unknown')) |
94 | if 'layout_aliases' in kb_info_json: | ||
95 | aliases = [f'{key}={value}' for key, value in kb_info_json['layout_aliases'].items()] | ||
96 | cli.echo('{fg_blue}Layout aliases:{fg_reset} %s' % (', '.join(aliases),)) | ||
94 | 97 | ||
95 | if cli.config.info.layouts: | 98 | if cli.config.info.layouts: |
96 | show_layouts(kb_info_json, True) | 99 | show_layouts(kb_info_json, True) |
diff --git a/lib/python/qmk/cli/kle2json.py b/lib/python/qmk/cli/kle2json.py index 66d504bfc..3bb744358 100755 --- a/lib/python/qmk/cli/kle2json.py +++ b/lib/python/qmk/cli/kle2json.py | |||
@@ -27,7 +27,7 @@ def kle2json(cli): | |||
27 | cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) | 27 | cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) |
28 | return False | 28 | return False |
29 | out_path = file_path.parent | 29 | out_path = file_path.parent |
30 | raw_code = file_path.open().read() | 30 | raw_code = file_path.read_text(encoding='utf-8') |
31 | # Check if info.json exists, allow overwrite with force | 31 | # Check if info.json exists, allow overwrite with force |
32 | if Path(out_path, "info.json").exists() and not cli.args.force: | 32 | if Path(out_path, "info.json").exists() and not cli.args.force: |
33 | cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', out_path) | 33 | cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', out_path) |