aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/path.py
diff options
context:
space:
mode:
authorQMK Bot <[email protected]>2025-03-19 01:46:02 +0000
committerQMK Bot <[email protected]>2025-03-19 01:46:02 +0000
commitd6850bab3f84b177021699ab97308d5afa29e7c8 (patch)
tree7df707901a7566c5d06654c44ba250b92b5c4336 /lib/python/qmk/path.py
parent80b16f688ce027191bb4e7ff5777572bdb4f9f68 (diff)
parent386a5019a8147136c2732452cd87954378e0ec16 (diff)
downloadqmk_firmware-d6850bab3f84b177021699ab97308d5afa29e7c8.tar.gz
qmk_firmware-d6850bab3f84b177021699ab97308d5afa29e7c8.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk/path.py')
-rw-r--r--lib/python/qmk/path.py24
1 files changed, 23 insertions, 1 deletions
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 @@
import logging
import os
import argparse
-from pathlib import Path
+from pathlib import Path, PureWindowsPath, PurePosixPath
from qmk.constants import MAX_KEYBOARD_SUBFOLDERS, QMK_FIRMWARE, QMK_USERSPACE, HAS_QMK_USERSPACE
from qmk.errors import NoSuchKeyboardError
@@ -146,6 +146,28 @@ def normpath(path):
return Path(os.environ['ORIG_CWD']) / path
+def unix_style_path(path):
+ """Converts a Windows-style path with drive letter to a Unix path.
+
+ Path().as_posix() normally returns the path with drive letter and forward slashes, so is inappropriate for `Makefile` paths.
+
+ Passes through unadulterated if the path is not a Windows-style path.
+
+ Args:
+
+ path
+ The path to convert.
+
+ Returns:
+ The input path converted to Unix format.
+ """
+ if isinstance(path, PureWindowsPath):
+ p = list(path.parts)
+ p[0] = f'/{p[0][0].lower()}' # convert from `X:/` to `/x`
+ path = PurePosixPath(*p)
+ return path
+
+
class FileType(argparse.FileType):
def __init__(self, *args, **kwargs):
# Use UTF8 by default for stdin