diff options
author | skullydazed <skullydazed@users.noreply.github.com> | 2020-04-18 13:00:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 22:00:56 +0200 |
commit | 66d94dc22af4fccae2af073c512662ce7eba7d98 (patch) | |
tree | a720968b0f1951cc2ec920da373701d308f04d88 /lib/python/qmk | |
parent | 5a8f59503e41923030249561e9ef56be62de3efa (diff) | |
download | qmk_firmware-66d94dc22af4fccae2af073c512662ce7eba7d98.tar.gz qmk_firmware-66d94dc22af4fccae2af073c512662ce7eba7d98.zip |
Move everything to Python 3.6 (#8835)
Diffstat (limited to 'lib/python/qmk')
-rw-r--r-- | lib/python/qmk/cli/__init__.py | 7 | ||||
-rw-r--r-- | lib/python/qmk/cli/cformat.py | 5 | ||||
-rwxr-xr-x | lib/python/qmk/cli/doctor.py | 11 | ||||
-rwxr-xr-x | lib/python/qmk/cli/json2c.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/kle2json.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/new/keymap.py | 2 | ||||
-rw-r--r-- | lib/python/qmk/keymap.py | 5 |
7 files changed, 22 insertions, 24 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index eb524217c..394a1353b 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. | 3 | We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. |
4 | """ | 4 | """ |
5 | import sys | ||
6 | |||
5 | from milc import cli | 7 | from milc import cli |
6 | 8 | ||
7 | from . import cformat | 9 | from . import cformat |
@@ -19,5 +21,6 @@ from . import new | |||
19 | from . import pyformat | 21 | from . import pyformat |
20 | from . import pytest | 22 | from . import pytest |
21 | 23 | ||
22 | if not hasattr(cli, 'config_source'): | 24 | if sys.version_info[0] != 3 or sys.version_info[1] < 6: |
23 | cli.log.warning("Your QMK CLI is out of date. Please upgrade with `pip3 install --upgrade qmk` or by using your package manager.") | 25 | cli.log.error('Your Python is too old! Please upgrade to Python 3.6 or later.') |
26 | exit(127) | ||
diff --git a/lib/python/qmk/cli/cformat.py b/lib/python/qmk/cli/cformat.py index 536ee30fd..0cd8b6192 100644 --- a/lib/python/qmk/cli/cformat.py +++ b/lib/python/qmk/cli/cformat.py | |||
@@ -22,9 +22,8 @@ def cformat_run(files, all_files): | |||
22 | cli.log.warn('No changes detected. Use "qmk cformat -a" to format all files') | 22 | cli.log.warn('No changes detected. Use "qmk cformat -a" to format all files') |
23 | return False | 23 | return False |
24 | if files and all_files: | 24 | if files and all_files: |
25 | cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(cli.args.files)) | 25 | cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(files)) |
26 | # 3.6+: Can remove the str casting, python will cast implicitly | 26 | subprocess.run(clang_format + [file for file in files], check=True) |
27 | subprocess.run(clang_format + [str(file) for file in files], check=True) | ||
28 | cli.log.info('Successfully formatted the C code.') | 27 | cli.log.info('Successfully formatted the C code.') |
29 | 28 | ||
30 | except subprocess.CalledProcessError: | 29 | except subprocess.CalledProcessError: |
diff --git a/lib/python/qmk/cli/doctor.py b/lib/python/qmk/cli/doctor.py index 3c74fae69..3c4624837 100755 --- a/lib/python/qmk/cli/doctor.py +++ b/lib/python/qmk/cli/doctor.py | |||
@@ -135,16 +135,15 @@ def check_udev_rules(): | |||
135 | } | 135 | } |
136 | 136 | ||
137 | if udev_dir.exists(): | 137 | if udev_dir.exists(): |
138 | udev_rules = [str(rule_file) for rule_file in udev_dir.glob('*.rules')] | 138 | udev_rules = [rule_file for rule_file in udev_dir.glob('*.rules')] |
139 | current_rules = set() | 139 | current_rules = set() |
140 | 140 | ||
141 | # Collect all rules from the config files | 141 | # Collect all rules from the config files |
142 | for rule_file in udev_rules: | 142 | for rule_file in udev_rules: |
143 | with open(rule_file, "r") as fd: | 143 | for line in rule_file.read_text().split('\n'): |
144 | for line in fd.readlines(): | 144 | line = line.strip() |
145 | line = line.strip() | 145 | if not line.startswith("#") and len(line): |
146 | if not line.startswith("#") and len(line): | 146 | current_rules.add(line) |
147 | current_rules.add(line) | ||
148 | 147 | ||
149 | # Check if the desired rules are among the currently present rules | 148 | # Check if the desired rules are among the currently present rules |
150 | for bootloader, rules in desired_rules.items(): | 149 | for bootloader, rules in desired_rules.items(): |
diff --git a/lib/python/qmk/cli/json2c.py b/lib/python/qmk/cli/json2c.py index 46c4d04bb..521840507 100755 --- a/lib/python/qmk/cli/json2c.py +++ b/lib/python/qmk/cli/json2c.py | |||
@@ -10,29 +10,27 @@ import qmk.path | |||
10 | 10 | ||
11 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') | 11 | @cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to') |
12 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | 12 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") |
13 | @cli.argument('filename', arg_only=True, help='Configurator JSON file') | 13 | @cli.argument('filename', type=qmk.path.normpath, arg_only=True, help='Configurator JSON file') |
14 | @cli.subcommand('Creates a keymap.c from a QMK Configurator export.') | 14 | @cli.subcommand('Creates a keymap.c from a QMK Configurator export.') |
15 | def json2c(cli): | 15 | def json2c(cli): |
16 | """Generate a keymap.c from a configurator export. | 16 | """Generate a keymap.c from a configurator export. |
17 | 17 | ||
18 | This command uses the `qmk.keymap` module to generate a keymap.c from a configurator export. The generated keymap is written to stdout, or to a file if -o is provided. | 18 | This command uses the `qmk.keymap` module to generate a keymap.c from a configurator export. The generated keymap is written to stdout, or to a file if -o is provided. |
19 | """ | 19 | """ |
20 | cli.args.filename = qmk.path.normpath(cli.args.filename) | ||
21 | |||
22 | # Error checking | 20 | # Error checking |
23 | if not cli.args.filename.exists(): | 21 | if not cli.args.filename.exists(): |
24 | cli.log.error('JSON file does not exist!') | 22 | cli.log.error('JSON file does not exist!') |
25 | cli.print_usage() | 23 | cli.print_usage() |
26 | exit(1) | 24 | exit(1) |
27 | 25 | ||
28 | if str(cli.args.filename) == '-': | 26 | if cli.args.filename.name == '-': |
29 | # TODO(skullydazed/anyone): Read file contents from STDIN | 27 | # TODO(skullydazed/anyone): Read file contents from STDIN |
30 | cli.log.error('Reading from STDIN is not (yet) supported.') | 28 | cli.log.error('Reading from STDIN is not (yet) supported.') |
31 | cli.print_usage() | 29 | cli.print_usage() |
32 | exit(1) | 30 | exit(1) |
33 | 31 | ||
34 | # Environment processing | 32 | # Environment processing |
35 | if cli.args.output == ('-'): | 33 | if cli.args.output.name == ('-'): |
36 | cli.args.output = None | 34 | cli.args.output = None |
37 | 35 | ||
38 | # Parse the configurator json | 36 | # Parse the configurator json |
diff --git a/lib/python/qmk/cli/kle2json.py b/lib/python/qmk/cli/kle2json.py index 3ed6594e0..5268462f9 100755 --- a/lib/python/qmk/cli/kle2json.py +++ b/lib/python/qmk/cli/kle2json.py | |||
@@ -37,12 +37,12 @@ def kle2json(cli): | |||
37 | file_path = Path(os.environ['ORIG_CWD'], cli.args.filename) | 37 | file_path = Path(os.environ['ORIG_CWD'], cli.args.filename) |
38 | # Check for valid file_path for more graceful failure | 38 | # Check for valid file_path for more graceful failure |
39 | if not file_path.exists(): | 39 | if not file_path.exists(): |
40 | return cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', str(file_path)) | 40 | return cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path) |
41 | out_path = file_path.parent | 41 | out_path = file_path.parent |
42 | raw_code = file_path.open().read() | 42 | raw_code = file_path.open().read() |
43 | # Check if info.json exists, allow overwrite with force | 43 | # Check if info.json exists, allow overwrite with force |
44 | if Path(out_path, "info.json").exists() and not cli.args.force: | 44 | if Path(out_path, "info.json").exists() and not cli.args.force: |
45 | cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', str(out_path)) | 45 | cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', out_path) |
46 | return False | 46 | return False |
47 | try: | 47 | try: |
48 | # Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed) | 48 | # Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed) |
@@ -69,7 +69,7 @@ def kle2json(cli): | |||
69 | # Replace layout in keyboard json | 69 | # Replace layout in keyboard json |
70 | keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout) | 70 | keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout) |
71 | # Write our info.json | 71 | # Write our info.json |
72 | file = open(str(out_path) + "/info.json", "w") | 72 | file = open(out_path + "/info.json", "w") |
73 | file.write(keyboard) | 73 | file.write(keyboard) |
74 | file.close() | 74 | file.close() |
75 | cli.log.info('Wrote out {fg_cyan}%s/info.json', str(out_path)) | 75 | cli.log.info('Wrote out {fg_cyan}%s/info.json', out_path) |
diff --git a/lib/python/qmk/cli/new/keymap.py b/lib/python/qmk/cli/new/keymap.py index 5ae262856..474fe7974 100755 --- a/lib/python/qmk/cli/new/keymap.py +++ b/lib/python/qmk/cli/new/keymap.py | |||
@@ -40,7 +40,7 @@ def new_keymap(cli): | |||
40 | exit(1) | 40 | exit(1) |
41 | 41 | ||
42 | # create user directory with default keymap files | 42 | # create user directory with default keymap files |
43 | shutil.copytree(str(keymap_path_default), str(keymap_path_new), symlinks=True) | 43 | shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True) |
44 | 44 | ||
45 | # end message to user | 45 | # end message to user |
46 | cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new) | 46 | cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new) |
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py index 4aa87de20..69cdc8d5b 100644 --- a/lib/python/qmk/keymap.py +++ b/lib/python/qmk/keymap.py | |||
@@ -1,6 +1,5 @@ | |||
1 | """Functions that help you work with QMK keymaps. | 1 | """Functions that help you work with QMK keymaps. |
2 | """ | 2 | """ |
3 | import os | ||
4 | from pathlib import Path | 3 | from pathlib import Path |
5 | 4 | ||
6 | import qmk.path | 5 | import qmk.path |
@@ -127,7 +126,7 @@ def list_keymaps(keyboard_name): | |||
127 | while kb_path != keyboards_dir: | 126 | while kb_path != keyboards_dir: |
128 | keymaps_dir = kb_path / "keymaps" | 127 | keymaps_dir = kb_path / "keymaps" |
129 | if keymaps_dir.exists(): | 128 | if keymaps_dir.exists(): |
130 | names = names.union([keymap for keymap in os.listdir(str(keymaps_dir)) if (keymaps_dir / keymap / "keymap.c").is_file()]) | 129 | names = names.union([keymap for keymap in keymaps_dir.iterdir() if (keymaps_dir / keymap / "keymap.c").is_file()]) |
131 | kb_path = kb_path.parent | 130 | kb_path = kb_path.parent |
132 | 131 | ||
133 | # if community layouts are supported, get them | 132 | # if community layouts are supported, get them |
@@ -135,6 +134,6 @@ def list_keymaps(keyboard_name): | |||
135 | for layout in rules_mk["LAYOUTS"].split(): | 134 | for layout in rules_mk["LAYOUTS"].split(): |
136 | cl_path = Path.cwd() / "layouts" / "community" / layout | 135 | cl_path = Path.cwd() / "layouts" / "community" / layout |
137 | if cl_path.exists(): | 136 | if cl_path.exists(): |
138 | names = names.union([keymap for keymap in os.listdir(str(cl_path)) if (cl_path / keymap / "keymap.c").is_file()]) | 137 | names = names.union([keymap for keymap in cl_path.iterdir() if (cl_path / keymap / "keymap.c").is_file()]) |
139 | 138 | ||
140 | return sorted(names) | 139 | return sorted(names) |