-
Notifications
You must be signed in to change notification settings - Fork 3
/
pypeline.sh
executable file
·93 lines (77 loc) · 2.42 KB
/
pypeline.sh
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
#!/bin/sh
# #############################################################################
# pypeline.sh
# ===========
# Author : Sepand KASHANI [kashani.sepand@gmail.com]
# #############################################################################
# Setup Pypeline environment + launch shell.
abs_script_dir="$(echo "${PWD}" | python3 -c "
import pathlib;
import sys;
file_path = sys.stdin.readline();
abs_cwd = pathlib.Path(file_path).absolute();
print(abs_cwd);
")"
show_help_message() {
cat << EOF
usage: [source] pypeline.sh [-h] [--no_shell]
Launch Python3 interactive shell with Pypeline installed.
optional arguments:
--no_shell (w/ source) Only load Pypeline environment in current shell process.
This option is mainly used for development.
Environment variables in this script can be modified by the user to tailor Pypeline to their environment.
Warning
-------
This script must be executed/sourced from the directory where it is defined.
Examples
--------
sh pypeline.sh # Launch Pypeline shell.
source pypeline.sh --no_shell # Just setup Pypeline environment.
EOF
}
has_conda() {
which conda >& /dev/null
return "${?}"
}
has_pypeline_env() {
has_conda
if [ "${?}" -eq 0 ]; then
conda info -e | grep -e'pypeline ' > /dev/null
return "${?}"
fi
}
load_pypeline_env() {
source activate pypeline
# CasaCore: add <miniconda_root>/lib/ to LD_LIBRARY_PATH for libtinfow.so
local miniconda_root="$(dirname "$(dirname "$(which conda)")")"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${miniconda_root}/lib"
}
if [ "${#}" -eq 1 ] && [ "${1}" = '-h' ]; then
show_help_message
else
has_conda
if [ "${?}" -eq 0 ]; then
if [ "${#}" -eq 1 ] && [ "${1}" = '--no_shell' ]; then
has_pypeline_env
if [ "${?}" -eq 0 ]; then
load_pypeline_env
else
echo 'Error: pypeline environment does not exist.'
fi
elif [ "${#}" -eq 0 ]; then
has_pypeline_env
if [ "${?}" -eq 0 ]; then
load_pypeline_env
ipython3 --matplotlib
else
echo 'Error: pypeline environment does not exist.'
fi
else
echo 'INCORRECT INVOCATION'
echo
show_help_message
fi
else
echo "Error: could not locate conda executable."
fi
fi