From ad8c332b593ac2e275cdd918672ee3d3336b877a Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 20 Mar 2025 23:53:19 +1100 Subject: [PATCH] Distribution path. --- lib/python/qmk/cli/__init__.py | 5 ++++- util/env-bootstrap.sh | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 07959f0bd3e..314b0489e93 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 @@ -13,7 +15,8 @@ from milc import cli, __VERSION__ from milc.questions import yesno # Ensure the QMK distribution is on the `$PATH` if present. -QMK_DISTRIB_DIR = Path(os.environ.get('QMK_DISTRIB_DIR', os.path.expanduser('~/.local/qmk/distrib'))) # the expansion must be kept in sync with `util/env-bootstrap.sh`! +_default_distrib_path = '/opt/qmk' if 'windows' in platform.platform().lower() else platformdirs.user_data_path('qmk') # this must be kept in sync with the default values inside `util/env-bootstrap.sh`! +QMK_DISTRIB_DIR = Path(os.environ.get('QMK_DISTRIB_DIR', _default_distrib_path)) if QMK_DISTRIB_DIR.exists(): os.environ['PATH'] = str(QMK_DISTRIB_DIR / 'bin') + os.pathsep + os.environ['PATH'] diff --git a/util/env-bootstrap.sh b/util/env-bootstrap.sh index ee26c5a623e..85fb0f8db71 100755 --- a/util/env-bootstrap.sh +++ b/util/env-bootstrap.sh @@ -8,7 +8,7 @@ set -eu ################################################################################ # Configurables: # QMK_DISTRIB_DIR: The directory to install the QMK distribution to. -# UV_INSTALL_DIR: The directory to install `uv` to. This will be ignored on QMK MSYS, installing into `/opt/uv` instead. +# UV_INSTALL_DIR: The directory to install `uv` to. # SKIP_CLEAN: Skip cleaning the distribution directory. # SKIP_UV: Skip installing `uv`. # SKIP_QMK_CLI: Skip installing the QMK CLI. @@ -24,8 +24,16 @@ set -eu # Any other configurable items listed above may be specified in the same way. ################################################################################ +# Windows/MSYS doesn't like `/tmp` so we need to set a different temporary directory. +# Also set the default `UV_INSTALL_DIR` and `QMK_DISTRIB_DIR` to locations which don't pollute the user's home directory, keeping the installation internal to MSYS. +if [ "$(uname -o 2>/dev/null || true)" = "Msys" ]; then + export TMPDIR="$(cygpath -w "$TMP")" + export UV_INSTALL_DIR=${UV_INSTALL_DIR:-/opt/uv} + export QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-/opt/qmk} +fi + # Work out where we want to install the distribution -QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-$HOME/.local/qmk/distrib} +export QMK_DISTRIB_DIR=${QMK_DISTRIB_DIR:-$HOME/.local/share/qmk} # Clear out the target directory if necessary if [ -z "${SKIP_CLEAN:-}" ] || [ -z "${SKIP_QMK_TOOLCHAINS:-}" -a -z "${SKIP_QMK_FLASHUTILS:-}" ]; then if [ -d "$QMK_DISTRIB_DIR" ]; then @@ -35,14 +43,6 @@ if [ -z "${SKIP_CLEAN:-}" ] || [ -z "${SKIP_QMK_TOOLCHAINS:-}" -a -z "${SKIP_QMK fi mkdir -p "$QMK_DISTRIB_DIR" -# Windows doesn't like `/tmp` so we need to set a different temporary directory -# and also set the `UV_INSTALL_DIR` to a location that doesn't pollute the user's -# home directory. -if [ "$(uname -o 2>/dev/null || true)" = "Msys" ]; then - export TMPDIR="$(cygpath -w "$TMP")" - export UV_INSTALL_DIR=/opt/uv -fi - download_url() { local url=$1 local filename=${2:-$(basename "$url")}