diff options
author | Zach White <skullydazed@gmail.com> | 2021-05-24 19:38:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-24 19:38:27 -0700 |
commit | bc67ca6a59ffa3d6e147b276c0544791e5f91d02 (patch) | |
tree | ac9dcf5a9de256c2d2d87b9a3b7549f1faed76f1 | |
parent | bbe453599f0ffde73e2386354f30d8b38e3b4b13 (diff) | |
download | qmk_firmware-bc67ca6a59ffa3d6e147b276c0544791e5f91d02.tar.gz qmk_firmware-bc67ca6a59ffa3d6e147b276c0544791e5f91d02.zip |
search for the readme in higher directories as well (#12997)
-rwxr-xr-x | lib/python/qmk/cli/generate/api.py | 6 | ||||
-rw-r--r-- | 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 8ab7522a7..285bd90eb 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 | |||
10 | from qmk.info import info_json | 10 | from qmk.info import info_json |
11 | from qmk.json_encoders import InfoJSONEncoder | 11 | from qmk.json_encoders import InfoJSONEncoder |
12 | from qmk.json_schema import json_load | 12 | from qmk.json_schema import json_load |
13 | from qmk.keyboard import list_keyboards | 13 | from qmk.keyboard import find_readme, list_keyboards |
14 | 14 | ||
15 | 15 | ||
16 | @cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.") | 16 | @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): | |||
38 | keyboard_dir = v1_dir / 'keyboards' / keyboard_name | 38 | keyboard_dir = v1_dir / 'keyboards' / keyboard_name |
39 | keyboard_info = keyboard_dir / 'info.json' | 39 | keyboard_info = keyboard_dir / 'info.json' |
40 | keyboard_readme = keyboard_dir / 'readme.md' | 40 | keyboard_readme = keyboard_dir / 'readme.md' |
41 | keyboard_readme_src = Path('keyboards') / keyboard_name / 'readme.md' | 41 | keyboard_readme_src = find_readme(keyboard_name) |
42 | 42 | ||
43 | keyboard_dir.mkdir(parents=True, exist_ok=True) | 43 | keyboard_dir.mkdir(parents=True, exist_ok=True) |
44 | keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) | 44 | keyboard_json = json.dumps({'last_updated': current_datetime(), 'keyboards': {keyboard_name: kb_all[keyboard_name]}}) |
@@ -46,7 +46,7 @@ def generate_api(cli): | |||
46 | keyboard_info.write_text(keyboard_json) | 46 | keyboard_info.write_text(keyboard_json) |
47 | cli.log.debug('Wrote file %s', keyboard_info) | 47 | cli.log.debug('Wrote file %s', keyboard_info) |
48 | 48 | ||
49 | if keyboard_readme_src.exists(): | 49 | if keyboard_readme_src: |
50 | copyfile(keyboard_readme_src, keyboard_readme) | 50 | copyfile(keyboard_readme_src, keyboard_readme) |
51 | cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) | 51 | cli.log.debug('Copied %s -> %s', keyboard_readme_src, keyboard_readme) |
52 | 52 | ||
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py index e45768556..06c9df874 100644 --- a/lib/python/qmk/keyboard.py +++ b/lib/python/qmk/keyboard.py | |||
@@ -6,10 +6,10 @@ from pathlib import Path | |||
6 | import os | 6 | import os |
7 | from glob import glob | 7 | from glob import glob |
8 | 8 | ||
9 | import qmk.path | ||
9 | from qmk.c_parse import parse_config_h_file | 10 | from qmk.c_parse import parse_config_h_file |
10 | from qmk.json_schema import json_load | 11 | from qmk.json_schema import json_load |
11 | from qmk.makefile import parse_rules_mk_file | 12 | from qmk.makefile import parse_rules_mk_file |
12 | from qmk.path import is_keyboard, under_qmk_firmware | ||
13 | 13 | ||
14 | BOX_DRAWING_CHARACTERS = { | 14 | BOX_DRAWING_CHARACTERS = { |
15 | "unicode": { | 15 | "unicode": { |
@@ -36,7 +36,7 @@ base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep | |||
36 | def find_keyboard_from_dir(): | 36 | def find_keyboard_from_dir(): |
37 | """Returns a keyboard name based on the user's current directory. | 37 | """Returns a keyboard name based on the user's current directory. |
38 | """ | 38 | """ |
39 | relative_cwd = under_qmk_firmware() | 39 | relative_cwd = qmk.path.under_qmk_firmware() |
40 | 40 | ||
41 | if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards': | 41 | if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards': |
42 | # Attempt to extract the keyboard name from the current directory | 42 | # Attempt to extract the keyboard name from the current directory |
@@ -47,10 +47,23 @@ def find_keyboard_from_dir(): | |||
47 | keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 | 47 | keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1 |
48 | current_path = current_path.parents[keymap_index] | 48 | current_path = current_path.parents[keymap_index] |
49 | 49 | ||
50 | if is_keyboard(current_path): | 50 | if qmk.path.is_keyboard(current_path): |
51 | return str(current_path) | 51 | return str(current_path) |
52 | 52 | ||
53 | 53 | ||
54 | def find_readme(keyboard): | ||
55 | """Returns the readme for this keyboard. | ||
56 | """ | ||
57 | cur_dir = qmk.path.keyboard(keyboard) | ||
58 | keyboards_dir = Path('keyboards') | ||
59 | while not (cur_dir / 'readme.md').exists(): | ||
60 | if cur_dir == keyboards_dir: | ||
61 | return None | ||
62 | cur_dir = cur_dir.parent | ||
63 | |||
64 | return cur_dir / 'readme.md' | ||
65 | |||
66 | |||
54 | def keyboard_folder(keyboard): | 67 | def keyboard_folder(keyboard): |
55 | """Returns the actual keyboard folder. | 68 | """Returns the actual keyboard folder. |
56 | 69 | ||
@@ -67,7 +80,7 @@ def keyboard_folder(keyboard): | |||
67 | rules_mk = parse_rules_mk_file(rules_mk_file) | 80 | rules_mk = parse_rules_mk_file(rules_mk_file) |
68 | keyboard = rules_mk.get('DEFAULT_FOLDER', keyboard) | 81 | keyboard = rules_mk.get('DEFAULT_FOLDER', keyboard) |
69 | 82 | ||
70 | if not is_keyboard(keyboard): | 83 | if not qmk.path.is_keyboard(keyboard): |
71 | raise ValueError(f'Invalid keyboard: {keyboard}') | 84 | raise ValueError(f'Invalid keyboard: {keyboard}') |
72 | 85 | ||
73 | return keyboard | 86 | return keyboard |