-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathactivate
More file actions
executable file
·163 lines (132 loc) · 3.72 KB
/
activate
File metadata and controls
executable file
·163 lines (132 loc) · 3.72 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
# Source this file from bash or zsh to make the Daylily CLI available in the
# current shell from a repo checkout.
__daylily_activate_is_sourced() {
if [ -n "${ZSH_VERSION:-}" ]; then
case "${ZSH_EVAL_CONTEXT:-}" in
*:file|*:file:*) return 0 ;;
esac
return 1
fi
if [ -n "${BASH_VERSION:-}" ]; then
[ "${BASH_SOURCE[0]}" != "$0" ]
return
fi
return 1
}
if ! __daylily_activate_is_sourced; then
echo "Error: this script must be sourced." >&2
echo "Usage: source ./activate" >&2
exit 1
fi
__daylily_activate_script_path() {
if [ -n "${BASH_VERSION:-}" ]; then
printf '%s\n' "${BASH_SOURCE[0]}"
return 0
fi
if [ -n "${ZSH_VERSION:-}" ]; then
eval 'printf "%s\n" "${(%):-%N}"'
return 0
fi
return 1
}
__daylily_activate_prepend_path() {
case ":${PATH}:" in
*":$1:"*) ;;
*) PATH="$1${PATH:+:${PATH}}" ;;
esac
}
__daylily_activate_conda_is_function() {
case "$(type conda 2>/dev/null)" in
*"shell function"*|*"function"*) return 0 ;;
esac
return 1
}
__daylily_activate_conda_exe() {
if [ -n "${CONDA_EXE:-}" ] && [ -x "${CONDA_EXE}" ]; then
printf '%s\n' "${CONDA_EXE}"
return 0
fi
if [ -n "${BASH_VERSION:-}" ]; then
type -p conda
return
fi
if [ -n "${ZSH_VERSION:-}" ]; then
whence -p conda
return
fi
command -v conda
}
__daylily_activate_load_conda() {
if ! command -v conda >/dev/null 2>&1; then
return 1
fi
if __daylily_activate_conda_is_function; then
return 0
fi
local conda_exe conda_shell conda_hook conda_base
conda_exe="$(__daylily_activate_conda_exe 2>/dev/null || true)"
if [ -z "${conda_exe}" ]; then
return 1
fi
if [ -n "${BASH_VERSION:-}" ]; then
conda_shell="bash"
elif [ -n "${ZSH_VERSION:-}" ]; then
conda_shell="zsh"
else
conda_shell="posix"
fi
conda_hook="$("${conda_exe}" "shell.${conda_shell}" hook 2>/dev/null || "${conda_exe}" shell.posix hook 2>/dev/null || true)"
if [ -n "${conda_hook}" ]; then
eval "${conda_hook}"
return 0
fi
conda_base="$("${conda_exe}" info --base 2>/dev/null || true)"
if [ -n "${conda_base}" ] && [ -f "${conda_base}/etc/profile.d/conda.sh" ]; then
. "${conda_base}/etc/profile.d/conda.sh"
return 0
fi
return 1
}
__daylily_activate_dayec_exists() {
command -v conda >/dev/null 2>&1 || return 1
conda env list 2>/dev/null | awk '{print $1}' | grep -qx 'DAY-EC'
}
__daylily_activate_repo_root="$(
cd "$(dirname "$(__daylily_activate_script_path)")" && pwd
)"
export DAYLILY_EC_REPO_ROOT="${__daylily_activate_repo_root}"
__daylily_activate_prepend_path "${DAYLILY_EC_REPO_ROOT}/bin"
export PATH
if __daylily_activate_load_conda && __daylily_activate_dayec_exists; then
conda activate DAY-EC >/dev/null 2>&1 || true
fi
__daylily_activate_cli_path="$(command -v daylily-ec 2>/dev/null || true)"
daylily-ec() {
if [ -n "${__daylily_activate_cli_path}" ] && [ -x "${__daylily_activate_cli_path}" ]; then
"${__daylily_activate_cli_path}" "$@"
return $?
fi
if __daylily_activate_load_conda && __daylily_activate_dayec_exists; then
conda run -n DAY-EC python -m daylily_ec "$@"
return $?
fi
if command -v python >/dev/null 2>&1 && (
cd "${DAYLILY_EC_REPO_ROOT}" &&
python -m daylily_ec version >/dev/null 2>&1
); then
(
cd "${DAYLILY_EC_REPO_ROOT}" &&
python -m daylily_ec "$@"
)
return $?
fi
echo "Error: daylily-ec dependencies are not available." >&2
echo "Run ./bin/init_dayec to create the DAY-EC environment first." >&2
return 1
}
if [ "${CONDA_DEFAULT_ENV:-}" = "DAY-EC" ]; then
echo "DAY-EC activated. daylily-ec is available in this shell."
else
echo "Repo tools added to PATH. daylily-ec is available via a shell wrapper."
fi