From bc67ca6a59ffa3d6e147b276c0544791e5f91d02 Mon Sep 17 00:00:00 2001 From: Zach White Date: Mon, 24 May 2021 19:38:27 -0700 Subject: [PATCH 001/274] search for the readme in higher directories as well (#12997) --- lib/python/qmk/cli/generate/api.py | 6 +++--- lib/python/qmk/keyboard.py | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py index 8ab7522a76..285bd90eb5 100755 --- a/lib/python/qmk/cli/generate/api.py +++ b/lib/python/qmk/cli/generate/api.py @@ -10,7 +10,7 @@ from qmk.datetime import current_datetime from qmk.info import info_json from qmk.json_encoders import InfoJSONEncoder from qmk.json_schema import json_load -from qmk.keyboard import list_keyboards +from qmk.keyboard import find_readme, list_keyboards @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") @@ -38,7 +38,7 @@ def generate_api(cli): keyboard_dir = v1_dir / 'keyboards' / keyboard_name keyboard_info = keyboard_dir / 'info.json' keyboard_readme = keyboard_dir / 'readme.md' - keyboard_readme_src = Path('keyboards') / keyboard_name / 'readme.md' + keyboard_readme_src = find_readme(keyboard_name) keyboard_dir.mkdir(parents=True, exist_ok=True) keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) @@ -46,7 +46,7 @@ def generate_api(cli): keyboard_info.write_text(keyboard_json) cli.log.debug('Wrote file %s', keyboard_info) - if keyboard_readme_src.exists(): + if keyboard_readme_src: copyfile(keyboard_readme_src, keyboard_readme) cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index e457685567..06c9df874f 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py @@ -6,10 +6,10 @@ from pathlib import Path import os from glob import glob +import qmk.path from qmk.c_parse import parse_config_h_file from qmk.json_schema import json_load from qmk.makefile import parse_rules_mk_file -from qmk.path import is_keyboard, under_qmk_firmware BOX_DRAWING_CHARACTERS = { "unicode": { @@ -36,7 +36,7 @@ base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep def find_keyboard_from_dir(): """Returns a keyboard name based on the user's current directory. """ - relative_cwd = under_qmk_firmware() + relative_cwd = qmk.path.under_qmk_firmware() if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards': # Attempt to extract the keyboard name from the current directory @@ -47,10 +47,23 @@ def find_keyboard_from_dir(): keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 current_path = current_path.parents[keymap_index] - if is_keyboard(current_path): + if qmk.path.is_keyboard(current_path): return str(current_path) +def find_readme(keyboard): + """Returns the readme for this keyboard. + """ + cur_dir = qmk.path.keyboard(keyboard) + keyboards_dir = Path('keyboards') + while not (cur_dir / 'readme.md').exists(): + if cur_dir == keyboards_dir: + return None + cur_dir = cur_dir.parent + + return cur_dir / 'readme.md' + + def keyboard_folder(keyboard): """Returns the actual keyboard folder. @@ -67,7 +80,7 @@ def keyboard_folder(keyboard): rules_mk = parse_rules_mk_file(rules_mk_file) keyboard = rules_mk.get('DEFAULT_FOLDER', keyboard) - if not is_keyboard(keyboard): + if not qmk.path.is_keyboard(keyboard): raise ValueError(f'Invalid keyboard: {keyboard}') return keyboard From aa97f52963f3da6aa112093d357296e62bfa5452 Mon Sep 17 00:00:00 2001 From: Zach White Date: Mon, 24 May 2021 23:36:38 -0700 Subject: [PATCH 002/274] Use milc.subcommand.config instead of qmk.cli.config (#13002) * Use milc.subcommand.config instead * pyformat * remove the config test --- lib/python/qmk/cli/__init__.py | 2 +- lib/python/qmk/cli/config.py | 116 ---------------------- lib/python/qmk/tests/test_cli_commands.py | 6 -- 3 files changed, 1 insertion(+), 123 deletions(-) delete mode 100644 lib/python/qmk/cli/config.py diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 6fe769fe7b..be5ba90ad7 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py @@ -140,7 +140,7 @@ from . import cformat # noqa from . import chibios # noqa from . import clean # noqa from . import compile # noqa -from . import config # noqa +from milc.subcommand import config # noqa from . import docs # noqa from . import doctor # noqa from . import fileformat # noqa diff --git a/lib/python/qmk/cli/config.py b/lib/python/qmk/cli/config.py deleted file mode 100644 index e17d8bb9ba..0000000000 --- a/lib/python/qmk/cli/config.py +++ /dev/null @@ -1,116 +0,0 @@ -"""Read and write configuration settings -""" -from milc import cli - - -def print_config(section, key): - """Print a single config setting to stdout. - """ - cli.echo('%s.%s{fg_cyan}={fg_reset}%s', section, key, cli.config[section][key]) - - -def show_config(): - """Print the current configuration to stdout. - """ - for section in cli.config: - for key in cli.config[section]: - print_config(section, key) - - -def parse_config_token(config_token): - """Split a user-supplied configuration-token into its components. - """ - section = option = value = None - - if '=' in config_token and '.' not in config_token: - cli.log.error('Invalid configuration token, the key must be of the form
.