-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·68 lines (59 loc) · 2.62 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·68 lines (59 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# One-time environment bootstrap.
#
# uv is the intended path. It reads .python-version, so the interpreter is pinned
# (3.13) the same way requirements.txt pins the packages. A venv + pip fallback is
# kept so a grader without uv can still build the project.
#
# Why the interpreter is pinned and not just the packages: every number in the
# report came out of Python 3.13 with the exact versions in requirements.txt.
# Building on a different interpreter can resolve different wheels, and the
# notebooks would then run to completion and produce slightly different results
# with nothing to tell you they had.
set -euo pipefail
cd "$(dirname "$0")"
PYVER="$(cat .python-version 2>/dev/null || echo 3.13)"
# True if $1 is a Python interpreter meeting the >= 3.11 floor.
py_ok() { "$1" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3,11) else 1)' 2>/dev/null; }
if command -v uv >/dev/null 2>&1; then
# uv picks up .python-version on its own, and downloads the interpreter if the
# machine does not have it. Nothing else to arrange.
echo "uv found. Building on Python $PYVER (pinned in .python-version)."
uv venv
uv pip install -r requirements.txt
else
echo "uv not found — falling back to venv + pip."
echo "(uv is the intended path: curl -LsSf https://astral.sh/uv/install.sh | sh)"
# Prefer the pinned version, then anything at or above the floor.
PYBIN=""
for cand in "python${PYVER}" python3.13 python3.12 python3.11 python3 python; do
if command -v "$cand" >/dev/null 2>&1 && py_ok "$cand"; then
PYBIN="$(command -v "$cand")"
break
fi
done
[ -n "$PYBIN" ] || {
echo "Error: need Python >= 3.11 in PATH, or install uv (link above)."
exit 1
}
echo "Using: $PYBIN ($("$PYBIN" -V 2>&1))"
if ! "$PYBIN" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == tuple(int(x) for x in '${PYVER}'.split('.')) else 1)" 2>/dev/null; then
echo
echo " NOTE: this is not Python $PYVER, which is what produced the committed results."
echo " The notebooks will still run. Numbers may differ in the last decimal or two."
echo
fi
"$PYBIN" -m venv .venv
./.venv/bin/pip install --upgrade pip
./.venv/bin/pip install -r requirements.txt
fi
# Fetch the dataset, reusing the freshly built interpreter for its verification step.
echo
echo "Fetching dataset..."
SETUP_PYBIN="$(pwd)/.venv/bin/python" bash data/download_data.sh
echo
echo "Setup complete."
echo
echo " source .venv/bin/activate # once per shell"
echo " bash run_notebooks.sh # reproduce every result"
echo " jupyter lab # or just read the notebooks, outputs are committed"