1#
2# Hi there!  Welcome to the yt installation script.
3#
4# First things first, if you experience problems, please visit the Help
5# section at http://yt-project.org.
6#
7# This script is designed to create a fully isolated Python installation
8# with the dependencies you need to run yt.
9#
10# If you would like to customize the yt installation, then please edit
11# the following options.
12
13# If you do not have a working compiler environment, use the following
14# configuration:
15
16INST_YT_SOURCE=0   # Should yt itself be installed from source?
17
18# What follows are some other options that you may or may not need to change.
19
20# If you've got a clone of the yt repository some other place, set this to
21# point to it. The script will already check the current directory and the one
22# above it in the tree.
23YT_DIR=""
24
25# These options can be set to customize the installation.
26
27INST_GIT=1      # Install git or not?  If git is not already installed, yt
28                # cannot be installed from source.
29INST_EMBREE=0   # Install dependencies needed for Embree-accelerated ray tracing
30INST_PYX=0      # Install PyX?  Sometimes PyX can be problematic without a
31                # working TeX installation.
32INST_SCIPY=0    # Install scipy?
33INST_H5PY=1     # Install h5py?
34INST_ASTROPY=0  # Install astropy?
35INST_CARTOPY=0  # Install cartopy?
36INST_NOSE=1     # Install nose?
37INST_NETCDF4=1  # Install netcdf4 and its python bindings?
38INST_POOCH=1    # Install pooch?
39
40# This is the branch we will install from for INST_YT_SOURCE=1
41BRANCH="main"
42
43# These variables control which miniconda version is used
44
45MINICONDA_URLBASE="http://repo.continuum.io/miniconda"
46MINICONDA_VERSION="latest"
47
48if [ ! -z "${CONDA_DEFAULT_ENV}" ]
49then
50    echo "Aborting the yt installation because you appear to already"
51    echo "have a conda environment activated. Either deactivate it with:"
52    echo
53    echo "    $ source deactivate"
54    echo
55    echo "or install yt into your current environment with:"
56    echo
57    echo "    $ conda install -c conda-forge yt"
58    echo
59    exit 1
60fi
61DEST_SUFFIX="yt-conda"
62if [ -n "${PYTHONPATH}" ]
63then
64    echo "WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
65    echo "*******************************************************"
66    echo
67    echo "The PYTHONPATH environment variable is set to:"
68    echo
69    echo "    $PYTHONPATH"
70    echo
71    echo "If dependencies of yt (numpy, scipy, matplotlib) are installed"
72    echo "to this path, this may cause issues. Exit the install script"
73    echo "with Ctrl-C and unset PYTHONPATH if you are unsure."
74    echo "Hit enter to continue."
75    echo
76    echo "WARNING WARNING WARNING WARNING WARNING WARNING WARNING"
77    echo "*******************************************************"
78    read -p "[hit enter]"
79fi
80
81if [ -z "${DEST_DIR}" ]
82then
83    DEST_DIR="`pwd`/${DEST_SUFFIX/ /}"   # Installation location
84fi
85
86# Make sure we are NOT being run as root
87if [[ $EUID -eq 0 ]]
88then
89   echo "******************************************************"
90   echo "*                                                    *"
91   echo "*                                                    *"
92   echo "*  IT IS A BAD IDEA TO RUN THIS SCRIPT AS ROOT!!!!   *"
93   echo "*                                                    *"
94   echo "*                                                    *"
95   echo "******************************************************"
96   echo
97   echo "If you really want to do this, you must manually edit"
98   echo "the script to re-enable root-level installation.  Sorry!"
99   exit 1
100fi
101if [[ ${DEST_DIR%/} == /usr/local ]]
102then
103   echo "******************************************************"
104   echo "*                                                    *"
105   echo "*                                                    *"
106   echo "*  THIS SCRIPT WILL NOT INSTALL TO /usr/local !!!!   *"
107   echo "*                                                    *"
108   echo "*                                                    *"
109   echo "******************************************************"
110   echo
111   echo "If you really want to do this, you must manually edit"
112   echo "the script."
113   echo "Sorry!"
114   exit 1
115fi
116
117#------------------------------------------------------------------------------#
118#                                                                              #
119# Okay, the script starts here.  Feel free to play with it, but hopefully      #
120# it'll work as is.                                                            #
121#                                                                              #
122#------------------------------------------------------------------------------#
123
124LOG_FILE="${DEST_DIR}/yt_install.log"
125
126function write_config
127{
128    CONFIG_FILE=${DEST_DIR}/.yt_config
129    echo INST_YT_SOURCE=${INST_YT_SOURCE} > ${CONFIG_FILE}
130    echo INST_GIT=${INST_GIT} >> ${CONFIG_FILE}
131    echo INST_PYX=${INST_PYX} >> ${CONFIG_FILE}
132    echo INST_SCIPY=${INST_SCIPY} >> ${CONFIG_FILE}
133    echo INST_EMBREE=${INST_EMBREE} >> ${CONFIG_FILE}
134    echo INST_H5PY=${INST_H5PY} >> ${CONFIG_FILE}
135    echo INST_ASTROPY=${INST_ASTROPY} >> ${CONFIG_FILE}
136    echo INST_CARTOPY=${INST_CARTOPY} >> ${CONFIG_FILE}
137    echo INST_NOSE=${INST_NOSE} >> ${CONFIG_FILE}
138    echo INST_POOCH=${INST_POOCH} >> ${CONFIG_FILE}
139
140    echo YT_DIR=${YT_DIR} >> ${CONFIG_FILE}
141}
142
143function get_willwont
144{
145    if [ $1 -eq 1 ]
146    then
147        echo -n "will  "
148    else
149        echo -n "won't "
150    fi
151}
152
153function host_specific
154{
155    MYHOST=`hostname -s`  # just give the short one, not FQDN
156    MYHOSTLONG=`hostname` # FQDN, for Ranger
157    MYOS=`uname -s`       # A guess at the OS
158    if [ "${MYOS##Darwin}" != "${MYOS}" ]
159    then
160        echo "Looks like you're running on MacOS."
161        echo
162        echo "NOTE: you must have the Xcode command line tools installed."
163        echo
164        echo "Download the appropriate version of Xcode from the"
165        echo "Mac App Store (search for Xcode)."
166        echo
167        echo "Additionally, you will have to manually install the Xcode"
168        echo "command line tools."
169        echo
170        echo "For MacOS 10.10 and newer the command line tools can be installed"
171        echo "with the following command:"
172        echo "    xcode-select --install"
173        echo
174    fi
175    if [ -f /etc/redhat-release ]
176    then
177        echo "Looks like you're on an Redhat-compatible machine."
178        echo
179        echo "You need to have these packages installed:"
180        echo
181        echo "  * openssl-devel"
182        echo "  * uuid-devel"
183        echo "  * readline-devel"
184        echo "  * ncurses-devel"
185        echo "  * zip"
186        echo "  * gcc-{,c++,gfortran}"
187        echo "  * make"
188        echo "  * patch"
189        echo "  * git"
190        echo
191        echo "You can accomplish this by executing:"
192        echo "$ sudo yum install gcc gcc-c++ gcc-gfortran make patch zip git"
193        echo "$ sudo yum install ncurses-devel uuid-devel openssl-devel readline-devel"
194    fi
195    if [ -f /etc/SuSE-release ] && [ `grep --count SUSE /etc/SuSE-release` -gt 0 ]
196    then
197        echo "Looks like you're on an OpenSUSE-compatible machine."
198        echo
199        echo "You need to have these packages installed:"
200        echo
201        echo "  * devel_C_C++"
202        echo "  * libopenssl-devel"
203        echo "  * libuuid-devel"
204        echo "  * zip"
205        echo "  * gcc-c++"
206        echo "  * git"
207        echo
208        echo "You can accomplish this by executing:"
209        echo
210        echo "$ sudo zypper install -t pattern devel_C_C++"
211        echo "$ sudo zypper install git-core gcc-c++ libopenssl-devel libuuid-devel zip"
212        echo
213        echo "I am also setting special configure arguments to Python to"
214        echo "specify control lib/lib64 issues."
215        PYCONF_ARGS="--libdir=${DEST_DIR}/lib"
216    fi
217    if [ -f /etc/lsb-release ] && [ `grep --count buntu /etc/lsb-release` -gt 0 ]
218    then
219        echo "Looks like you're on an Ubuntu-compatible machine."
220        echo
221        echo "You need to have these packages installed:"
222        echo
223        echo "  * libssl-dev"
224        echo "  * build-essential"
225        echo "  * libncurses5"
226        echo "  * libncurses5-dev"
227        echo "  * zip"
228        echo "  * uuid-dev"
229        echo "  * libfreetype6-dev"
230        echo "  * tk-dev"
231        echo "  * git"
232        echo
233        echo "You can accomplish this by executing:"
234        echo
235        echo "$ sudo apt-get install libssl-dev build-essential libncurses5 libncurses5-dev zip uuid-dev libfreetype6-dev tk-dev git"
236        echo
237        echo
238        echo " Additionally, if you want to put yt's lib dir in your LD_LIBRARY_PATH"
239        echo " so you can use yt without the activate script, you might "
240        echo " want to consider turning off LIBZ and FREETYPE in this"
241        echo " install script by editing this file and setting"
242        echo
243        echo " INST_ZLIB=0"
244        echo " INST_FTYPE=0"
245        echo
246        echo " to avoid conflicts with other command-line programs "
247        echo " (like eog and evince, for example)."
248    fi
249}
250
251function log_cmd
252{
253    echo "EXECUTING:" >> ${LOG_FILE}
254    echo "  $*" >> ${LOG_FILE}
255    ( $* 2>&1 ) 1>> ${LOG_FILE} || do_exit
256}
257
258# set paths needed for Embree
259
260if [ $INST_EMBREE -ne 0 ]
261then
262    if [ $INST_YT_SOURCE -eq 0 ]
263    then
264        echo "yt must be compiled from source to install Embree support."
265        echo "Please set INST_YT_SOURCE to 1 and re-run the install script."
266        exit 1
267    fi
268    if [ `uname` = "Darwin" ]
269    then
270        EMBREE="embree-2.8.0.x86_64.macosx"
271        EMBREE_URL="https://github.com/embree/embree/releases/download/v2.8.0/$EMBREE.tar.gz"
272    elif [ `uname` = "Linux" ]
273    then
274        EMBREE="embree-2.8.0.x86_64.linux"
275        EMBREE_URL="https://github.com/embree/embree/releases/download/v2.8.0/$EMBREE.tar.gz"
276    else
277        echo "Embree is not supported on this platform."
278        echo "Set INST_EMBREE=0 and re-run the install script."
279        exit 1
280    fi
281    PYEMBREE_URL="https://github.com/scopatz/pyembree/archive/master.zip"
282fi
283
284echo
285echo
286echo "========================================================================"
287echo
288echo "Hi there!  This is the yt installation script.  We're going to download"
289echo "some stuff and install it to create a self-contained, isolated"
290echo "environment for yt to run within."
291echo
292echo "Inside the installation script you can set a few variables.  Here's what"
293echo "they're currently set to -- you can hit Ctrl-C and edit the values in "
294echo "the script if you aren't such a fan."
295echo
296
297printf "%-18s = %s so I " "INST_YT_SOURCE" "${INST_YT_SOURCE}"
298get_willwont ${INST_YT_SOURCE}
299echo "be compiling yt from source"
300
301printf "%-18s = %s so I " "INST_GIT" "${INST_GIT}"
302get_willwont ${INST_GIT}
303echo "be installing git"
304
305printf "%-18s = %s so I " "INST_EMBREE" "${INST_EMBREE}"
306get_willwont ${INST_EMBREE}
307echo "be installing Embree"
308
309printf "%-18s = %s so I " "INST_PYX" "${INST_PYX}"
310get_willwont ${INST_PYX}
311echo "be installing PyX"
312
313printf "%-18s = %s so I " "INST_H5PY" "${INST_H5PY}"
314get_willwont ${INST_H5PY}
315echo "be installing h5py"
316
317printf "%-18s = %s so I " "INST_ASTROPY" "${INST_ASTROPY}"
318get_willwont ${INST_ASTROPY}
319echo "be installing astropy"
320
321printf "%-18s = %s so I " "INST_CARTOPY" "${INST_CARTOPY}"
322get_willwont ${INST_CARTOPY}
323echo "be installing cartopy"
324
325printf "%-18s = %s so I " "INST_NOSE" "${INST_NOSE}"
326get_willwont ${INST_NOSE}
327echo "be installing nose"
328
329printf "%-18s = %s so I " "INST_POOCH" "${INST_POOCH}"
330get_willwont ${INST_POOCH}
331echo "be installing pooch"
332
333echo
334
335echo
336echo "Installation will be to"
337echo "  ${DEST_DIR}"
338echo
339echo "and I'll be logging the installation in"
340echo "  ${LOG_FILE}"
341echo
342echo "I think that about wraps it up.  If you want to continue, hit enter.  "
343echo "If you'd rather stop, maybe think things over, even grab a sandwich, "
344echo "hit Ctrl-C."
345echo
346
347if [ $INST_YT_SOURCE -ne 0 ]
348then
349   host_specific
350fi
351
352echo
353
354if [[ $1 != "--yes" ]]
355then
356    read -p "[hit enter] "
357fi
358
359echo
360echo "Awesome!  Here we go."
361echo
362
363function do_exit
364{
365    echo "********************************************"
366    echo "        FAILURE REPORT:"
367    echo "********************************************"
368    echo
369    tail -n 10 ${LOG_FILE}
370    echo
371    echo "********************************************"
372    echo "********************************************"
373    echo "Failure.  Check ${LOG_FILE}.  The last 10 lines are above."
374    exit 1
375}
376
377PYTHON_EXEC='python3'
378
379
380if type -P curl &>/dev/null
381then
382    echo "Using curl"
383    export GETFILE="curl -sSOL"
384else
385    echo "Using wget"
386    export GETFILE="wget -nv"
387fi
388
389function test_install
390{
391    echo "Testing that yt can be imported"
392    ( ${DEST_DIR}/bin/${PYTHON_EXEC} -c "import yt" 2>&1 ) 1>> ${LOG_FILE} || do_exit
393}
394
395ORIG_PWD=`pwd`
396
397MYARCH=`uname -m`
398MYOS=`uname -s`
399
400if [ $MYOS = "Darwin" ]
401then
402    MINICONDA_OS="MacOSX"
403    MINICONDA_ARCH="x86_64"
404elif [ $MYOS = "Linux" ]
405then
406    MINICONDA_OS="Linux"
407    if [ $MYARCH = "i386" ]
408    then
409        MINICONDA_ARCH="x86"
410    elif [ $MYARCH = "i686"  ]
411    then
412        MINICONDA_ARCH="x86"
413    elif [ $MYARCH = "x86_64"  ]
414    then
415        MINICONDA_ARCH="x86_64"
416    elif [ $MYARCH = "ppc64le"  ]
417    then
418        MINICONDA_ARCH="ppc64le"
419    else
420        echo "Not sure which architecture you are running."
421        echo "Going with x86_64 architecture."
422        MINICONDA_ARCH="x86_64"
423    fi
424else
425    echo "The yt install script is not supported on the ${MYOS}"
426    echo "operating system."
427    exit 1
428fi
429
430PY_VERSION='3'
431
432MINICONDA_PKG="Miniconda${PY_VERSION}-${MINICONDA_VERSION}-${MINICONDA_OS}-${MINICONDA_ARCH}.sh"
433
434echo
435echo "Downloading ${MINICONDA_URLBASE}/${MINICONDA_PKG}"
436echo
437
438if [ -f ${MINICONDA_PKG} ]
439then
440    rm $MINICONDA_PKG
441fi
442
443echo "Installing the Miniconda python environment."
444
445if [ -e ${DEST_DIR} ]
446then
447    rm -rf $DEST_DIR/*
448else
449    mkdir $DEST_DIR
450fi
451
452log_cmd ${GETFILE} ${MINICONDA_URLBASE}/${MINICONDA_PKG} || do_exit
453
454log_cmd bash ./${MINICONDA_PKG} -b -p $DEST_DIR -f
455
456# Need to set PATH so we use miniconda's python environment
457export PATH=${DEST_DIR}/bin:$PATH
458
459echo "Installing the necessary packages for yt."
460echo "This may take a while, but don't worry.  yt loves you."
461
462declare -a YT_DEPS
463YT_DEPS+=('python')
464YT_DEPS+=('setuptools')
465YT_DEPS+=('numpy')
466YT_DEPS+=('jupyter')
467YT_DEPS+=('ipython')
468YT_DEPS+=('sphinx')
469if [ ${INST_GIT} -eq 1 ]
470then
471    YT_DEPS+=('git')
472    YT_DEPS+=('gitpython')
473fi
474if [ $INST_H5PY -ne 0 ]
475then
476    YT_DEPS+=('h5py')
477fi
478YT_DEPS+=('matplotlib')
479YT_DEPS+=('cython')
480if [ $INST_NOSE -ne 0 ]
481then
482    YT_DEPS+=('nose')
483fi
484if [ $INST_SCIPY -ne 0 ]
485then
486    YT_DEPS+=('scipy')
487fi
488if [ $INST_ASTROPY -ne 0 ]
489then
490    YT_DEPS+=('astropy')
491fi
492if [ $INST_CARTOPY -ne 0 ]
493then
494    YT_DEPS+=('cartopy')
495fi
496if [ $INST_POOCH -ne 0 ]
497then
498    YT_DEPS+=('pooch')
499fi
500YT_DEPS+=('conda-build')
501YT_DEPS+=('sympy')
502
503if [ $INST_NETCDF4 -eq 1 ]
504then
505    YT_DEPS+=('netcdf4')
506fi
507
508log_cmd ${DEST_DIR}/bin/conda update --yes conda
509
510if [ $INST_GIT -eq 1 ]
511then
512    GIT_EXE=${DEST_DIR}/bin/git
513else
514    if type -P git &>/dev/null
515    then
516        GIT_EXE="git"
517    else
518        if [ $INST_YT_SOURCE -eq 1 ]
519        then
520            echo "Cannot find git. Please install git or set INST_GIT=1."
521            do_exit
522        fi
523    fi
524fi
525
526log_cmd echo "DEPENDENCIES" ${YT_DEPS[@]}
527for YT_DEP in "${YT_DEPS[@]}"; do
528    echo "Installing $YT_DEP"
529    log_cmd ${DEST_DIR}/bin/conda install -c conda-forge --yes ${YT_DEP}
530done
531
532if [ $INST_YT_SOURCE -eq 1 ]
533then
534    log_cmd ${GIT_EXE} clone https://github.com/yt-project/yt_conda ${DEST_DIR}/src/yt_conda
535fi
536
537if [ $INST_EMBREE -eq 1 ]
538then
539    echo "Installing Embree"
540    if [ ! -d ${DEST_DIR}/src ]
541    then
542        mkdir ${DEST_DIR}/src
543    fi
544    cd ${DEST_DIR}/src
545    ( ${GETFILE} "$EMBREE_URL" 2>&1 ) 1>> ${LOG_FILE} || do_exit
546    log_cmd tar xfz ${EMBREE}.tar.gz
547    log_cmd mv ${DEST_DIR}/src/${EMBREE}/include/embree2 ${DEST_DIR}/include
548    log_cmd mv ${DEST_DIR}/src/${EMBREE}/lib/lib*.* ${DEST_DIR}/lib
549    if [ `uname` = "Darwin" ]
550    then
551        ln -s ${DEST_DIR}/lib/libembree.2.dylib ${DEST_DIR}/lib/libembree.dylib
552        install_name_tool -id ${DEST_DIR}/lib/libembree.2.dylib ${DEST_DIR}/lib/libembree.2.dylib
553    else
554        ln -s ${DEST_DIR}/lib/libembree.so.2 ${DEST_DIR}/lib/libembree.so
555    fi
556
557    echo "Installing pyembree from source"
558    ( ${GETFILE} "$PYEMBREE_URL" 2>&1 ) 1>> ${LOG_FILE} || do_exit
559    log_cmd unzip ${DEST_DIR}/src/master.zip
560    pushd ${DEST_DIR}/src/pyembree-master &> /dev/null
561    log_cmd ${DEST_DIR}/bin/${PYTHON_EXEC} setup.py install build_ext -I${DEST_DIR}/include -L${DEST_DIR}/lib
562    popd &> /dev/null
563fi
564
565# conda doesn't package pyx, so we install manually with pip
566if [ $INST_PYX -eq 1 ]
567then
568    log_cmd ${DEST_DIR}/bin/pip install pyx
569fi
570
571if [ $INST_YT_SOURCE -eq 0 ]
572then
573    echo "Installing yt"
574    log_cmd ${DEST_DIR}/bin/conda install -c conda-forge --yes yt
575else
576    echo "Building yt from source"
577    if [ -z "$YT_DIR" ]
578    then
579        if [ -e $ORIG_PWD/yt/mods.py ]
580        then
581            YT_DIR="$ORIG_PWD"
582        elif [ -e $ORIG_PWD/../yt/mods.py ]
583        then
584            YT_DIR=$(dirname $ORIG_PWD)
585        else
586            YT_DIR="${DEST_DIR}/src/yt-git"
587            log_cmd ${GIT_EXE} clone https://github.com/yt-project/yt ${YT_DIR}
588            log_cmd ${GIT_EXE} -C ${YT_DIR} checkout ${BRANCH}
589        fi
590        echo Setting YT_DIR=${YT_DIR}
591    else
592        if [ ! -e $YT_DIR/.git ]
593        then
594            echo "$YT_DIR is not a clone of the yt git repository, exiting"
595            do_exit
596        fi
597    fi
598    if [ $INST_EMBREE -eq 1 ]
599    then
600        echo $DEST_DIR > ${YT_DIR}/embree.cfg
601    fi
602    pushd ${YT_DIR} &> /dev/null
603    ( ${DEST_DIR}/bin/${PYTHON_EXEC} setup.py develop 2>&1) 1>> ${LOG_FILE} || do_exit
604    popd &> /dev/null
605fi
606
607test_install
608
609echo
610echo
611echo "========================================================================"
612echo
613echo "yt and the Conda system are now installed in $DEST_DIR"
614echo
615echo "To get started with yt, check out the orientation:"
616echo
617echo "    http://yt-project.org/doc/orientation/"
618echo
619echo "For support, see the website and join the mailing list:"
620echo
621echo "    http://yt-project.org/"
622echo "    http://yt-project.org/data/      (Sample data)"
623echo "    http://yt-project.org/doc/       (Docs)"
624echo
625echo "    https://mail.python.org/archives/list/yt-users@python.org/"
626echo
627echo "You must now prepend the following folder to your PATH environment variable:"
628echo
629echo "    $DEST_DIR/bin"
630echo
631echo "On Bash-style shells you can copy/paste the following command to "
632echo "temporarily activate the yt installation:"
633echo
634echo "    export PATH=$DEST_DIR/bin:\$PATH"
635echo
636echo "and on csh-style shells:"
637echo
638echo "    setenv PATH $DEST_DIR/bin:\$PATH"
639echo
640echo "You can also update the init file appropriate for your shell"
641echo "(e.g. .bashrc, .bash_profile, .cshrc, or .zshrc) to include"
642echo "the same command."
643echo
644echo "========================================================================"
645echo
646echo "Oh, look at me, still talking when there's science to do!"
647echo "Good luck, and email the mailing list if you run into any problems."
648