diff options
| author | Nick Brassel <nick@tzarc.org> | 2025-11-28 00:36:49 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-28 00:36:49 +1100 |
| commit | 9c2ca00074784dbee27b459d71cfc8e75f47b976 (patch) | |
| tree | a59576289fd024bf35b0573db70eb8862ed44568 /lib/python/qmk/cli/__init__.py | |
| parent | 594558ec7b9ac1963870447778426682065e0d20 (diff) | |
QMK CLI Environment bootstrapper (#25038)
Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Pascal Getreuer <getreuer@google.com>
Diffstat (limited to 'lib/python/qmk/cli/__init__.py')
| -rw-r--r-- | lib/python/qmk/cli/__init__.py | 24 |
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 @@ | |||
| 3 | We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. | 3 | We list each subcommand here explicitly because all the reliable ways of searching for modules are slow and delay startup. |
| 4 | """ | 4 | """ |
| 5 | import os | 5 | import os |
| 6 | import platform | ||
| 7 | import platformdirs | ||
| 6 | import shlex | 8 | import shlex |
| 7 | import sys | 9 | import sys |
| 8 | from importlib.util import find_spec | 10 | from importlib.util import find_spec |
| @@ -12,6 +14,28 @@ from subprocess import run | |||
| 12 | from milc import cli, __VERSION__ | 14 | from milc import cli, __VERSION__ |
| 13 | from milc.questions import yesno | 15 | from milc.questions import yesno |
| 14 | 16 | ||
| 17 | |||
| 18 | def _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. | ||
| 31 | QMK_DISTRIB_DIR = Path(os.environ.get('QMK_DISTRIB_DIR', _get_default_distrib_path())) | ||
| 32 | if 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 | ||
| 36 | if 'QMK_PATH_PREFIX' in os.environ: | ||
| 37 | os.environ['PATH'] = os.environ['QMK_PATH_PREFIX'] + os.pathsep + os.environ['PATH'] | ||
| 38 | |||
| 15 | import_names = { | 39 | import_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', |
