summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/__init__.py
diff options
context:
space:
mode:
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 @@
3We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. 3We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup.
4""" 4"""
5import os 5import os
6import platform
7import platformdirs
6import shlex 8import shlex
7import sys 9import sys
8from importlib.util import find_spec 10from importlib.util import find_spec
@@ -12,6 +14,28 @@ from subprocess import run
12from milc import cli, __VERSION__ 14from milc import cli, __VERSION__
13from milc.questions import yesno 15from milc.questions import yesno
14 16
17
18def _get_default_distrib_path():
19 if 'windows' in platform.platform().lower():
20 try:
21 result = cli.run(['cygpath', '-w', '/opt/qmk'])
22 if result.returncode == 0:
23 return result.stdout.strip()
24 except Exception:
25 pass
26
27 return platformdirs.user_data_dir('qmk')
28
29
30# Ensure the QMK distribution is on the `$PATH` if present. This must be kept in sync with qmk/qmk_cli.
31QMK_DISTRIB_DIR = Path(os.environ.get('QMK_DISTRIB_DIR', _get_default_distrib_path()))
32if QMK_DISTRIB_DIR.exists():
33 os.environ['PATH'] = str(QMK_DISTRIB_DIR / 'bin') + os.pathsep + os.environ['PATH']
34
35# Prepend any user-defined path prefix
36if 'QMK_PATH_PREFIX' in os.environ:
37 os.environ['PATH'] = os.environ['QMK_PATH_PREFIX'] + os.pathsep + os.environ['PATH']
38
15import_names = { 39import_names = {
16 # A mapping of package name to importable name 40 # A mapping of package name to importable name
17 'pep8-naming': 'pep8ext_naming', 41 'pep8-naming': 'pep8ext_naming',