Skip to content

Instantly share code, notes, and snippets.

@digitalsignalperson
Created March 3, 2026 06:45
Show Gist options
  • Select an option

  • Save digitalsignalperson/4af0eb8324d1a94ec5968f882140c8f9 to your computer and use it in GitHub Desktop.

Select an option

Save digitalsignalperson/4af0eb8324d1a94ec5968f882140c8f9 to your computer and use it in GitHub Desktop.
uw - a uv wrapper to run a uv "workspace" with independent uv.lock from its dependencies
#!/usr/bin/env bash
set -euo pipefail
# Walk up from CWD looking for .uw
find_uw_root() {
local dir="$PWD"
while [[ "$dir" != "/" ]]; do
if [[ -f "$dir/.uw" ]]; then
echo "$dir"
return 0
fi
dir="$(dirname "$dir")"
done
echo "uw: no .uw file found in any parent directory" >&2
return 1
}
UW_ROOT="$(find_uw_root)"
# Parse the workspace path from .uw (handles `workspace = "packages/workspace"`)
WORKSPACE_REL="$(grep '^workspace' "$UW_ROOT/.uw" | sed 's/.*=\s*"\(.*\)"/\1/')"
WORKSPACE_DIR="$UW_ROOT/$WORKSPACE_REL"
if [[ ! -d "$WORKSPACE_DIR" ]]; then
echo "uw: workspace directory not found: $WORKSPACE_DIR" >&2
exit 1
fi
# Run uv with the workspace package as the project root
exec uv --project "$WORKSPACE_DIR" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment