music-assistant-server

1.1 KBSH
run-in-env.sh
1.1 KB23 lines • bash
1#!/usr/bin/env bash
2# Run a development tool through `uv run`, also from a git worktree.
3set -euo pipefail
4
5# A worktree has no virtualenv of its own, so `uv run` builds an incomplete one there (the
6# linters live in the `test` extra, which uv never syncs) and then fails to spawn the tool.
7# Point uv at the main checkout's environment instead. Syncing is disabled in that case
8# because uv resolves the environment against the *current* project, which would re-point
9# the shared venv's editable install at the worktree, so a tool pinned newer on this branch
10# only takes effect once the main checkout is set up again. Export UV_PROJECT_ENVIRONMENT
11# yourself to run against a different environment; this only fills in a default.
12git_dir=$(git rev-parse --path-format=absolute --git-dir 2>/dev/null || true)
13common_dir=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null || true)
14if [[ -z "${UV_PROJECT_ENVIRONMENT:-}" && -n "$common_dir" && "$git_dir" != "$common_dir" ]]; then
15  main_venv="$(dirname "$common_dir")/.venv"
16  if [[ -d "$main_venv" ]]; then
17    export UV_PROJECT_ENVIRONMENT="$main_venv"
18    export UV_NO_SYNC=1
19  fi
20fi
21
22exec uv run "$@"
23