From f64033e6f17c64379b43fea7f566cb4749224d20 Mon Sep 17 00:00:00 2001 From: Jay-Allemand Maxime Date: Wed, 24 Apr 2024 10:19:40 +0200 Subject: [PATCH] adapt the bash script to install SMASH 1.0 into a virtual python environnement using venv. --- venv_install.sh | 84 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/venv_install.sh b/venv_install.sh index 77b53e03..df6dda15 100755 --- a/venv_install.sh +++ b/venv_install.sh @@ -3,28 +3,74 @@ #The installation has been tested for ubuntu 22.04 only #When running this script, you will be prompted for your administrator password to install the required dependencies. -venv_path=~/python_venv/ -env_name=smash +venv_path=~/python_venv +env_name=smash_1.0 + + +#Parse input arguments +i=1 +until [ $# = 0 ] +do +case $1 in + --venv_path) + shift + venv_path=$1 + echo "venv_path="$venv_path + shift + ;; + --env_name) + shift + env_name=$1 + echo "env_name="$env_name + shift + ;; + --help | -h) + echo "Installation of the SMASH python package" + echo "" + echo "Options :" + echo "-h, --help Display the help" + echo "--venv_path {venv_path} Specify the folder where the python environnement will be created. Default value is $venv_path" + echo "--env_name {env_name} Specify the name of the python environment that will be created. Default is $env_name" + exit 0 + ;; + *) + echo "Unknown options ..." + echo "Use --help to see available options." + exit 0 + ;; +esac +done + if [ ! -d ${venv_path} ] ; then + echo "Creating the folder to store the python environnement in ${venv_path}" mkdir ${venv_path} fi #install debian dependencies -#we should support other distribution here... and check the os version +#Warning to the user +if [ $(cat /etc/*release | grep ^NAME | grep -o Ubuntu) == "Ubuntu" ]; then -if cat /etc/*release | grep ^NAME | grep Ubuntu; then DEB_PACKAGE_NAME="gfortran build-essential gdal-bin libgdal-dev libshp-dev python3-gdal python3-venv python3-dev" echo "===============================================" - echo "Installing packages $DEB_PACKAGE_NAME on Ubuntu" + echo "Make sure you first installed the following package (ubuntu): $DEB_PACKAGE_NAME" echo "===============================================" - sudo apt install $DEB_PACKAGE_NAME + else - echo "unsupported os. Please install manually the corresponding package (Ubuntu/Debian) for your distribution." - echo "sudo apt install $DEB_PACKAGE_NAME" + + PACKAGE_NAME="gfortran build-essential gdal-bin libgdal-dev libshp-dev python3-gdal python3-venv python3-dev" + echo "===============================================" + echo "Builging smash require some packages. Make sure you install them first. Install the corresponding package depending your distribution. On Debian/Ubuntu these package are: $PACKAGE_NAME" + echo "===============================================" + fi -if [ ! -d ${venv_path}/${env_name} ] ; then + +echo "" +read -p "Press enter to continue, ctrl+c to abort ..." + + +if [ ! -d "${venv_path}/.venv-${env_name}" ] ; then echo '' echo 'Creating a virtual python environment for Smash...' @@ -32,34 +78,31 @@ if [ ! -d ${venv_path}/${env_name} ] ; then #creating a python environment and activate it python3 -m venv "${venv_path}/.venv-${env_name}" - ln "${venv_path}/.venv-smash/bin/activate" "${venv_path}/${env_name}" + ln "${venv_path}/.venv-${env_name}/bin/activate" "${venv_path}/${env_name}" source ${venv_path}/${env_name} - #install minimal python dependencies - #here we should list and install all dependencies ? + #install python dependencies pip install --upgrade pip pip install 'numpy>=1.13,<=1.23' pip install f90wrap pip install wheel - - #manually intalling gdal, because it depends on the version of the installed system library - pip install GDAL<=$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal" + pip install rasterio pandas h5py tqdm scipy pyyaml terminaltables matplotlib echo '' echo 'Building Smash...' echo '' - #building the code inside the python environnement. This will automatically install all others python dependencies + make echo '' echo 'Installing extra-package for building the documentation...' echo '' #install extra-package for building the documentation: - pip install sphinx numpydoc pydata-sphinx-theme ipython sphinxcontrib-bibtex sphinx-design sphinx-autosummary-accessors pytest black + pip install sphinx numpydoc pydata-sphinx-theme ipython sphinxcontrib-bibtex sphinx-design sphinx-autosummary-accessors pytest pytest-cov black ruff fprettify else echo '' - echo "The python environnemnt smash already exist. Remove the directory ${venv_path}/${env_name} if you need to re-install Smash." + echo "The python environnemnt ${venv_path}/${env_name} already exist..." echo '' fi echo '************************************************' @@ -67,13 +110,16 @@ echo '************************************************' echo '' echo '************************************************' -echo 'To activate the python environment for Smash run:' +echo 'To activate the python environment for Smash, run:' echo "> source ${venv_path}/${env_name}" echo 'To deactivate the python environnement, juste type:' echo '>deactivate' +echo '' echo 'To use the smash package run the following commands:' echo "> source ${venv_path}/${env_name}" +echo '>Then launch python:' echo '(smash)> python' +echo 'Import the SMASH package in your python shell:' echo '>>> import smash' echo '************************************************'