mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-31 15:57:26 +00:00
Do not re-download already installed Python versions (#1133)
A minor usability improvement cherry-picked from https://github.com/astral-sh/puffin/pull/1131 e.g. ``` ❯ scripts/bootstrap/install.sh Installing cpython-3.8.12-darwin-arm64 Already available, skipping download Updated executables for python3.8.12 Installing cpython-3.8.18-darwin-arm64 Already available, skipping download Updated executables for python3.8.18 Installing cpython-3.9.18-darwin-arm64 Already available, skipping download Updated executables for python3.9.18 Installing cpython-3.10.13-darwin-arm64 Already available, skipping download Updated executables for python3.10.13 Installing cpython-3.11.7-darwin-arm64 Already available, skipping download Updated executables for python3.11.7 Installing cpython-3.12.1-darwin-arm64 Already available, skipping download Updated executables for python3.12.1 Done! ```
This commit is contained in:
parent
15ca17a68d
commit
cb73b724cb
1 changed files with 27 additions and 10 deletions
|
@ -63,14 +63,39 @@ interpreter='cpython'
|
||||||
# On macOS, we need a newer version of `realpath` for `--relative-to` support
|
# On macOS, we need a newer version of `realpath` for `--relative-to` support
|
||||||
realpath="$(which grealpath || which realpath)"
|
realpath="$(which grealpath || which realpath)"
|
||||||
|
|
||||||
|
|
||||||
|
# Utility for linking executables for the version being installed
|
||||||
|
# We need to update executables even if the version is already downloaded and extracted
|
||||||
|
# to ensure that changes to the precedence of versions are respected
|
||||||
|
link_executables() {
|
||||||
|
# Use relative paths for links so if the bin is moved they don't break
|
||||||
|
local link=$($realpath --relative-to="$bin_dir" "$install_key/install/bin/python3")
|
||||||
|
local minor=$(jq --arg key "$key" '.[$key] | .minor' -r < "$versions_metadata")
|
||||||
|
|
||||||
|
# Link as all version tuples, later versions in the file will take precedence
|
||||||
|
ln -sf "./$link" "$bin_dir/python$version"
|
||||||
|
ln -sf "./$link" "$bin_dir/python3.$minor"
|
||||||
|
ln -sf "./$link" "$bin_dir/python3"
|
||||||
|
ln -sf "./$link" "$bin_dir/python"
|
||||||
|
}
|
||||||
|
|
||||||
# Read requested versions into an array
|
# Read requested versions into an array
|
||||||
readarray -t versions < "$versions_file"
|
readarray -t versions < "$versions_file"
|
||||||
|
|
||||||
# Install each version
|
# Install each version
|
||||||
for version in "${versions[@]}"; do
|
for version in "${versions[@]}"; do
|
||||||
key="$interpreter-$version-$os-$arch"
|
key="$interpreter-$version-$os-$arch"
|
||||||
|
install_key="$install_dir/$interpreter@$version"
|
||||||
echo "Installing $key"
|
echo "Installing $key"
|
||||||
|
|
||||||
|
if [ -d "$install_key" ]; then
|
||||||
|
echo "Already available, skipping download"
|
||||||
|
link_executables
|
||||||
|
echo "Updated executables for python$version"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
url=$(jq --arg key "$key" '.[$key] | .url' -r < "$versions_metadata")
|
url=$(jq --arg key "$key" '.[$key] | .url' -r < "$versions_metadata")
|
||||||
|
|
||||||
if [ "$url" == 'null' ]; then
|
if [ "$url" == 'null' ]; then
|
||||||
|
@ -91,7 +116,6 @@ for version in "${versions[@]}"; do
|
||||||
echo " OK"
|
echo " OK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install_key="$install_dir/$interpreter@$version"
|
|
||||||
rm -rf "$install_key"
|
rm -rf "$install_key"
|
||||||
echo "Extracting to $($realpath --relative-to="$root_dir" "$install_key")"
|
echo "Extracting to $($realpath --relative-to="$root_dir" "$install_key")"
|
||||||
mkdir -p "$install_key"
|
mkdir -p "$install_key"
|
||||||
|
@ -99,16 +123,9 @@ for version in "${versions[@]}"; do
|
||||||
|
|
||||||
# Setup the installation
|
# Setup the installation
|
||||||
mv "$install_key/python/"* "$install_key"
|
mv "$install_key/python/"* "$install_key"
|
||||||
# Use relative paths for links so if the bin is moved they don't break
|
|
||||||
link=$($realpath --relative-to="$bin_dir" "$install_key/install/bin/python3")
|
|
||||||
minor=$(jq --arg key "$key" '.[$key] | .minor' -r < "$versions_metadata")
|
|
||||||
|
|
||||||
# Link as all version tuples, later versions in the file will take precedence
|
link_executables
|
||||||
ln -sf "./$link" "$bin_dir/python$version"
|
echo "Installed executables for python$version"
|
||||||
ln -sf "./$link" "$bin_dir/python3.$minor"
|
|
||||||
ln -sf "./$link" "$bin_dir/python3"
|
|
||||||
ln -sf "./$link" "$bin_dir/python"
|
|
||||||
echo "Installed as python$version"
|
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
rmdir "$install_key/python/"
|
rmdir "$install_key/python/"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue