aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk')
-rw-r--r--lib/python/qmk/cli/__init__.py4
-rw-r--r--lib/python/qmk/cli/new/keyboard.py74
-rw-r--r--lib/python/qmk/cli/painter/convert_graphics.py4
-rw-r--r--lib/python/qmk/cli/painter/make_font.py4
-rw-r--r--lib/python/qmk/info.py3
-rw-r--r--lib/python/qmk/painter.py32
6 files changed, 76 insertions, 45 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 0baf19a629..2d63dfb447 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -207,8 +207,8 @@ def _eprint(errmsg):
# Ubuntu 24.04: 3.12
# void: 3.12
-if sys.version_info[0] != 3 or sys.version_info[1] < 7:
- _eprint('Error: Your Python is too old! Please upgrade to Python 3.7 or later.')
+if sys.version_info[0] != 3 or sys.version_info[1] < 9:
+ _eprint('Error: Your Python is too old! Please upgrade to Python 3.9 or later.')
exit(127)
milc_version = __VERSION__.split('.')
diff --git a/lib/python/qmk/cli/new/keyboard.py b/lib/python/qmk/cli/new/keyboard.py
index b84b130f8e..bd02acf9c8 100644
--- a/lib/python/qmk/cli/new/keyboard.py
+++ b/lib/python/qmk/cli/new/keyboard.py
@@ -8,7 +8,7 @@ from pathlib import Path
from dotty_dict import dotty
from milc import cli
-from milc.questions import choice, question
+from milc.questions import choice, question, yesno
from qmk.git import git_get_username
from qmk.json_schema import load_jsonschema
@@ -131,60 +131,70 @@ def _question(*args, **kwargs):
return ret
-def prompt_keyboard():
- prompt = """{fg_yellow}Name Your Keyboard Project{style_reset_all}
-For more infomation, see:
-https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project
+def prompt_heading_subheading(heading, subheading):
+ cli.log.info(f"{{fg_yellow}}{heading}{{style_reset_all}}")
+ cli.log.info(subheading)
+
-Keyboard Name? """
+def prompt_keyboard():
+ prompt_heading_subheading("Name Your Keyboard Project", """For more information, see:
+https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project""")
errmsg = 'Keyboard already exists! Please choose a different name:'
- return _question(prompt, reprompt=errmsg, validate=lambda x: not keyboard(x).exists())
+ return _question("Keyboard Name?", reprompt=errmsg, validate=lambda x: not keyboard(x).exists())
def prompt_user():
- prompt = """
-{fg_yellow}Attribution{style_reset_all}
-Used for maintainer, copyright, etc
+ prompt_heading_subheading("Attribution", "Used for maintainer, copyright, etc.")
-Your GitHub Username? """
- return question(prompt, default=git_get_username())
+ return question("Your GitHub Username?", default=git_get_username())
def prompt_name(def_name):
- prompt = """
-{fg_yellow}More Attribution{style_reset_all}
-Used for maintainer, copyright, etc
+ prompt_heading_subheading("More Attribution", "Used for maintainer, copyright, etc.")
-Your Real Name? """
- return question(prompt, default=def_name)
+ return question("Your Real Name?", default=def_name)
def prompt_layout():
- prompt = """
-{fg_yellow}Pick Base Layout{style_reset_all}
-As a starting point, one of the common layouts can be used to bootstrap the process
+ prompt_heading_subheading("Pick Base Layout", """As a starting point, one of the common layouts can be used to
+bootstrap the process""")
-Default Layout? """
# avoid overwhelming user - remove some?
filtered_layouts = [x for x in available_layouts if not any(xs in x for xs in ['_split', '_blocker', '_tsangan', '_f13'])]
filtered_layouts.append("none of the above")
- return choice(prompt, filtered_layouts, default=len(filtered_layouts) - 1)
+ return choice("Default Layout?", filtered_layouts, default=len(filtered_layouts) - 1)
+
+
+def prompt_mcu_type():
+ prompt_heading_subheading(
+ "What Powers Your Project", """Is your board using a separate development board, such as a Pro Micro,
+or is the microcontroller integrated onto the PCB?
+
+For more information, see:
+https://docs.qmk.fm/compatible_microcontrollers"""
+ )
+
+ return yesno("Using a Development Board?")
+
+
+def prompt_dev_board():
+ prompt_heading_subheading("Select Development Board", """For more information, see:
+https://docs.qmk.fm/compatible_microcontrollers""")
+
+ return choice("Development Board?", dev_boards, default=dev_boards.index("promicro"))
def prompt_mcu():
- prompt = """
-{fg_yellow}What Powers Your Project{style_reset_all}
-For more infomation, see:
-https://docs.qmk.fm/#/compatible_microcontrollers
+ prompt_heading_subheading("Select Microcontroller", """For more information, see:
+https://docs.qmk.fm/compatible_microcontrollers""")
-MCU? """
# remove any options strictly used for compatibility
- filtered_mcu = [x for x in (dev_boards + mcu_types) if not any(xs in x for xs in ['cortex', 'unknown'])]
+ filtered_mcu = [x for x in mcu_types if not any(xs in x for xs in ['cortex', 'unknown'])]
- return choice(prompt, filtered_mcu, default=filtered_mcu.index("atmega32u4"))
+ return choice("Microcontroller?", filtered_mcu, default=filtered_mcu.index("atmega32u4"))
@cli.argument('-kb', '--keyboard', help='Specify the name for the new keyboard directory', arg_only=True, type=keyboard_name)
@@ -211,7 +221,11 @@ def new_keyboard(cli):
user_name = cli.config.new_keyboard.name if cli.config.new_keyboard.name else prompt_user()
real_name = cli.args.realname or cli.config.new_keyboard.name if cli.args.realname or cli.config.new_keyboard.name else prompt_name(user_name)
default_layout = cli.args.layout if cli.args.layout else prompt_layout()
- mcu = cli.args.type if cli.args.type else prompt_mcu()
+
+ if cli.args.type:
+ mcu = cli.args.type
+ else:
+ mcu = prompt_dev_board() if prompt_mcu_type() else prompt_mcu()
config = {}
if mcu in dev_boards:
diff --git a/lib/python/qmk/cli/painter/convert_graphics.py b/lib/python/qmk/cli/painter/convert_graphics.py
index 553c26aa5d..f74d655fd5 100644
--- a/lib/python/qmk/cli/painter/convert_graphics.py
+++ b/lib/python/qmk/cli/painter/convert_graphics.py
@@ -60,9 +60,7 @@ def painter_convert_graphics(cli):
return
# Work out the text substitutions for rendering the output data
- args_str = " ".join((f"--{arg} {getattr(cli.args, arg.replace('-', '_'))}" for arg in ["input", "output", "format", "no-rle", "no-deltas"]))
- command = f"qmk painter-convert-graphics {args_str}"
- subs = generate_subs(cli, out_bytes, image_metadata=metadata, command=command)
+ subs = generate_subs(cli, out_bytes, image_metadata=metadata, command_name="painter_convert_graphics")
# Render and write the header file
header_text = render_header(subs)
diff --git a/lib/python/qmk/cli/painter/make_font.py b/lib/python/qmk/cli/painter/make_font.py
index 19db844931..3e18fd74a5 100644
--- a/lib/python/qmk/cli/painter/make_font.py
+++ b/lib/python/qmk/cli/painter/make_font.py
@@ -61,10 +61,8 @@ def painter_convert_font_image(cli):
return
# Work out the text substitutions for rendering the output data
- args_str = " ".join((f"--{arg} {getattr(cli.args, arg.replace('-', '_'))}" for arg in ["input", "output", "no-ascii", "unicode-glyphs", "format", "no-rle"]))
- command = f"qmk painter-convert-font-image {args_str}"
metadata = {"glyphs": _generate_font_glyphs_list(not cli.args.no_ascii, cli.args.unicode_glyphs)}
- subs = generate_subs(cli, out_bytes, font_metadata=metadata, command=command)
+ subs = generate_subs(cli, out_bytes, font_metadata=metadata, command_name="painter_convert_font_image")
# Render and write the header file
header_text = render_header(subs)
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 82082f5cf0..5dae353538 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -901,9 +901,6 @@ def arm_processor_rules(info_data, rules):
info_data['platform'] = 'STM32'
elif 'MCU_SERIES' in rules:
info_data['platform'] = rules['MCU_SERIES']
- elif 'ARM_ATSAM' in rules:
- info_data['platform'] = 'ARM_ATSAM'
- info_data['platform_key'] = 'arm_atsam'
return info_data
diff --git a/lib/python/qmk/painter.py b/lib/python/qmk/painter.py
index 512a486ce8..ed0372c163 100644
--- a/lib/python/qmk/painter.py
+++ b/lib/python/qmk/painter.py
@@ -3,6 +3,7 @@
import datetime
import math
import re
+from pathlib import Path
from string import Template
from PIL import Image, ImageOps
@@ -137,10 +138,31 @@ def _render_image_metadata(metadata):
return "\n".join(lines)
-def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, command):
+def command_args_str(cli, command_name):
+ """Given a command name, introspect milc to get the arguments passed in."""
+
+ args = {}
+ max_length = 0
+ for arg_name, was_passed in cli.args_passed[command_name].items():
+ max_length = max(max_length, len(arg_name))
+
+ val = getattr(cli.args, arg_name.replace("-", "_"))
+
+ # do not leak full paths, keep just file name
+ if isinstance(val, Path):
+ val = val.name
+
+ args[arg_name] = val
+
+ return "\n".join(f"// {arg_name.ljust(max_length)} | {val}" for arg_name, val in args.items())
+
+
+def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, command_name):
if font_metadata is not None and image_metadata is not None:
raise ValueError("Cant generate subs for font and image at the same time")
+ args = command_args_str(cli, command_name)
+
subs = {
"year": datetime.date.today().strftime("%Y"),
"input_file": cli.args.input.name,
@@ -148,7 +170,8 @@ def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, co
"byte_count": len(out_bytes),
"bytes_lines": render_bytes(out_bytes),
"format": cli.args.format,
- "generator_command": command,
+ "generator_command": command_name.replace("_", "-"),
+ "command_args": args,
}
if font_metadata is not None:
@@ -167,7 +190,7 @@ def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, co
subs.update({
"generated_type": "image",
"var_prefix": "gfx",
- "generator_command": command,
+ "generator_command": command_name,
"metadata": _render_image_metadata(image_metadata),
})
@@ -183,7 +206,8 @@ license_template = """\
// Copyright ${year} QMK -- generated source code only, ${generated_type} retains original copyright
// SPDX-License-Identifier: GPL-2.0-or-later
-// This file was auto-generated by `${generator_command}`
+// This file was auto-generated by `${generator_command}` with arguments:
+${command_args}
"""