-
Notifications
You must be signed in to change notification settings - Fork 5
/
dev
executable file
·77 lines (69 loc) · 2.21 KB
/
dev
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
69
70
71
72
73
74
75
76
77
#!/bin/bash
# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
sourced=0
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
# shellcheck disable=SC2296
[ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && sourced=1
else
# All other shells: examine $0 for known shell binary filenames.
# Detects `sh` and `dash`; add additional shell filenames as needed.
case ${0##*/} in sh|-sh|dash|-dash)
if [ -z "$PROJECT_ROOT" ]; then
echo "POSIX environments need PROJECT_ROOT in the environment for 'source run.sh activate' to work"
echo "This must be set to the root of this repository"
return 1
fi
;;
esac
fi
# Bash does not make it easy to find where this file is
# Here I'm making it so it doesn't matter what directory you are in
# when you execute this script. And it doesn't matter whether you're
# executing a symlink to this script
# Note the `-h` in the while loop asks if this path is a symlink
pushd . >'/dev/null'
DIRECTORY_BEFORE="$(pwd)"
SCRIPT_PATH="${BASH_SOURCE[0]:-$0}"
find_here() {
while [ -h "$SCRIPT_PATH" ]; do
cd "$(dirname -- "$SCRIPT_PATH")" || return 1
SCRIPT_PATH="$(readlink -f -- "$SCRIPT_PATH")"
done
cd "$(dirname -- "$SCRIPT_PATH")" >'/dev/null' || return 1
}
if ! find_here; then
if [ "$sourced" = "1" ]; then
return 1
else
exit 1
fi
fi
PROJECT_ROOT=$(pwd)
export PROJECT_ROOT
if ! ./tools/uv sync --locked -q; then
if [ "$sourced" = "1" ]; then
return 1
else
exit 1
fi
fi
if [ -f ./tools/requirements.local.txt ]; then
if ! ./tools/uv pip install -q -r ./tools/requirements.local.txt; then
if [ "$sourced" = "1" ]; then
return 1
else
exit 1
fi
fi
fi
if [ "$sourced" = "1" ]; then
# shellcheck source=/dev/null
source .venv/bin/activate
cd "$DIRECTORY_BEFORE" || return 1
else
exec uv run ./tools/run.py "$@"
fi