aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/cli/__init__.py
diff options
context:
space:
mode:
authorQMK Bot2025-11-27 14:37:29 +0100
committerQMK Bot2025-11-27 14:37:29 +0100
commit9acd127cc1318d761aac76a806189fadeaaa247a (patch)
treeaf6649c0034b51d0595855cbb692256ae17d97dd /lib/python/qmk/cli/__init__.py
parent9ab8e4cd5a9d21f45c9f68c718c7c31765e0a321 (diff)
parent9c2ca00074784dbee27b459d71cfc8e75f47b976 (diff)
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk/cli/__init__.py')
-rw-r--r--lib/python/qmk/cli/__init__.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 26905ec134..dc2e4726a5 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -3,6 +3,8 @@
We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
"""
import os
+import platform
+import platformdirs
import shlex
import sys
from importlib.util import find_spec
@@ -12,6 +14,28 @@ from subprocess import run
from milc import cli, __VERSION__
from milc.questions import yesno
+
+def _get_default_distrib_path():
+ if 'windows' in platform.platform().lower():
+ try:
+ result = cli.run(['cygpath', '-w', '/opt/qmk'])
+ if result.returncode == 0:
+ return result.stdout.strip()
+ except Exception:
+ pass
+
+ return platformdirs.user_data_dir('qmk')
+
+
+# Ensure the QMK distribution is on the `$PATH` if present. This must be kept in sync with qmk/qmk_cli.
+QMK_DISTRIB_DIR = Path(os.environ.get('QMK_DISTRIB_DIR', _get_default_distrib_path()))
+if QMK_DISTRIB_DIR.exists():
+ os.environ['PATH'] = str(QMK_DISTRIB_DIR / 'bin') + os.pathsep + os.environ['PATH']
+
+# Prepend any user-defined path prefix
+if 'QMK_PATH_PREFIX' in os.environ:
+ os.environ['PATH'] = os.environ['QMK_PATH_PREFIX'] + os.pathsep + os.environ['PATH']
+
import_names = {
# A mapping of package name to importable name
'pep8-naming': 'pep8ext_naming',