pup-py commited on
Commit
0e968fe
1 Parent(s): 8d50ae4
Files changed (4) hide show
  1. Dockerfile +12 -0
  2. README.md +2 -1
  3. packages.txt +1 -0
  4. pup +260 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:latest
2
+
3
+ WORKDIR /code
4
+
5
+ COPY . .
6
+
7
+ RUN ./pup py3.11
8
+
9
+ # EXPOSE 786
10
+ # CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
11
+
12
+ CMD ["python3", "-m", "http.server", "7860", "--directory", "."]
README.md CHANGED
@@ -1,10 +1,11 @@
1
  ---
2
  title: Pixi
3
- emoji: 🐢
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Pixi
3
+ emoji:
4
  colorFrom: blue
5
  colorTo: purple
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ curl
pup ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ VERSION="pup v0 @ Apr 1 2024"
3
+
4
+
5
+ ####################
6
+ #### Parameters ####
7
+ ####################
8
+
9
+ LOG=.woof.log
10
+ PIXI_DEFAULT_TASK="jupyter notebook --ip=0.0.0.0 --port=8880"
11
+ SYMLINK_ON_PATH=~/.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
+ mkdir -p ~/.local/bin
75
+ ln -s --force "$(pwd)"/pup $SYMLINK_ON_PATH
76
+ fi
77
+ log_command "$0 $*"
78
+ log woof!
79
+ log "🐶 = $(pup which)"
80
+
81
+ # initialize Pixi project in 'pup home'
82
+ pup pixi init
83
+ exit 0
84
+ fi
85
+
86
+
87
+ #### py|python ####
88
+ if [[ "$1" =~ ^py$|^python$ ]]; then
89
+ USAGE="\n
90
+ \e[1m\e[4mUsage\e[0m: pup $1{version} [ADDITIONAL PACKAGES]\n
91
+ For example:\n
92
+ \tpup py3.12 jupyter jupyter-collaboration>=2\n
93
+ \e[4mNote\e[0m:\n
94
+ \tthis command is meant to be used once during the first base layer setup;\n
95
+ \tbeyond that, use 'pixi add'\n
96
+ \n"
97
+ echo -e $USAGE
98
+ read -ei "" -p $'\e[0;33minstall which python version (blank = latest)? \e[0m' PYVER
99
+ PACKAGES=${@:2}
100
+ read -ei "${PACKAGES:-notebook>=7}" -p $'\e[0;33many additional packages? \e[0m' PACKAGES
101
+ pup pixi init
102
+ COMMAND="pixi add uv python${PYVER:+=$PYVER} $PACKAGES"
103
+ log "🐶 asked for: '$COMMAND'"
104
+ $COMMAND
105
+ exit 0
106
+ fi
107
+
108
+ if [[ "$1" =~ ^py3.*$ ]]; then
109
+ log_command "$0 $*"
110
+ pup pixi init
111
+ COMMAND="pixi add uv python=${1#py} ${@:2}"
112
+ log "🐶 asked for: '$COMMAND'"
113
+ $COMMAND
114
+ log "✨ $(pixi run python -VV)"
115
+ exit 0
116
+ fi
117
+
118
+
119
+ #### fetch|install ####
120
+ if [[ "$1" =~ ^fetch$|^install$ ]]; then
121
+ USAGE="\e[1m\e[4mUsage\e[0m: pup $1 [WHERE] [WHAT] [OPTIONS]"
122
+ if [ -z "$2" ]; then
123
+ echo -e $USAGE
124
+ read -ei "." -p "Fetch packages where? " WHERE
125
+ read -ei "" -p "What packages? " WHAT
126
+ read -ei "" -p "Options to pass to 'uv pip install'? " OPTIONS
127
+ COMMAND="pup fetch $WHERE $WHAT $OPTIONS"
128
+ log "🐶 asked for: '$COMMAND'"
129
+ $COMMAND
130
+ exit 0
131
+ fi
132
+ if [ $# -eq 2 ]; then
133
+ echo "`🐶 fetch` needs more arguments"
134
+ echo -e $USAGE
135
+ fi
136
+ if [ $# -gt 2 ] && [ "$2" = "." ]; then
137
+ PYTHON=$(pixi run which python)
138
+ fi
139
+ if [ $# -gt 2 ] && [ "$2" != "." ]; then
140
+ pup new $2
141
+ PYTHON="$(pup home)/$2/.venv/bin/python"
142
+ fi
143
+ COMMAND="pixi run uv pip install -p $PYTHON ${@:3}"
144
+ log "🐶 asked for: '$COMMAND'"
145
+ $COMMAND
146
+ exit 0
147
+ fi
148
+
149
+
150
+ #### kernel ####
151
+ if [ "$1" == "kernel" ]; then
152
+ USAGE="\e[1m\e[4mUsage\e[0m: pup $1 [WHERE] [KERNEL_NAME]"
153
+ if [ -z "$2" ]; then
154
+ echo -e $USAGE
155
+ read -ei "." -p "Install kernel for which environment? " WHERE
156
+ PYVER=$(pixi run python -V); PYVER=${PYVER#Python }
157
+ read -ei "pup$PYVER-$WHERE" -p "Unique kernel name? (allowed characters: [a-zA-Z0-9.-_]) " KERNEL_NAME
158
+ COMMAND="pup kernel $WHERE $KERNEL_NAME"
159
+ log "🐶 asked for: '$COMMAND'"
160
+ $COMMAND
161
+ exit 0
162
+ fi
163
+ if [ $# -eq 2 ]; then
164
+ echo "`🐶 kernel` needs more arguments"
165
+ echo -e $USAGE
166
+ fi
167
+ if [ $# -gt 2 ] && [ "$2" = "." ]; then
168
+ PYTHON=$(pixi run which python)
169
+ fi
170
+ if [ $# -gt 2 ] && [ "$2" != "." ]; then
171
+ PYTHON="$(pup home)/$2/.venv/bin/python"
172
+ fi
173
+ pup fetch $2 ipykernel
174
+ COMMAND="$PYTHON -m ipykernel install --user --name $3"
175
+ log "🐶 asked for: '$COMMAND'"
176
+ $COMMAND
177
+ exit 0
178
+ fi
179
+
180
+ #### new ####
181
+ if [ "$1" == "new" ]; then
182
+ log_command "$0 $*"
183
+ VENV_PATH="$(pup home)/$2/.venv"
184
+ if [ ! -d "$VENV_PATH" ]; then
185
+ pixi run uv venv -p "$(pixi run which python)" $VENV_PATH
186
+ log "pup & uv created new environment in $2"
187
+ else
188
+ log "found existing uv virtual environment $2"
189
+ fi
190
+ exit 0
191
+ fi
192
+
193
+
194
+ #### play ####
195
+ if [ "$1" == "play" ]; then
196
+ pixi run start
197
+ exit 0
198
+ fi
199
+
200
+
201
+ #########################
202
+ #### HELPER COMMANDS ####
203
+ #########################
204
+
205
+ #### home ####
206
+ if [ "$1" == "home" ]; then
207
+ if [ -L "$0" ]; then
208
+ dirname $(readlink -f $SYMLINK_ON_PATH)
209
+ else
210
+ realpath $(dirname $0)
211
+ fi
212
+ exit 0
213
+ fi
214
+
215
+
216
+ #### pixi ####
217
+ if [ "$1" == "pixi" ]; then
218
+ if [ "$2" == "init" ]; then
219
+ # install and init Pixi project in pup's home dir
220
+ if ! command -v pixi &> /dev/null; then
221
+ curl -fsSL https://pixi.sh/install.sh | bash
222
+ fi
223
+ PUPHOME=$(pup home)
224
+ if [[ ! -f "$PUPHOME"/pixi.toml ]]; then
225
+ pixi init "$PUPHOME"
226
+ pixi task add start "$(pup home)/.pixi/envs/default/bin/$PIXI_DEFAULT_TASK"
227
+ fi
228
+ exit 0
229
+ fi
230
+ if [ "$2" == "rm" ]; then
231
+ # remove pixi files
232
+ rm -r "$(pup home)"/.pixi "$(pup home)"/pixi*
233
+ exit 0
234
+ fi
235
+ fi
236
+
237
+
238
+ #### version ####
239
+ if [ "$1" == "version" ]; then
240
+ echo $VERSION
241
+ exit 0
242
+ fi
243
+
244
+
245
+ #### which ####
246
+ if [ "$1" == "which" ]; then
247
+ echo $(ls "$SYMLINK_ON_PATH") -\> $(readlink -f $SYMLINK_ON_PATH)
248
+ exit 0
249
+ fi
250
+
251
+
252
+ #### whereami ####
253
+ if [ "$1" == "whereami" ]; then
254
+ cat "$(pup home)/$LOG"
255
+ exit 0
256
+ fi
257
+
258
+
259
+ #### unknown command ####
260
+ echo -e "\e[0;33m🐶 does not know 'pup $*'\e[0m\nrun 'pup' to list known commands"