-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_recolour_system_conda_python_adapter_4_hyde.sh
executable file
·230 lines (188 loc) · 8.65 KB
/
setup_recolour_system_conda_python_adapter_4_hyde.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash -e
#-----------------------------------------------------------------------------------------
# Script information
script_name='RECOLOUR ENVIRONMENT - PYTHON3 LIBRARIES FOR PACKAGE - ADAPTER TYPE - CONDA'
script_version="1.6.4"
script_date='2024/04/09'
# Define file reference path according with https link(s) --> https://repo.anaconda.com/miniconda/
fp_env_file_miniconda='https://repo.continuum.io/miniconda/Miniconda3-py37_4.8.2-Linux-x86_64.sh'
#fp_env_file_miniconda='https://repo.continuum.io/miniconda/Miniconda3-py39_23.1.0-1-Linux-x86_64.sh'
# Argument(s) default definition(s)
fp_env_tag_default='recolour_adapter_4_hyde'
fp_env_folder_root_default='./conda/'
fp_env_file_reference_default='%ENV_TAG_settings'
fp_env_folder_libraries_default='%ENV_TAG_libraries'
fp_env_file_requirements_default='requirements_%ENV_TAG.yaml'
# Examples of generic command-line:
# conda create --yes --name $fp_env_folder_libraries numpy scipy pip python=3
# conda create --yes --nama $fp_env_folder_libraries -c conda-forge pyresample pygeobase
# conda install --yes -c conda-forge nbconvert
# conda env export | grep -v "^prefix: " > requirements_fp_env_python.yaml
# conda env create --file $fp_env_file_requirements # create virtual env using yaml file
# conda create -y --name $fp_env_folder_libraries --file $fp_env_file_requirements # create virtual env using ascii file
#-----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Info script start
echo " ==================================================================================="
echo " ==> "$script_name" (Version: "$script_version" Release_Date: "$script_date")"
echo " ==> START ..."
# Get arguments number and values
script_args_n=$#
script_args_values=$@
echo ""
echo " ==> Script arguments number: $script_args_n"
echo " ==> Script arguments values: $script_args_values"
echo ""
echo " ==> ARGS DEFINED:"
echo ""
echo " ==> Script arguments 1 - Tag of virtual environmenf [string: path]-> $1"
echo " ==> Script arguments 2 - Directory of libraries [string: path]-> $2"
echo " ==> Script arguments 3 - Filename of system environment [string: filename] -> $3"
echo " ==> Script arguments 4 - Name of virtual environment [string: name] -> $4"
echo " ==> Script arguments 5 - Filename of system requirements in yaml format [string: name] -> $5"
echo ""
# Get folder root path
if [ $# -eq 0 ]; then
fp_env_tag=$fp_env_tag_default
fp_env_folder_root=$fp_env_folder_root_default
fp_env_file_reference=$fp_env_file_reference_default
fp_env_folder_libraries=$fp_env_folder_libraries_default
fp_env_file_requirements=$fp_env_file_requirements_default
elif [ $# -eq 1 ]; then
fp_env_tag=$1
fp_env_folder_root=$fp_env_folder_root_default
fp_env_file_reference=$fp_env_file_reference_default
fp_env_folder_libraries=$fp_env_folder_libraries_default
fp_env_file_requirements=$fp_env_file_requirements_default
elif [ $# -eq 2 ]; then
fp_env_tag=$1
fp_env_folder_root=$2
fp_env_file_reference=$fp_env_file_reference_default
fp_env_folder_libraries=$fp_env_folder_libraries_default
fp_env_file_requirements=$fp_env_file_requirements_default
elif [ $# -eq 3 ]; then
fp_env_tag=$1
fp_env_folder_root=$2
fp_env_file_reference=$3
fp_env_folder_libraries=$fp_env_folder_libraries_default
fp_env_file_requirements=$fp_env_file_requirements_default
elif [ $# -eq 4 ]; then
fp_env_tag=$1
fp_env_folder_root=$2
fp_env_file_reference=$3
fp_env_folder_libraries=$4
fp_env_file_requirements=$fp_env_file_requirements_default
elif [ $# -eq 5 ]; then
fp_env_tag=$1
fp_env_folder_root=$2
fp_env_file_reference=$3
fp_env_folder_libraries=$4
fp_env_file_requirements=$5
fi
# Set the
fp_env_folder_root=${fp_env_folder_root/'%ENV_TAG'/$fp_env_tag}
fp_env_file_reference=${fp_env_file_reference/'%ENV_TAG'/$fp_env_tag}
fp_env_folder_libraries=${fp_env_folder_libraries/'%ENV_TAG'/$fp_env_tag}
fp_env_file_requirements=${fp_env_file_requirements/'%ENV_TAG'/$fp_env_tag}
echo ""
echo " ==> ARGS SELECTED:"
echo ""
echo " ==> Script arguments 1 - Tag of virtual environmenf [string: path]-> ${fp_env_tag}"
echo " ==> Script arguments 2 - Directory of libraries [string: path]-> ${fp_env_folder_root}"
echo " ==> Script arguments 3 - Filename of system environment [string: filename] -> ${fp_env_file_reference}"
echo " ==> Script arguments 4 - Name of virtual environment [string: name] -> ${fp_env_folder_libraries}"
echo " ==> Script arguments 5 - Filename of system requirements in yaml format [string: name] -> ${fp_env_file_requirements}"
echo ""
# Create root folder
if [ ! -d "$fp_env_folder_root" ]; then
mkdir -p $fp_env_folder_root
fi
# Define folder path(s)
fp_env_folder_root=$fp_env_folder_root
# Define environment filename
fp_env_path_reference=$fp_env_folder_root/$fp_env_file_reference
# multilines comment: if [ 1 -eq 0 ]; then ... fi
#-----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Install python environmente using miniconda
echo " ====> CHECK PYTHON ENVIRONMENT ... "
if [ -d "$fp_env_folder_root/bin/" ] > /dev/null 2>&1 ; then
export PATH="$fp_env_folder_root/bin:$PATH"
if source activate $fp_env_folder_root > /dev/null 2>&1 ; then
echo " ====> CHECK PYTHON ENVIRONMENT ... FOUND."
fp_env_install=false
else
echo " ====> CHECK PYTHON ENVIRONMENT ... FOUND ENVIRONMENT BUT LIBRARIES ARE NOT FOUND."
fp_env_install=false
fi
else
echo " ====> CHECK PYTHON ENVIRONMENT ... NOT FOUND."
fp_env_install=true
fi
echo " ====> INSTALL PYTHON ENVIRONMENT ... "
if $fp_env_install; then
# Download library source codes
echo " =====> GET LIBRARY FILES ... "
wget $fp_env_file_miniconda -O miniconda.sh
echo " =====> GET LIBRARY FILES ... DONE!"
if [ -d "$fp_env_folder_root" ]; then
rm -Rf $fp_env_folder_root;
fi
bash miniconda.sh -b -p $fp_env_folder_root
echo " ====> INSTALL PYTHON ENVIRONMENT ... DONE!"
else
echo " ====> INSTALL PYTHON ENVIRONMENT ... DONE. PREVIOSLY INSTALLED"
fi
# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Install python libraries
echo " ====> INSTALL PYTHON LIBRARIES ... "
export PATH="$fp_env_folder_root/bin:$PATH"
if [ -f $fp_env_file_requirements ] ; then
echo " =====> USE OF CONDA REQUIREMENTS FILE YAML: $fp_env_file_requirements"
# source activate $fp_env_folder_libraries
# conda create -y --name $fp_env_folder_libraries --file $fp_env_file_requirements
conda env create --file $fp_env_file_requirements
else
echo " =====> USE OF CONDA GENERIC COMMAND-LINE"
echo " =====> CONDA INSTALLATION ... "
echo " ======> [1/2] CONDA-DEFAULT CHANNEL INSTALLATION ... "
conda create --yes --name $fp_env_folder_libraries numpy scipy matplotlib==3.1.3 gdal h5py cartopy==0.17 pandas rasterio netCDF4 cython xarray=0.18.0 bottleneck dask pip python=3.7
echo " ======> [1/2] CONDA-DEFAULT CHANNEL INSTALLATION ... DONE"
echo " ======> [2/2] PYTHON-PIP INSTALLATION ... "
source activate $fp_env_folder_libraries
pip install wheel
pip install progressbar2
pip install gldas
pip install pygeogrids
pip install ascat==2.2.0
pip install pytesmo
pip install memon
pip install astropy
echo " ======> [2/2] PYTHON-PIP INSTALLATION ... DONE"
echo " =====> CONDA INSTALLATION ... DONE"
fi
echo " ====> INSTALL PYTHON LIBRARIES ... DONE!"
# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Create environmental file
echo " ====> CREATE ENVIRONMENTAL FILE ... "
# Delete old version of environmental file
cd $fp_env_folder_root
if [ -f $fp_env_file_reference ] ; then
rm $fp_env_file_reference
fi
# Export BINARY PATH(S)
echo "PATH=$fp_env_folder_root/bin:"'$PATH'"" >> $fp_env_file_reference
echo "export PATH" >> $fp_env_file_reference
# Export VENV ACTIVATION
echo "source activate $fp_env_folder_libraries" >> $fp_env_file_reference
echo " ====> CREATE ENVIRONMENTAL FILE ... DONE!"
# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Info script end
echo " ==> "$script_name" (Version: "$script_version" Release_Date: "$script_date")"
echo " ==> ... END"
echo " ==> Bye, Bye"
echo " ==================================================================================="
# ----------------------------------------------------------------------------------------