Skip to content

Commit

Permalink
Start adding a script to manage the python environment, this addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ekluzek committed May 17, 2022
1 parent 6cf26e9 commit b286e3a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ test -------------- CTSM Testing scripts for CTSM offline tools.
tools ------------- CTSM Offline tools to prepare input datasets and process output.
cime_config ------- Configuration files of cime for compsets and CTSM settings
manage_externals -- Script to manage the external source directories
manage_python_env - Script to setup the python environment for CTSM python tools using conda
python ------------ Some python modules mostly for use by run_sys_tests (but could be used elsewhere l

Directory structure only for a CTSM checkout:
Expand Down
72 changes: 72 additions & 0 deletions manage_python_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash -f
#
# manage_python_env -- setup the python environment in order to use CTSM python tools
#
# Simple bash script to setup the python environment for the user so they can run the CTSM
# python tools using "conda".
#

# Check if conda is in your path
conda --help >& /dev/null
if [ $? != 0 ]; then
echo "conda is NOT in your path add it with modules or whatever is required on your system to get it in your path"
echo "on cheyenne use -- module load conda"
exit -1
fi
ctsm_python=ctsm_py


#----------------------------------------------------------------------
# Usage subroutine
usage() {
echo ""
echo "**********************"
echo "usage:"
echo "./manage_python_env"
echo ""
echo "valid arguments: "
echo "[-h|--help] "
echo " Displays this help message"
echo "**********************"
}

while [ $# -gt 0 ]; do
case $1 in
-h|--help )
usage
exit 0
;;
* )
echo "ERROR:: invalid argument sent in: $2"
usage
exit 1
;;
esac
shift
done

echo "Use conda to install the python environment needed to run the CTSM python tools in the conda environment: $ctsm_python"

# Check if the environment already exists, if it does continue, if not create it
conda list -n $ctsm_python >& /dev/null
if [ $? != 0 ]; then
echo "Create $ctsm_python"
conda create -n $ctsm_python
else
echo "$ctsm_python environment already exists"
fi
echo "Install $ctsm_python this can take a long time, be patient...."
conda install --yes -q -n $ctsm_python --file python/conda_env_ctsm_py.txt
if [ $? != 0 ]; then
echo "Trouble installing the $ctsm_python python environment"
exit -2
fi
echo "Activate $ctsm_python"
conda activate $ctsm_python
if [ $? != 0 ]; then
echo "Trouble activating the $ctsm_python python environment fix as outlined above and then run"
echo "conda activate $ctsm_python"
echo "On CGD systems for tcsh you need to source the conda.csh under the /etc/profile.d/ subdirectory of the /usr/local/anaconda-* version you are using for python"
exit -3
fi
echo "Successfully installed the $ctsm_python python environment"

0 comments on commit b286e3a

Please sign in to comment.