summaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2025-03-19 12:45:28 +1100
committerGitHub <noreply@github.com>2025-03-19 12:45:28 +1100
commit386a5019a8147136c2732452cd87954378e0ec16 (patch)
tree9c172e40a59919ca98fcc123dd7ca4abf6794b27 /lib/python
parent271efeb8bc99922e6ce1a664f82bc922cd2e8121 (diff)
Fixup MSYS + unix-style paths in Community Modules. (#25012)
Fixup MSYS + unix-style paths.
Diffstat (limited to 'lib/python')
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py4
-rw-r--r--lib/python/qmk/path.py24
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py
index cae9b07c3e..ef4101d77f 100755
--- a/lib/python/qmk/cli/generate/rules_mk.py
+++ b/lib/python/qmk/cli/generate/rules_mk.py
@@ -10,7 +10,7 @@ from qmk.info import info_json, get_modules
10from qmk.json_schema import json_load 10from qmk.json_schema import json_load
11from qmk.keyboard import keyboard_completer, keyboard_folder 11from qmk.keyboard import keyboard_completer, keyboard_folder
12from qmk.commands import dump_lines, parse_configurator_json 12from qmk.commands import dump_lines, parse_configurator_json
13from qmk.path import normpath, FileType 13from qmk.path import normpath, unix_style_path, FileType
14from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE 14from qmk.constants import GPL2_HEADER_SH_LIKE, GENERATED_HEADER_SH_LIKE
15from qmk.community_modules import find_module_path, load_module_jsons 15from qmk.community_modules import find_module_path, load_module_jsons
16 16
@@ -63,7 +63,7 @@ def generate_modules_rules(keyboard, filename):
63 lines.append('') 63 lines.append('')
64 lines.append('OPT_DEFS += -DCOMMUNITY_MODULES_ENABLE=TRUE') 64 lines.append('OPT_DEFS += -DCOMMUNITY_MODULES_ENABLE=TRUE')
65 for module in modules: 65 for module in modules:
66 module_path = find_module_path(module) 66 module_path = unix_style_path(find_module_path(module))
67 if not module_path: 67 if not module_path:
68 raise FileNotFoundError(f"Module '{module}' not found.") 68 raise FileNotFoundError(f"Module '{module}' not found.")
69 lines.append('') 69 lines.append('')
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py
index 61daad585f..c47ed18362 100644
--- a/lib/python/qmk/path.py
+++ b/lib/python/qmk/path.py
@@ -3,7 +3,7 @@
3import logging 3import logging
4import os 4import os
5import argparse 5import argparse
6from pathlib import Path 6from pathlib import Path, PureWindowsPath, PurePosixPath
7 7
8from qmk.constants import MAX_KEYBOARD_SUBFOLDERS, QMK_FIRMWARE, QMK_USERSPACE, HAS_QMK_USERSPACE 8from qmk.constants import MAX_KEYBOARD_SUBFOLDERS, QMK_FIRMWARE, QMK_USERSPACE, HAS_QMK_USERSPACE
9from qmk.errors import NoSuchKeyboardError 9from qmk.errors import NoSuchKeyboardError
@@ -146,6 +146,28 @@ def normpath(path):
146 return Path(os.environ['ORIG_CWD']) / path 146 return Path(os.environ['ORIG_CWD']) / path
147 147
148 148
149def unix_style_path(path):
150 """Converts a Windows-style path with drive letter to a Unix path.
151
152 Path().as_posix() normally returns the path with drive letter and forward slashes, so is inappropriate for `Makefile` paths.
153
154 Passes through unadulterated if the path is not a Windows-style path.
155
156 Args:
157
158 path
159 The path to convert.
160
161 Returns:
162 The input path converted to Unix format.
163 """
164 if isinstance(path, PureWindowsPath):
165 p = list(path.parts)
166 p[0] = f'/{p[0][0].lower()}' # convert from `X:/` to `/x`
167 path = PurePosixPath(*p)
168 return path
169
170
149class FileType(argparse.FileType): 171class FileType(argparse.FileType):
150 def __init__(self, *args, **kwargs): 172 def __init__(self, *args, **kwargs):
151 # Use UTF8 by default for stdin 173 # Use UTF8 by default for stdin