Skip to content

Instantly share code, notes, and snippets.

@jimdiroffii
Last active April 18, 2025 04:53
Show Gist options
  • Save jimdiroffii/81c449544464c8bdaa09b52ffb4e5de7 to your computer and use it in GitHub Desktop.
Save jimdiroffii/81c449544464c8bdaa09b52ffb4e5de7 to your computer and use it in GitHub Desktop.
Maintain a Python wheelhouse across different machines. I'm using this for VM data disks, where the VM is only used on one host at a time, and the data disk is transferred between hosts.
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Path to the data disk
DATA_DISK="/mnt/data"
WHEELHOUSE_PATH="$DATA_DISK/wheelhouse"
PIP_CONF_PATH="$DATA_DISK/pip/pip.conf"
mountpoint -q "$DATA_DISK" || { echo "Error: $DATA_DISK not mounted"; exit 1; }
# Ensure the wheelhouse directory exists
if [ ! -d "$WHEELHOUSE_PATH" ]; then
echo "Creating wheelhouse directory..."
mkdir -p "$WHEELHOUSE_PATH"
fi
# Ensure pip config directory exists
if [ ! -d "$DATA_DISK/pip" ]; then
echo "Creating pip config directory..."
mkdir -p "$DATA_DISK/pip"
fi
# Create/update pip.conf if needed
if [ ! -f "$PIP_CONF_PATH" ]; then
echo "Creating pip.conf..."
mkdir -p "$DATA_DISK/.configs/pip"
cat > "$PIP_CONF_PATH" << EOL
[global]
find-links = file://$WHEELHOUSE_PATH
no-index = false
EOL
fi
# Set up the user pip config to point to our pip.conf
USER_PIP_DIR="$HOME/.config/pip"
if [ ! -d "$USER_PIP_DIR" ]; then
echo "Creating user pip dir"
mkdir -p "$USER_PIP_DIR"
fi
if [ -f "$USER_PIP_DIR/pip.conf" ] && [ ! -L "$USER_PIP_DIR/pip.conf" ]; then
cp "$USER_PIP_DIR/pip.conf"{,.bak}
fi
echo "Configuring pip to use wheelhouse..."
ln -sf "$PIP_CONF_PATH" "$USER_PIP_DIR/pip.conf"
# Set helpful environment variables for the current session (Edit: set in bashrc)
#export PIP_FIND_LINKS="file://$WHEELHOUSE_PATH"
#export PYTHONPATH="$PYTHONPATH:$DATA_DISK/lib"
# Verify the setup
echo "Wheelhouse activated!"
echo "Wheelhouse location: $WHEELHOUSE_PATH"
echo "Run 'pip install --no-index --find-links=$WHEELHOUSE_PATH package_name' to install packages"
echo "Run 'pip download --prefer-binary -d $WHEELHOUSE_PATH package_name' to download packages to the wheelhouse"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment