aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
authorskullydazed <skullydazed@users.noreply.github.com>2020-04-18 13:00:56 -0700
committerGitHub <noreply@github.com>2020-04-18 22:00:56 +0200
commit66d94dc22af4fccae2af073c512662ce7eba7d98 (patch)
treea720968b0f1951cc2ec920da373701d308f04d88 /lib/python/qmk/cli
parent5a8f59503e41923030249561e9ef56be62de3efa (diff)
downloadqmk_firmware-66d94dc22af4fccae2af073c512662ce7eba7d98.tar.gz
qmk_firmware-66d94dc22af4fccae2af073c512662ce7eba7d98.zip
Move everything to Python 3.6 (#8835)
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/__init__.py7
-rw-r--r--lib/python/qmk/cli/cformat.py5
-rwxr-xr-xlib/python/qmk/cli/doctor.py11
-rwxr-xr-xlib/python/qmk/cli/json2c.py8
-rwxr-xr-xlib/python/qmk/cli/kle2json.py8
-rwxr-xr-xlib/python/qmk/cli/new/keymap.py2
6 files changed, 20 insertions, 21 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
3We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. 3We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
4""" 4"""
5import sys
6
5from milc import cli 7from milc import cli
6 8
7from . import cformat 9from . import cformat
@@ -19,5 +21,6 @@ from . import new
19from . import pyformat 21from . import pyformat
20from . import pytest 22from . import pytest
21 23
22if not hasattr(cli, 'config_source'): 24if 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.')
15def json2c(cli): 15def 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)