Move everything to Python 3.6 (#8835)
This commit is contained in:
committed by
Florian Didron
parent
d424a716a0
commit
1dfe06affc
2
bin/qmk
2
bin/qmk
@@ -35,7 +35,7 @@ def _check_modules(requirements):
|
|||||||
|
|
||||||
if not find_spec(module['import']):
|
if not find_spec(module['import']):
|
||||||
print('Could not find module %s!' % module['name'])
|
print('Could not find module %s!' % module['name'])
|
||||||
print('Please run `python3 -m pip install -r %s` to install required python dependencies.' % str(qmk_dir / requirements))
|
print('Please run `python3 -m pip install -r %s` to install required python dependencies.' % (qmk_dir / requirements,))
|
||||||
if developer:
|
if developer:
|
||||||
print('You can also turn off developer mode: qmk config user.developer=None')
|
print('You can also turn off developer mode: qmk config user.developer=None')
|
||||||
print()
|
print()
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
|
We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from . import cformat
|
from . import cformat
|
||||||
@@ -18,5 +20,6 @@ from . import new
|
|||||||
from . import pyformat
|
from . import pyformat
|
||||||
from . import pytest
|
from . import pytest
|
||||||
|
|
||||||
if not hasattr(cli, 'config_source'):
|
if sys.version_info[0] != 3 or sys.version_info[1] < 6:
|
||||||
cli.log.warning("Your QMK CLI is out of date. Please upgrade with `pip3 install --upgrade qmk` or by using your package manager.")
|
cli.log.error('Your Python is too old! Please upgrade to Python 3.6 or later.')
|
||||||
|
exit(127)
|
||||||
|
|||||||
@@ -22,9 +22,8 @@ def cformat_run(files, all_files):
|
|||||||
cli.log.warn('No changes detected. Use "qmk cformat -a" to format all files')
|
cli.log.warn('No changes detected. Use "qmk cformat -a" to format all files')
|
||||||
return False
|
return False
|
||||||
if files and all_files:
|
if files and all_files:
|
||||||
cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(cli.args.files))
|
cli.log.warning('Filenames passed with -a, only formatting: %s', ','.join(files))
|
||||||
# 3.6+: Can remove the str casting, python will cast implicitly
|
subprocess.run(clang_format + [file for file in files], check=True)
|
||||||
subprocess.run(clang_format + [str(file) for file in files], check=True)
|
|
||||||
cli.log.info('Successfully formatted the C code.')
|
cli.log.info('Successfully formatted the C code.')
|
||||||
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
|
|||||||
@@ -135,16 +135,15 @@ def check_udev_rules():
|
|||||||
}
|
}
|
||||||
|
|
||||||
if udev_dir.exists():
|
if udev_dir.exists():
|
||||||
udev_rules = [str(rule_file) for rule_file in udev_dir.glob('*.rules')]
|
udev_rules = [rule_file for rule_file in udev_dir.glob('*.rules')]
|
||||||
current_rules = set()
|
current_rules = set()
|
||||||
|
|
||||||
# Collect all rules from the config files
|
# Collect all rules from the config files
|
||||||
for rule_file in udev_rules:
|
for rule_file in udev_rules:
|
||||||
with open(rule_file, "r") as fd:
|
for line in rule_file.read_text().split('\n'):
|
||||||
for line in fd.readlines():
|
line = line.strip()
|
||||||
line = line.strip()
|
if not line.startswith("#") and len(line):
|
||||||
if not line.startswith("#") and len(line):
|
current_rules.add(line)
|
||||||
current_rules.add(line)
|
|
||||||
|
|
||||||
# Check if the desired rules are among the currently present rules
|
# Check if the desired rules are among the currently present rules
|
||||||
for bootloader, rules in desired_rules.items():
|
for bootloader, rules in desired_rules.items():
|
||||||
|
|||||||
@@ -10,29 +10,27 @@ import qmk.path
|
|||||||
|
|
||||||
@cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to')
|
@cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to')
|
||||||
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
|
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
|
||||||
@cli.argument('filename', arg_only=True, help='Configurator JSON file')
|
@cli.argument('filename', type=qmk.path.normpath, arg_only=True, help='Configurator JSON file')
|
||||||
@cli.subcommand('Creates a keymap.c from a QMK Configurator export.')
|
@cli.subcommand('Creates a keymap.c from a QMK Configurator export.')
|
||||||
def json2c(cli):
|
def json2c(cli):
|
||||||
"""Generate a keymap.c from a configurator export.
|
"""Generate a keymap.c from a configurator export.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
"""
|
"""
|
||||||
cli.args.filename = qmk.path.normpath(cli.args.filename)
|
|
||||||
|
|
||||||
# Error checking
|
# Error checking
|
||||||
if not cli.args.filename.exists():
|
if not cli.args.filename.exists():
|
||||||
cli.log.error('JSON file does not exist!')
|
cli.log.error('JSON file does not exist!')
|
||||||
cli.print_usage()
|
cli.print_usage()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if str(cli.args.filename) == '-':
|
if cli.args.filename.name == '-':
|
||||||
# TODO(skullydazed/anyone): Read file contents from STDIN
|
# TODO(skullydazed/anyone): Read file contents from STDIN
|
||||||
cli.log.error('Reading from STDIN is not (yet) supported.')
|
cli.log.error('Reading from STDIN is not (yet) supported.')
|
||||||
cli.print_usage()
|
cli.print_usage()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Environment processing
|
# Environment processing
|
||||||
if cli.args.output == ('-'):
|
if cli.args.output.name == ('-'):
|
||||||
cli.args.output = None
|
cli.args.output = None
|
||||||
|
|
||||||
# Parse the configurator json
|
# Parse the configurator json
|
||||||
|
|||||||
@@ -37,12 +37,12 @@ def kle2json(cli):
|
|||||||
file_path = Path(os.environ['ORIG_CWD'], cli.args.filename)
|
file_path = Path(os.environ['ORIG_CWD'], cli.args.filename)
|
||||||
# Check for valid file_path for more graceful failure
|
# Check for valid file_path for more graceful failure
|
||||||
if not file_path.exists():
|
if not file_path.exists():
|
||||||
return cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', str(file_path))
|
return cli.log.error('File {fg_cyan}%s{style_reset_all} was not found.', file_path)
|
||||||
out_path = file_path.parent
|
out_path = file_path.parent
|
||||||
raw_code = file_path.open().read()
|
raw_code = file_path.open().read()
|
||||||
# Check if info.json exists, allow overwrite with force
|
# Check if info.json exists, allow overwrite with force
|
||||||
if Path(out_path, "info.json").exists() and not cli.args.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.', str(out_path))
|
cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', out_path)
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
# Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed)
|
# Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed)
|
||||||
@@ -69,7 +69,7 @@ def kle2json(cli):
|
|||||||
# Replace layout in keyboard json
|
# Replace layout in keyboard json
|
||||||
keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout)
|
keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout)
|
||||||
# Write our info.json
|
# Write our info.json
|
||||||
file = open(str(out_path) + "/info.json", "w")
|
file = open(out_path + "/info.json", "w")
|
||||||
file.write(keyboard)
|
file.write(keyboard)
|
||||||
file.close()
|
file.close()
|
||||||
cli.log.info('Wrote out {fg_cyan}%s/info.json', str(out_path))
|
cli.log.info('Wrote out {fg_cyan}%s/info.json', out_path)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def new_keymap(cli):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# create user directory with default keymap files
|
# create user directory with default keymap files
|
||||||
shutil.copytree(str(keymap_path_default), str(keymap_path_new), symlinks=True)
|
shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
|
||||||
|
|
||||||
# end message to user
|
# end message to user
|
||||||
cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new)
|
cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"""Functions that help you work with QMK keymaps.
|
"""Functions that help you work with QMK keymaps.
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import qmk.path
|
import qmk.path
|
||||||
@@ -127,7 +126,7 @@ def list_keymaps(keyboard_name):
|
|||||||
while kb_path != keyboards_dir:
|
while kb_path != keyboards_dir:
|
||||||
keymaps_dir = kb_path / "keymaps"
|
keymaps_dir = kb_path / "keymaps"
|
||||||
if keymaps_dir.exists():
|
if keymaps_dir.exists():
|
||||||
names = names.union([keymap for keymap in os.listdir(str(keymaps_dir)) if (keymaps_dir / keymap / "keymap.c").is_file()])
|
names = names.union([keymap for keymap in keymaps_dir.iterdir() if (keymaps_dir / keymap / "keymap.c").is_file()])
|
||||||
kb_path = kb_path.parent
|
kb_path = kb_path.parent
|
||||||
|
|
||||||
# if community layouts are supported, get them
|
# if community layouts are supported, get them
|
||||||
@@ -135,6 +134,6 @@ def list_keymaps(keyboard_name):
|
|||||||
for layout in rules_mk["LAYOUTS"].split():
|
for layout in rules_mk["LAYOUTS"].split():
|
||||||
cl_path = Path.cwd() / "layouts" / "community" / layout
|
cl_path = Path.cwd() / "layouts" / "community" / layout
|
||||||
if cl_path.exists():
|
if cl_path.exists():
|
||||||
names = names.union([keymap for keymap in os.listdir(str(cl_path)) if (cl_path / keymap / "keymap.c").is_file()])
|
names = names.union([keymap for keymap in cl_path.iterdir() if (cl_path / keymap / "keymap.c").is_file()])
|
||||||
|
|
||||||
return sorted(names)
|
return sorted(names)
|
||||||
|
|||||||
Reference in New Issue
Block a user