forked from CODAIT/text-extensions-for-pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.sh
executable file
·204 lines (168 loc) · 6.38 KB
/
env.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#! /bin/bash
################################################################################
# Create conda environment to run the notebooks in this directory.
#
# See usage() below for the current set of arguments this script accepts.
################################################################################
# Argument processing
# Default values for parameters passed on command line
# Use environment variables if present.
# (-z predicate means "unset or empty string")
if [ -z "$PYTHON_VERSION" ]; then
PYTHON_VERSION="3.8"
fi
ENV_NAME="pd"
usage() {
echo "Usage: ./env.sh [-h] [--env_name <name>] "
echo " [--use_active_env]"
echo " [--python_version <version>]"
echo " [--pandas_version <version>]"
echo ""
echo "You can also use the following environment variables:"
echo " PYTHON_VERSION: Version of Python to install"
echo " PANDAS_VERSION: version of Pandas to install"
echo "(command-line arguments override environment variables values)"
}
die() {
echo $1
usage
exit 1
}
# Read command line arguments
# See Bash docs at http://mywiki.wooledge.org/BashFAQ/035
while :; do
case $1 in
-h|--help)
usage
exit 0
;;
--env_name)
if [ "$2" ]; then ENV_NAME=$2; shift
else die "ERROR: --env_name requires an environment name"
fi
;;
--use_active_env)
unset ENV_NAME; shift
;;
--python_version)
if [ "$2" ]; then PYTHON_VERSION=$2; shift
else die "ERROR: --python_version requires a python version"
fi
;;
--pandas_version)
if [ "$2" ]; then PANDAS_VERSION=$2; shift
else die "ERROR: --pandas_version requires a pandas version"
fi
;;
?*)
die "Unknown option '$1'"
;;
*) # No more options
break
esac
shift # Move on to next argument
done
if [ -n "${ENV_NAME}" ]; then
echo "Creating environment '${ENV_NAME}' with Python '${PYTHON_VERSION}'."
else
echo "Using active environment with Python '${PYTHON_VERSION}'."
fi
if [ -n "${PANDAS_VERSION}" ]; then
echo "Will use non-default Pandas version '${PANDAS_VERSION}'."
fi
############################
# HACK ALERT *** HACK ALERT
# The friendly folks at Anaconda thought it would be a good idea to make the
# "conda" command a shell function.
# See https://github.com/conda/conda/issues/7126
# The following workaround will probably be fragile.
if [ -z "$CONDA_HOME" ]
then
echo "Error: CONDA_HOME not set."
exit
fi
if [ -e "${CONDA_HOME}/etc/profile.d/conda.sh" ]
then
# shellcheck disable=SC1090
. "${CONDA_HOME}/etc/profile.d/conda.sh"
else
echo "Error: CONDA_HOME (${CONDA_HOME}) does not appear to be set up."
exit
fi
# END HACK
############################
################################################################################
# Create the environment if not using active
if [ -n "${ENV_NAME}" ]; then
# Remove the detrius of any previous runs of this script
conda env remove -n ${ENV_NAME}
# Note that we also install pip and wheel, which may or may not be present
# on the environment.
conda create -y --name ${ENV_NAME} python=${PYTHON_VERSION} pip wheel
################################################################################
# All the installation steps that follow must be done from within the new
# environment.
conda activate ${ENV_NAME}
fi
################################################################################
# Install packages with conda
# We currently install JupyterLab from conda because the pip packages are
# broken for Anaconda environments with Python 3.6 and 3.8 on Mac, as of
# April 2021.
conda install -y -c conda-forge jupyterlab
conda install -y -c conda-forge/label/main nodejs
conda install -y -c conda-forge jupyterlab-git
################################################################################
# Install packages with pip
# pip install with the project's requirements.txt so that any hard constraints
# on package versions are respected in the created environment.
echo "Installing from requirements.txt..."
pip install -r requirements.txt
# Additional layer of pip-installed stuff for running regression tests
echo "Installing from config/dev_reqs.txt..."
pip install -r config/dev_reqs.txt
# Additional layer of pip-installed stuff for running notebooks
echo "Installing from config/jupyter_reqs.txt..."
pip install -r config/jupyter_reqs.txt
# Additional layer of large packages
echo "Installing from config/big_reqs.txt..."
pip install -r config/big_reqs.txt
# Additional layer of packages that no longer work with Python 3.6
if [ "${PYTHON_VERSION}" == "3.6" ]; then
echo "Skipping packages in config/non_36_reqs.txt because Python version"
echo "is set to 3.6."
else
echo "Installing from config/non_36_reqs.txt..."
pip install -r config/non_36_reqs.txt
fi
# The previous steps will have installed some version of Pandas.
# Override that version if the user requested it.
if [ -n "${PANDAS_VERSION}" ]; then
echo "Ensuring Pandas ${PANDAS_VERSION} is installed"
pip install pandas==${PANDAS_VERSION}
fi
################################################################################
# Non-pip package installation
# spaCy language models for English
python -m spacy download en_core_web_sm
python -m spacy download en_core_web_trf
# Finish installation of ipywidgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install --no-build @jupyter-widgets/jupyterlab-manager
# Elyra extensions to JupyterLab (enables git integration, debugger, workflow
# editor, table of contents, and other features)
if [ "${PYTHON_VERSION}" == "3.6" ]; then
echo "Skipping Elyra extensions because Python version is set to 3.6."
else
pip install --upgrade --use-deprecated=legacy-resolver elyra
fi
# Build once after installing all the extensions, and skip minimization of the
# JuptyerLab resources, since we'll be running from the local machine.
jupyter lab build --minimize=False
if [ -n "${ENV_NAME}" ]; then
conda deactivate
echo "Anaconda environment '${ENV_NAME}' successfully created."
echo "To use, type 'conda activate ${ENV_NAME}'."
else
echo "Current environment updated successfully."
fi