diff options
Diffstat (limited to 'lib/python/qmk/makefile.py')
| -rw-r--r-- | lib/python/qmk/makefile.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/python/qmk/makefile.py b/lib/python/qmk/makefile.py index 89494bbc0..8645056d2 100644 --- a/lib/python/qmk/makefile.py +++ b/lib/python/qmk/makefile.py | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | """ Functions for working with Makefiles | 1 | """ Functions for working with Makefiles |
| 2 | """ | 2 | """ |
| 3 | import os | 3 | from pathlib import Path |
| 4 | 4 | ||
| 5 | import qmk.path | ||
| 6 | from qmk.errors import NoSuchKeyboardError | 5 | from qmk.errors import NoSuchKeyboardError |
| 7 | 6 | ||
| 8 | 7 | ||
| @@ -19,8 +18,9 @@ def parse_rules_mk_file(file, rules_mk=None): | |||
| 19 | if not rules_mk: | 18 | if not rules_mk: |
| 20 | rules_mk = {} | 19 | rules_mk = {} |
| 21 | 20 | ||
| 22 | if os.path.exists(file): | 21 | file = Path(file) |
| 23 | rules_mk_lines = qmk.path.file_lines(file) | 22 | if file.exists(): |
| 23 | rules_mk_lines = file.read_text().split("\n") | ||
| 24 | 24 | ||
| 25 | for line in rules_mk_lines: | 25 | for line in rules_mk_lines: |
| 26 | # Filter out comments | 26 | # Filter out comments |
| @@ -66,15 +66,16 @@ def get_rules_mk(keyboard): | |||
| 66 | a dictionary with the content of the rules.mk file | 66 | a dictionary with the content of the rules.mk file |
| 67 | """ | 67 | """ |
| 68 | # Start with qmk_firmware/keyboards | 68 | # Start with qmk_firmware/keyboards |
| 69 | kb_path = os.path.join(os.getcwd(), "keyboards") | 69 | kb_path = Path.cwd() / "keyboards" |
| 70 | # walk down the directory tree | 70 | # walk down the directory tree |
| 71 | # and collect all rules.mk files | 71 | # and collect all rules.mk files |
| 72 | if os.path.exists(os.path.join(kb_path, keyboard)): | 72 | kb_dir = kb_path / keyboard |
| 73 | if kb_dir.exists(): | ||
| 73 | rules_mk = dict() | 74 | rules_mk = dict() |
| 74 | for directory in keyboard.split(os.path.sep): | 75 | for directory in Path(keyboard).parts: |
| 75 | kb_path = os.path.join(kb_path, directory) | 76 | kb_path = kb_path / directory |
| 76 | rules_mk_path = os.path.join(kb_path, "rules.mk") | 77 | rules_mk_path = kb_path / "rules.mk" |
| 77 | if os.path.exists(rules_mk_path): | 78 | if rules_mk_path.exists(): |
| 78 | rules_mk = parse_rules_mk_file(rules_mk_path, rules_mk) | 79 | rules_mk = parse_rules_mk_file(rules_mk_path, rules_mk) |
| 79 | else: | 80 | else: |
| 80 | raise NoSuchKeyboardError("The requested keyboard and/or revision does not exist.") | 81 | raise NoSuchKeyboardError("The requested keyboard and/or revision does not exist.") |
