Spaces:
Sleeping
Sleeping
workdir appenv; rm old pup
Browse files
pup
DELETED
|
@@ -1,238 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/bash
|
| 2 |
-
VERSION="pup v0 @ Apr 2 2024" # for Debian
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
####################
|
| 6 |
-
#### Parameters ####
|
| 7 |
-
####################
|
| 8 |
-
|
| 9 |
-
LOG=.woof.log
|
| 10 |
-
# PIXI_DEFAULT_TASK="echo" #"$HOME/appenv/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 7860"
|
| 11 |
-
SYMLINK_ON_PATH=$HOME/.local/bin/pup
|
| 12 |
-
USAGE_MAIN="\n
|
| 13 |
-
\e[1m\e[4mUsage\e[0m: (each subcommand shows more help)\n
|
| 14 |
-
\e[0;33mpup\e[0m\n
|
| 15 |
-
\tinitialize and link ๐ถ to PATH\n
|
| 16 |
-
\e[0;33mpup py\e[0m\n
|
| 17 |
-
\tinteractively install base python to current folder\n
|
| 18 |
-
\tif you know what you need:\n
|
| 19 |
-
\tpup py3.12 jupyter jupyter-collaboration>=2\n
|
| 20 |
-
\t(additional arguments go into 'pixi add')\n
|
| 21 |
-
\e[0;33mpup fetch\e[0m\n
|
| 22 |
-
\tinteractively install packages with uv into specified virtual env\n
|
| 23 |
-
\tif you know what you need:\n
|
| 24 |
-
\tpup fetch . duckdb\n
|
| 25 |
-
\tpup fetch newviz altair seaborn\n
|
| 26 |
-
\e[0;33mpup install\e[0m\n
|
| 27 |
-
\tsame as pup fetch\n
|
| 28 |
-
\e[0;33mpup home\e[0m\n
|
| 29 |
-
\tshow ๐ถ's home folder\n
|
| 30 |
-
\e[0;33mpup kernel\e[0m\n
|
| 31 |
-
\tinteractively create Jupyter kernel linked to ๐ถ's environment\n
|
| 32 |
-
\tif you know what you need:\n
|
| 33 |
-
\tpup kernel . pup3.11-home\n
|
| 34 |
-
\tpup kernel dataenv pup3.11-data\n
|
| 35 |
-
\e[0;33mpup play\e[0m\n
|
| 36 |
-
\truns PIXI_DEFAULT_TASK (default: 'jupyter notebook')\n
|
| 37 |
-
\e[0;33mpup whereami\e[0m\n
|
| 38 |
-
\tin case you got lost: log of ๐ถ's commands thus far\n
|
| 39 |
-
\e[0;33mpup which\e[0m\n
|
| 40 |
-
\tshow ๐ถ's current symlink\n
|
| 41 |
-
\n"
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
###################
|
| 45 |
-
#### Functions ####
|
| 46 |
-
###################
|
| 47 |
-
|
| 48 |
-
log_command() {
|
| 49 |
-
ts=$(date +'%FT%T')
|
| 50 |
-
echo "# $ts" >> "$(pup home)/$LOG"
|
| 51 |
-
echo "$1" >> "$(pup home)/$LOG"
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
log() {
|
| 55 |
-
ts=$(date +'%FT%T')
|
| 56 |
-
for arg in "$@"; do
|
| 57 |
-
echo "# $ts - $arg" | tee -a "$(pup home)/$LOG"
|
| 58 |
-
done
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
#######################
|
| 63 |
-
#### CORE COMMANDS ####
|
| 64 |
-
#######################
|
| 65 |
-
|
| 66 |
-
#### init (no args) ####
|
| 67 |
-
if [ -z "$1" ]; then
|
| 68 |
-
# init pup and show usage
|
| 69 |
-
echo -e $USAGE_MAIN
|
| 70 |
-
|
| 71 |
-
# link
|
| 72 |
-
SYMLINK_CURRENT=$(readlink -f "$SYMLINK_ON_PATH")
|
| 73 |
-
if [ "$SYMLINK_CURRENT" != "$(pwd)/pup" ] && [ -f "./pup" ]; then
|
| 74 |
-
SYMLINK_PATH_FOLDER=${SYMLINK_ON_PATH%/*}
|
| 75 |
-
mkdir -p "$SYMLINK_PATH_FOLDER"
|
| 76 |
-
ln -s -f "$(pwd)"/pup $SYMLINK_ON_PATH
|
| 77 |
-
fi
|
| 78 |
-
log_command "$0 $*"
|
| 79 |
-
log woof!
|
| 80 |
-
log "๐ถ = $(pup which)"
|
| 81 |
-
# initialize Pixi project in 'pup home'
|
| 82 |
-
pup pixi init
|
| 83 |
-
exit 0
|
| 84 |
-
fi
|
| 85 |
-
#### py|python ####
|
| 86 |
-
if [[ "$1" =~ ^py$|^python$ ]]; then
|
| 87 |
-
USAGE="\n
|
| 88 |
-
\e[1m\e[4mUsage\e[0m: pup $1{version} [ADDITIONAL PACKAGES]\n
|
| 89 |
-
For example:\n
|
| 90 |
-
\tpup py3.12 jupyter jupyter-collaboration>=2\n
|
| 91 |
-
\e[4mNote\e[0m:\n
|
| 92 |
-
\tthis command is meant to be used once during the first base layer setup;\n
|
| 93 |
-
\tbeyond that, use 'pixi add'\n
|
| 94 |
-
\n"
|
| 95 |
-
echo -e $USAGE
|
| 96 |
-
read -ei "" -p $'\e[0;33minstall which python version (blank = latest)? \e[0m' PYVER
|
| 97 |
-
PACKAGES=${@:2}
|
| 98 |
-
read -ei "${PACKAGES:-notebook>=7}" -p $'\e[0;33many additional packages? \e[0m' PACKAGES
|
| 99 |
-
pup pixi init
|
| 100 |
-
COMMAND="pixi add uv python${PYVER:+=$PYVER} $PACKAGES"
|
| 101 |
-
log "๐ถ asked for: '$COMMAND'"
|
| 102 |
-
$COMMAND
|
| 103 |
-
exit 0
|
| 104 |
-
fi
|
| 105 |
-
if [[ "$1" =~ ^py3.*$ ]]; then
|
| 106 |
-
log_command "$0 $*"
|
| 107 |
-
pup pixi init
|
| 108 |
-
COMMAND="pixi add uv python=${1#py} ${@:2}"
|
| 109 |
-
log "๐ถ asked for: '$COMMAND'"
|
| 110 |
-
$COMMAND
|
| 111 |
-
log "โจ $(pixi run python -VV)"
|
| 112 |
-
exit 0
|
| 113 |
-
fi
|
| 114 |
-
#### fetch|install ####
|
| 115 |
-
if [[ "$1" =~ ^fetch$|^install$ ]]; then
|
| 116 |
-
USAGE="\e[1m\e[4mUsage\e[0m: pup $1 [WHERE] [WHAT] [OPTIONS]"
|
| 117 |
-
if [ -z "$2" ]; then
|
| 118 |
-
echo -e $USAGE
|
| 119 |
-
read -ei "." -p "Fetch packages where? " WHERE
|
| 120 |
-
read -ei "" -p "What packages? " WHAT
|
| 121 |
-
read -ei "" -p "Options to pass to 'uv pip install'? " OPTIONS
|
| 122 |
-
COMMAND="pup fetch $WHERE $WHAT $OPTIONS"
|
| 123 |
-
log "๐ถ asked for: '$COMMAND'"
|
| 124 |
-
$COMMAND
|
| 125 |
-
exit 0
|
| 126 |
-
fi
|
| 127 |
-
if [ $# -eq 2 ]; then
|
| 128 |
-
echo "`๐ถ fetch` needs more arguments"
|
| 129 |
-
echo -e $USAGE
|
| 130 |
-
fi
|
| 131 |
-
if [ $# -gt 2 ] && [ "$2" = "." ]; then
|
| 132 |
-
PYTHON=$(pixi run which python)
|
| 133 |
-
fi
|
| 134 |
-
if [ $# -gt 2 ] && [ "$2" != "." ]; then
|
| 135 |
-
pup new $2
|
| 136 |
-
PYTHON="$(pup home)/$2/.venv/bin/python"
|
| 137 |
-
fi
|
| 138 |
-
COMMAND="pixi run uv pip install -p $PYTHON ${@:3}"
|
| 139 |
-
log "๐ถ asked for: '$COMMAND'"
|
| 140 |
-
$COMMAND
|
| 141 |
-
exit 0
|
| 142 |
-
fi
|
| 143 |
-
#### kernel ####
|
| 144 |
-
if [ "$1" == "kernel" ]; then
|
| 145 |
-
USAGE="\e[1m\e[4mUsage\e[0m: pup $1 [WHERE] [KERNEL_NAME]"
|
| 146 |
-
if [ -z "$2" ]; then
|
| 147 |
-
echo -e $USAGE
|
| 148 |
-
read -ei "." -p "Install kernel for which environment? " WHERE
|
| 149 |
-
PYVER=$(pixi run python -V); PYVER=${PYVER#Python }
|
| 150 |
-
read -ei "pup$PYVER-$WHERE" -p "Unique kernel name? (allowed characters: [a-zA-Z0-9.-_]) " KERNEL_NAME
|
| 151 |
-
COMMAND="pup kernel $WHERE $KERNEL_NAME"
|
| 152 |
-
log "๐ถ asked for: '$COMMAND'"
|
| 153 |
-
$COMMAND
|
| 154 |
-
exit 0
|
| 155 |
-
fi
|
| 156 |
-
if [ $# -eq 2 ]; then
|
| 157 |
-
echo "`๐ถ kernel` needs more arguments"
|
| 158 |
-
echo -e $USAGE
|
| 159 |
-
fi
|
| 160 |
-
if [ $# -gt 2 ] && [ "$2" = "." ]; then
|
| 161 |
-
PYTHON=$(pixi run which python)
|
| 162 |
-
fi
|
| 163 |
-
if [ $# -gt 2 ] && [ "$2" != "." ]; then
|
| 164 |
-
PYTHON="$(pup home)/$2/.venv/bin/python"
|
| 165 |
-
fi
|
| 166 |
-
pup fetch $2 ipykernel
|
| 167 |
-
COMMAND="$PYTHON -m ipykernel install --user --name $3"
|
| 168 |
-
log "๐ถ asked for: '$COMMAND'"
|
| 169 |
-
$COMMAND
|
| 170 |
-
exit 0
|
| 171 |
-
fi
|
| 172 |
-
#### new ####
|
| 173 |
-
if [ "$1" == "new" ]; then
|
| 174 |
-
log_command "$0 $*"
|
| 175 |
-
VENV_PATH="$(pup home)/$2/.venv"
|
| 176 |
-
if [ ! -d "$VENV_PATH" ]; then
|
| 177 |
-
pixi run uv venv -p "$(pixi run which python)" $VENV_PATH
|
| 178 |
-
log "pup & uv created new environment in $2"
|
| 179 |
-
else
|
| 180 |
-
log "found existing uv virtual environment $2"
|
| 181 |
-
fi
|
| 182 |
-
exit 0
|
| 183 |
-
fi
|
| 184 |
-
#### play ####
|
| 185 |
-
if [ "$1" == "play" ]; then
|
| 186 |
-
pixi run start
|
| 187 |
-
exit 0
|
| 188 |
-
fi
|
| 189 |
-
#########################
|
| 190 |
-
#### HELPER COMMANDS ####
|
| 191 |
-
#########################
|
| 192 |
-
#### home ####
|
| 193 |
-
if [ "$1" == "home" ]; then
|
| 194 |
-
if [ -L "$0" ]; then
|
| 195 |
-
dirname $(readlink -f $SYMLINK_ON_PATH)
|
| 196 |
-
else
|
| 197 |
-
realpath $(dirname $0)
|
| 198 |
-
fi
|
| 199 |
-
exit 0
|
| 200 |
-
fi
|
| 201 |
-
#### pixi ####
|
| 202 |
-
if [ "$1" == "pixi" ]; then
|
| 203 |
-
if [ "$2" == "init" ]; then
|
| 204 |
-
# install and init Pixi project in pup's home dir
|
| 205 |
-
if ! command -v pixi &> /dev/null; then
|
| 206 |
-
export SHELL=bash
|
| 207 |
-
curl -fsSL https://pixi.sh/install.sh | bash
|
| 208 |
-
fi
|
| 209 |
-
PUPHOME=$(pup home)
|
| 210 |
-
if [[ ! -f "$PUPHOME"/pixi.toml ]]; then
|
| 211 |
-
pixi init "$PUPHOME"
|
| 212 |
-
# pixi task add start "$PIXI_DEFAULT_TASK"
|
| 213 |
-
fi
|
| 214 |
-
exit 0
|
| 215 |
-
fi
|
| 216 |
-
if [ "$2" == "rm" ]; then
|
| 217 |
-
# remove pixi files
|
| 218 |
-
rm -r "$(pup home)"/.pixi "$(pup home)"/pixi*
|
| 219 |
-
exit 0
|
| 220 |
-
fi
|
| 221 |
-
fi
|
| 222 |
-
#### version ####
|
| 223 |
-
if [ "$1" == "version" ]; then
|
| 224 |
-
echo $VERSION
|
| 225 |
-
exit 0
|
| 226 |
-
fi
|
| 227 |
-
#### which ####
|
| 228 |
-
if [ "$1" == "which" ]; then
|
| 229 |
-
echo $(ls "$SYMLINK_ON_PATH") -\> $(readlink -f $SYMLINK_ON_PATH)
|
| 230 |
-
exit 0
|
| 231 |
-
fi
|
| 232 |
-
#### whereami ####
|
| 233 |
-
if [ "$1" == "whereami" ]; then
|
| 234 |
-
cat "$(pup home)/$LOG"
|
| 235 |
-
exit 0
|
| 236 |
-
fi
|
| 237 |
-
#### unknown command ####
|
| 238 |
-
echo -e "\e[0;33m๐ถ does not know 'pup $*'\e[0m\nrun 'pup' to list known commands"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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