-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNerlnetJupyterLaunch.sh
executable file
·145 lines (121 loc) · 3.34 KB
/
NerlnetJupyterLaunch.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
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
#!/bin/bash
NERLNET_LIB_DIR="/usr/local/lib/nerlnet-lib"
NERLNET_DIR=$NERLNET_LIB_DIR/NErlNet
SRC_PY_DIR=$NERLNET_DIR/src_py
API_SERVER_DIR=$SRC_PY_DIR/apiServer
# Args Default Values
_arg_venv="on"
JUPDIR="$PWD/JupyterLabDir"
# functions
print()
{
echo "[NERLNET JUPYTER LAUNCHER] $1"
}
set_env()
{
cd $NERLNET_DIR
source ./tests/set_env.sh
pip3 install jupyterlab
cd -
}
generate_set_jupyter_env()
{
STARTUP_FILE_NAME=set_jupyter_env.py
STARTUP_FILE_PATH=$JUPDIR/$STARTUP_FILE_NAME
print "Generating $STARTUP_FILE_PATH"
echo "import sys" > $STARTUP_FILE_PATH
echo "sys.path.append(\"$API_SERVER_DIR\")" >> $STARTUP_FILE_PATH
}
generate_readme_md()
{
README_FILE_NAME=README.md
README_FILE_PATH=$JUPDIR/$README_FILE_NAME
print "Generating $README_FILE_PATH"
echo "This directory is intended to be used as a workspace for JupyterLab " > $README_FILE_PATH
echo "To use ApiServer from Jupyter Notebook, please run the following command in the first cell: " >> $README_FILE_PATH
echo "\`\`\`import set_jupyter_env\`\`\` " >> $README_FILE_PATH
echo "Run the first cell " >> $README_FILE_PATH
echo "Then you can use ApiServer in the next cells " >> $README_FILE_PATH
}
# Generated online by https://argbash.io/generate
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
begins_with_short_option()
{
local first_option all_short_options='dvh'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
print_help()
{
printf '%s\n' "The general script's help msg"
printf 'Usage: %s [-d|--dir <arg>] [-v|--(no-)venv] [-h|--help]\n' "$0"
printf '\t%s\n' "-d, --dir: directory that jupyter notebook runs from (no default)"
printf '\t%s\n' "-v, --venv, --no-venv: automatically use nerlnet venv (on by default)"
printf '\t%s\n' "-h, --help: Prints help"
}
parse_commandline()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
-d|--dir)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
JUPDIR="$2"
shift
;;
--dir=*)
JUPDIR="${_key##--dir=}"
;;
-d*)
JUPDIR="${_key##-d}"
;;
-v|--no-venv|--venv)
_arg_venv="on"
test "${1:0:5}" = "--no-" && _arg_venv="off"
;;
-v*)
_arg_venv="on"
_next="${_key##-v}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-v" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
if [ "$_arg_venv" = "on" ]; then
print "Setting up nerlnet venv"
set_env
else
print "This is user responsibility to set up the environment"
print "If you want to use nerlnet venv, please use -v or --venv option"
fi
mkdir -p $JUPDIR
cd $JUPDIR
generate_set_jupyter_env
generate_readme_md
# TODO add networkx and pygraphviz installations!
jupyter-lab